Skip to content

Commit

Permalink
Refocus textview after Escape pressed in Search (#1388)
Browse files Browse the repository at this point in the history
* Use EventControllerKey in MainWindow

* Handle "Escape" in MainWindow
  • Loading branch information
jeremypw committed Dec 20, 2023
1 parent 742b31f commit 344f1f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -643,13 +646,16 @@ 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);
fetch_action.set_state (false);
document_view.current_document.source_view.grab_focus ();
}

break;
}

Expand Down
6 changes: 0 additions & 6 deletions src/Widgets/SearchBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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 ();
Expand Down

0 comments on commit 344f1f8

Please sign in to comment.