Skip to content

Commit f1341d1

Browse files
jeremypwJeremy Wootten
andauthored
Update construction of completion provider (#1528)
Co-authored-by: Jeremy Wootten <[email protected]>
1 parent 9da4dbc commit f1341d1

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

plugins/word-completion/completion-provider.vala

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2024 elementary, Inc. <https://elementary.io>
23
* Copyright (c) 2013 Mario Guerriero <[email protected]>
34
*
45
* This is a free software; you can redistribute it and/or
@@ -18,37 +19,50 @@
1819
*
1920
*/
2021

21-
public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, Object {
22-
public string name;
23-
public int priority;
22+
public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, GLib.Object {
23+
private const int MAX_COMPLETIONS = 10;
24+
public string name { get; construct; }
25+
public int priority { get; construct; }
26+
public int interactive_delay { get; construct; }
27+
public Gtk.SourceCompletionActivation activation { get; construct; }
2428

2529
public const string COMPLETION_END_MARK_NAME = "ScratchWordCompletionEnd";
2630
public const string COMPLETION_START_MARK_NAME = "ScratchWordCompletionStart";
2731

28-
private Gtk.TextView? view;
29-
private Gtk.TextBuffer? buffer;
30-
private Euclide.Completion.Parser parser;
32+
public Gtk.TextView? view { get; construct; }
33+
public Euclide.Completion.Parser parser { get; construct; }
34+
35+
private unowned Gtk.TextBuffer buffer {
36+
get {
37+
return view.buffer;
38+
}
39+
}
40+
3141
private Gtk.TextMark completion_end_mark;
3242
private Gtk.TextMark completion_start_mark;
43+
private string current_text_to_find = "";
3344

3445
public signal void can_propose (bool b);
3546

36-
public CompletionProvider (Scratch.Plugins.Completion completion) {
37-
this.view = completion.current_view as Gtk.TextView;
38-
this.buffer = completion.current_view.buffer;
39-
this.parser = completion.parser;
40-
Gtk.TextIter iter;
41-
buffer.get_iter_at_offset (out iter, 0);
42-
completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false);
43-
completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false);
44-
}
47+
public CompletionProvider (
48+
Euclide.Completion.Parser _parser,
49+
Scratch.Services.Document _doc
50+
) {
4551

46-
public string get_name () {
47-
return this.name;
52+
Object (
53+
parser: _parser,
54+
view: _doc.source_view,
55+
name: _("%s - Word Completion").printf (_doc.get_basename ())
56+
);
4857
}
4958

50-
public int get_priority () {
51-
return this.priority;
59+
construct {
60+
interactive_delay = (int) Completion.INTERACTIVE_DELAY;
61+
activation = INTERACTIVE | USER_REQUESTED;
62+
Gtk.TextIter iter;
63+
view.buffer.get_iter_at_offset (out iter, 0);
64+
completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false);
65+
completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false);
5266
}
5367

5468
public bool match (Gtk.SourceCompletionContext context) {
@@ -85,15 +99,6 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider,
8599
return true;
86100
}
87101

88-
public Gtk.SourceCompletionActivation get_activation () {
89-
return Gtk.SourceCompletionActivation.INTERACTIVE |
90-
Gtk.SourceCompletionActivation.USER_REQUESTED;
91-
}
92-
93-
public int get_interactive_delay () {
94-
return 0;
95-
}
96-
97102
public bool get_start_iter (Gtk.SourceCompletionContext context,
98103
Gtk.SourceCompletionProposal proposal,
99104
out Gtk.TextIter iter) {

plugins/word-completion/plugin.vala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020

2121
public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
22+
public const uint INTERACTIVE_DELAY = 500;
23+
2224
public Object object { owned get; construct; }
2325

2426
private List<Gtk.SourceView> text_view_list = new List<Gtk.SourceView> ();
@@ -88,9 +90,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
8890
if (text_view_list.find (current_view) == null)
8991
text_view_list.append (current_view);
9092

91-
var comp_provider = new Scratch.Plugins.CompletionProvider (this);
92-
comp_provider.priority = 1;
93-
comp_provider.name = provider_name_from_document (doc);
93+
var comp_provider = new Scratch.Plugins.CompletionProvider (parser, doc);
9494

9595
try {
9696
current_view.completion.add_provider (comp_provider);

0 commit comments

Comments
 (0)