From a7810a02e68d68ba52f85708244c96545f5b1918 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 11:18:26 +0000 Subject: [PATCH 1/4] Grab focus and save current doc on enter terminal pane --- src/Widgets/Terminal.vala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index 8b22da3aa..2cdd9e5d2 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -149,6 +149,20 @@ public class Code.Terminal : Gtk.Box { }; key_controller.key_pressed.connect (key_pressed); + // Cannot use event controller in Gtk3 because of https://gitlab.gnome.org/GNOME/gtk/-/issues/7225 + terminal.enter_notify_event.connect (() => { + if (!terminal.has_focus) { + terminal.grab_focus (); + // Use Idle to avoid critical warning + Idle.add (() => { + var win_group = get_action_group (Scratch.MainWindow.ACTION_GROUP); + win_group.activate_action (Scratch.MainWindow.ACTION_SAVE, null); + + return Gdk.EVENT_STOP; + }); + } + }); + terminal.button_press_event.connect ((event) => { if (event.button == 3) { paste_action.set_enabled (current_clipboard.wait_is_text_available ()); From 8adf19ca3415a28a31a382849eeaf82e2d8583ed Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 11:38:21 +0000 Subject: [PATCH 2/4] Document strip trailing on focus out, grab focus on enter --- src/Services/Document.vala | 15 +++++++++++++++ src/Widgets/Terminal.vala | 6 ------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Services/Document.vala b/src/Services/Document.vala index ae4bf524f..b5f766c65 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -300,6 +300,21 @@ namespace Scratch.Services { completion_shown = false; }); + source_view.enter_notify_event.connect (() => { + if (!source_view.has_focus) { + source_view.grab_focus (); + } + }); + + source_view.focus_out_event.connect (() => { + if (source_view.buffer.get_modified () && + Scratch.settings.get_boolean ("strip-trailing-on-save")) { + + strip_trailing_spaces (); + } + }); + + loaded = file == null; add (main_stack); diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index 2cdd9e5d2..57f15a806 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -153,13 +153,7 @@ public class Code.Terminal : Gtk.Box { terminal.enter_notify_event.connect (() => { if (!terminal.has_focus) { terminal.grab_focus (); - // Use Idle to avoid critical warning - Idle.add (() => { - var win_group = get_action_group (Scratch.MainWindow.ACTION_GROUP); - win_group.activate_action (Scratch.MainWindow.ACTION_SAVE, null); - return Gdk.EVENT_STOP; - }); } }); From 20abc8be17ab54b4fbf68341ab30dbec6874d36a Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 11:52:12 +0000 Subject: [PATCH 3/4] Ignore modified flag --- src/Services/Document.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Services/Document.vala b/src/Services/Document.vala index b5f766c65..09ecbe671 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -307,8 +307,7 @@ namespace Scratch.Services { }); source_view.focus_out_event.connect (() => { - if (source_view.buffer.get_modified () && - Scratch.settings.get_boolean ("strip-trailing-on-save")) { + if (Scratch.settings.get_boolean ("strip-trailing-on-save")) { strip_trailing_spaces (); } From d073a9c57822820f039760c88cf73aaf2bae4ba3 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 12:06:41 +0000 Subject: [PATCH 4/4] Fix whitespace --- src/Services/Document.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Services/Document.vala b/src/Services/Document.vala index 09ecbe671..cc32ecf76 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -313,7 +313,6 @@ namespace Scratch.Services { } }); - loaded = file == null; add (main_stack);