diff --git a/src/Services/Document.vala b/src/Services/Document.vala index ae4bf524f..cc32ecf76 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -300,6 +300,19 @@ 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 (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 8b22da3aa..57f15a806 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -149,6 +149,14 @@ 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 (); + + } + }); + terminal.button_press_event.connect ((event) => { if (event.button == 3) { paste_action.set_enabled (current_clipboard.wait_is_text_available ());