From 0d91a936ef1b1d778e6227c59ea4c748c5887c25 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 11 Dec 2023 17:41:02 +0000 Subject: [PATCH 1/2] Use EventControllerKey in MainWindow --- src/MainWindow.vala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7166a555e..f4241b631 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -38,7 +38,7 @@ namespace Scratch { private Code.Terminal terminal; private FolderManager.FileView folder_manager_view; private Scratch.Services.DocumentManager document_manager; - + private Gtk.EventControllerKey key_controller; // Plugins private Scratch.Services.PluginsManager plugins; @@ -263,7 +263,10 @@ namespace Scratch { plugins = new Scratch.Services.PluginsManager (this); - key_press_event.connect (on_key_pressed); + key_controller = new Gtk.EventControllerKey (this) { + propagation_phase = CAPTURE + }; + key_controller.key_pressed.connect (on_key_pressed); // Set up layout init_layout (); @@ -643,8 +646,9 @@ namespace Scratch { }); } - private bool on_key_pressed (Gdk.EventKey event) { - switch (Gdk.keyval_name (event.keyval)) { + // private bool on_key_pressed (Gdk.EventKey event) { + private bool on_key_pressed (uint keyval, uint keycode, Gdk.ModifierType state) { + switch (Gdk.keyval_name (keyval)) { case "Escape": if (search_revealer.get_child_revealed ()) { var fetch_action = Utils.action_from_group (ACTION_SHOW_FIND, actions); From b6fadfa8ee87e8f0791120e06b7a43dc21a9fccd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 11 Dec 2023 18:34:53 +0000 Subject: [PATCH 2/2] Handle "Escape" in MainWindow --- src/MainWindow.vala | 2 ++ src/Widgets/SearchBar.vala | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f4241b631..151e857c6 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -653,7 +653,9 @@ namespace Scratch { if (search_revealer.get_child_revealed ()) { var fetch_action = Utils.action_from_group (ACTION_SHOW_FIND, actions); fetch_action.set_state (false); + document_view.current_document.source_view.grab_focus (); } + break; } diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 16defc314..5f43f0015 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -497,9 +497,6 @@ namespace Scratch.Widgets { case "Down": search_next (); return true; - case "Escape": - text_view.grab_focus (); - return true; case "Tab": if (search_entry.is_focus) { replace_entry.grab_focus (); @@ -524,9 +521,6 @@ namespace Scratch.Widgets { case "Down": search_next (); return true; - case "Escape": - text_view.grab_focus (); - return true; case "Tab": if (replace_entry.is_focus) { search_entry.grab_focus ();