From 49367f3e5959edce436e9dc544d5d26aa5bb7675 Mon Sep 17 00:00:00 2001 From: Dipanshu Singh Date: Sun, 17 May 2026 07:50:22 +0530 Subject: [PATCH 1/3] Sidebar: add action and shortcut to focus sidebar (#1711) Allows users to move keyboard focus directly to the projects sidebar using Left, improving accessibility and full keyboard navigation. --- src/MainWindow.vala | 16 ++++++++++++++++ src/Widgets/Sidebar.vala | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bdbd129f0..10bf7086a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -106,6 +106,7 @@ namespace Scratch { public const string ACTION_TOGGLE_COMMENT = "action-toggle-comment"; public const string ACTION_TOGGLE_SHOW_FIND = "action-toggle_show-find"; public const string ACTION_TOGGLE_SIDEBAR = "action-toggle-sidebar"; + public const string ACTION_FOCUS_SIDEBAR = "action-focus-sidebar"; public const string ACTION_TOGGLE_OUTLINE = "action-toggle-outline"; public const string ACTION_TOGGLE_TERMINAL = "action-toggle-terminal"; public const string ACTION_OPEN_IN_TERMINAL = "action-open-in-terminal"; @@ -166,6 +167,7 @@ namespace Scratch { { ACTION_ZOOM_OUT, action_zoom_out}, { ACTION_TOGGLE_COMMENT, action_toggle_comment }, { ACTION_TOGGLE_SIDEBAR, action_toggle_sidebar, null, "true" }, + { ACTION_FOCUS_SIDEBAR, action_focus_sidebar }, { ACTION_TOGGLE_TERMINAL, action_toggle_terminal, null, "false"}, { ACTION_OPEN_IN_TERMINAL, action_open_in_terminal, "s"}, { ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"}, @@ -236,6 +238,7 @@ namespace Scratch { action_accelerators.set (ACTION_TOGGLE_COMMENT, "slash"); action_accelerators.set (ACTION_TOGGLE_SIDEBAR, "F9"); // GNOME action_accelerators.set (ACTION_TOGGLE_SIDEBAR, "backslash"); // Atom + action_accelerators.set (ACTION_FOCUS_SIDEBAR, "Left"); action_accelerators.set (ACTION_TOGGLE_TERMINAL, "t"); action_accelerators.set (ACTION_OPEN_IN_TERMINAL + "::", "t"); action_accelerators.set (ACTION_TOGGLE_OUTLINE, "backslash"); @@ -1427,6 +1430,19 @@ namespace Scratch { sidebar.visible = action.get_state ().get_boolean (); } + private void action_focus_sidebar () { + if (sidebar == null) { + return; + } + + if (!sidebar.visible) { + var toggle_sidebar_action = Utils.action_from_group (ACTION_TOGGLE_SIDEBAR, actions); + toggle_sidebar_action.activate (null); + } + + sidebar.focus_sidebar (); + } + private void action_toggle_terminal () { var toggle_terminal_action = Utils.action_from_group (ACTION_TOGGLE_TERMINAL, actions); toggle_terminal_action.set_state (!toggle_terminal_action.get_state ().get_boolean ()); diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 0b6a7ef47..b9f7a0acc 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -45,6 +45,7 @@ public class Code.Sidebar : Gtk.Grid { construct { orientation = Gtk.Orientation.VERTICAL; get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR); + can_focus = true; choose_project_button = new Code.ChooseProjectButton () { hexpand = true, @@ -195,4 +196,12 @@ public class Code.Sidebar : Gtk.Grid { public void notify_cloning_success () { cloning_success_toast.send_notification (); } + + public void focus_sidebar () { + if (stack.visible_child != null) { + stack.visible_child.grab_focus (); + } else { + grab_focus (); + } + } } From 3f704fe41ebf7cc8acdb91954bce6f3c024bddfe Mon Sep 17 00:00:00 2001 From: Dipanshu Singh Date: Sun, 17 May 2026 22:11:24 +0530 Subject: [PATCH 2/3] Sidebar: fix focus delegation to TreeView (elementary#1711) --- src/Widgets/Sidebar.vala | 7 ++----- src/Widgets/SourceList/SourceList.vala | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index b9f7a0acc..619ec0b55 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -45,7 +45,6 @@ public class Code.Sidebar : Gtk.Grid { construct { orientation = Gtk.Orientation.VERTICAL; get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR); - can_focus = true; choose_project_button = new Code.ChooseProjectButton () { hexpand = true, @@ -198,10 +197,8 @@ public class Code.Sidebar : Gtk.Grid { } public void focus_sidebar () { - if (stack.visible_child != null) { - stack.visible_child.grab_focus (); - } else { - grab_focus (); + if (stack.visible_child is Code.Widgets.SourceList) { + ((Code.Widgets.SourceList) stack.visible_child).grab_focus (); } } } diff --git a/src/Widgets/SourceList/SourceList.vala b/src/Widgets/SourceList/SourceList.vala index 85b7ecd02..99444ad82 100644 --- a/src/Widgets/SourceList/SourceList.vala +++ b/src/Widgets/SourceList/SourceList.vala @@ -2937,5 +2937,9 @@ public class SourceList : Gtk.ScrolledWindow { return null; } + + public new void grab_focus () { + tree.grab_focus (); + } } } From 73e3e7e775fba8f6624ebd1d86755d86898b79b4 Mon Sep 17 00:00:00 2001 From: Dipanshu Singh Date: Mon, 18 May 2026 21:56:40 +0530 Subject: [PATCH 3/3] MainWindow: add action-focus-document to return focus to editor (#1711) Binds Right to action-focus-document, allowing users to return keyboard focus from the project sidebar back to the active text document as requested by maintainer. --- src/MainWindow.vala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 10bf7086a..863cd8142 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -107,6 +107,7 @@ namespace Scratch { public const string ACTION_TOGGLE_SHOW_FIND = "action-toggle_show-find"; public const string ACTION_TOGGLE_SIDEBAR = "action-toggle-sidebar"; public const string ACTION_FOCUS_SIDEBAR = "action-focus-sidebar"; + public const string ACTION_FOCUS_DOCUMENT = "action-focus-document"; public const string ACTION_TOGGLE_OUTLINE = "action-toggle-outline"; public const string ACTION_TOGGLE_TERMINAL = "action-toggle-terminal"; public const string ACTION_OPEN_IN_TERMINAL = "action-open-in-terminal"; @@ -168,6 +169,7 @@ namespace Scratch { { ACTION_TOGGLE_COMMENT, action_toggle_comment }, { ACTION_TOGGLE_SIDEBAR, action_toggle_sidebar, null, "true" }, { ACTION_FOCUS_SIDEBAR, action_focus_sidebar }, + { ACTION_FOCUS_DOCUMENT, action_focus_document }, { ACTION_TOGGLE_TERMINAL, action_toggle_terminal, null, "false"}, { ACTION_OPEN_IN_TERMINAL, action_open_in_terminal, "s"}, { ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"}, @@ -239,6 +241,7 @@ namespace Scratch { action_accelerators.set (ACTION_TOGGLE_SIDEBAR, "F9"); // GNOME action_accelerators.set (ACTION_TOGGLE_SIDEBAR, "backslash"); // Atom action_accelerators.set (ACTION_FOCUS_SIDEBAR, "Left"); + action_accelerators.set (ACTION_FOCUS_DOCUMENT, "Right"); action_accelerators.set (ACTION_TOGGLE_TERMINAL, "t"); action_accelerators.set (ACTION_OPEN_IN_TERMINAL + "::", "t"); action_accelerators.set (ACTION_TOGGLE_OUTLINE, "backslash"); @@ -1443,6 +1446,13 @@ namespace Scratch { sidebar.focus_sidebar (); } + private void action_focus_document () { + var doc = get_current_document (); + if (doc != null) { + doc.focus (); + } + } + private void action_toggle_terminal () { var toggle_terminal_action = Utils.action_from_group (ACTION_TOGGLE_TERMINAL, actions); toggle_terminal_action.set_state (!toggle_terminal_action.get_state ().get_boolean ());