From 49fc736f1b56b3f58e51504b44382cc11b0ee529 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 31 Jan 2025 15:56:04 +0000 Subject: [PATCH] Start to rework on_new_source_view --- plugins/word-completion/plugin.vala | 36 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index bd5183b8e..f72c9f8f3 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -81,7 +81,13 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { current_document = doc; current_view = doc.source_view; + + if (text_view_list.find (current_view) == null) { + text_view_list.append (current_view); + } + current_view.key_press_event.connect (on_key_press); + current_view.completion.show.connect (() => { completion_in_progress = true; }); @@ -89,23 +95,27 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { completion_in_progress = false; }); - - if (text_view_list.find (current_view) == null) - text_view_list.append (current_view); - - var comp_provider = new Scratch.Plugins.CompletionProvider (this); - comp_provider.priority = 1; - comp_provider.name = provider_name_from_document (doc); - + current_completion = current_view.completion; try { - current_view.completion.add_provider (comp_provider); - current_view.completion.show_headers = true; - current_view.completion.show_icons = true; + current_provider = new Scratch.Plugins.CompletionProvider (this); + current_provider.priority = 1; + current_provider.name = provider_name_from_document (doc); + + current_completion.add_provider (current_provider); + current_completion.show_headers = true; + current_completion.show_icons = true; + current_completion.accelerators = 9; + current_completion.select_on_show = true; /* Wait a bit to allow text to load then run parser*/ timeout_id = Timeout.add (1000, on_timeout_update); - } catch (Error e) { - warning (e.message); + critical ( + "Could not add completion provider to %s. %s\n", + current_document.title, + e.message + ); + cleanup (current_view); + return; } }