Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/word-completion/completion-provider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider,
Gtk.TextIter start, end;
buffer.get_iter_at_offset (out end, buffer.cursor_position);
start = end.copy ();
start.backward_word_start ();
Euclide.Completion.Parser.back_to_word_start (ref start);
string text = buffer.get_text (start, end, true);

return parser.match (text);
Expand Down Expand Up @@ -102,10 +102,11 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider,
buffer.get_iter_at_mark (out cursor_iter, mark);

iter = cursor_iter;
iter.backward_word_start ();
Euclide.Completion.Parser.back_to_word_start (ref iter);
return true;
}


private bool get_proposals (out GLib.List<Gtk.SourceCompletionItem>? props, bool no_minimum) {
string to_find = "";
Gtk.TextBuffer temp_buffer = buffer;
Expand All @@ -120,15 +121,14 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider,
temp_buffer.get_iter_at_offset (out end, buffer.cursor_position);

start = end;
start.backward_word_start ();
Euclide.Completion.Parser.back_to_word_start (ref start);

to_find = buffer.get_text (start, end, false);
}

buffer.move_mark_by_name (COMPLETION_END_MARK_NAME, end);
buffer.move_mark_by_name (COMPLETION_START_MARK_NAME, start);


/* There is no minimum length of word to find if the user requested a completion */
if (no_minimum || to_find.length >= Euclide.Completion.Parser.MINIMUM_WORD_LENGTH) {
/* Get proposals, if any */
Expand Down
5 changes: 5 additions & 0 deletions plugins/word-completion/engine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class Euclide.Completion.Parser : GLib.Object {
return DELIMITERS.index_of_char (c) >= 0;
}

public static void back_to_word_start (ref Gtk.TextIter iter) {
iter.backward_find_char (is_delimiter, null);
iter.forward_char ();
}

public Gee.HashMap<Gtk.TextView,Scratch.Plugins.PrefixTree> text_view_words;
public bool parsing_cancelled = false;

Expand Down
5 changes: 2 additions & 3 deletions plugins/word-completion/plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable {
}
}

if (!completion_in_progress && parser.is_delimiter (uc) &&
if (!completion_in_progress && Euclide.Completion.Parser.is_delimiter (uc) &&
(uc.isprint () || uc.isspace ())) {

var buffer = current_view.buffer;
var mark = buffer.get_insert ();
Gtk.TextIter cursor_iter;
buffer.get_iter_at_mark (out cursor_iter, mark);

var word_start = cursor_iter;
word_start.backward_word_start ();
Euclide.Completion.Parser.back_to_word_start (ref word_start);

string word = buffer.get_text (word_start, cursor_iter, false);
parser.add_word (word);
Expand Down