From 49367f3e5959edce436e9dc544d5d26aa5bb7675 Mon Sep 17 00:00:00 2001 From: Dipanshu Singh Date: Sun, 17 May 2026 07:50:22 +0530 Subject: [PATCH 1/2] 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 9f37b0e71eeb9486c99d67c5784f32da65004cc7 Mon Sep 17 00:00:00 2001 From: Dipanshu Singh Date: Sun, 17 May 2026 22:11:24 +0530 Subject: [PATCH 2/2] Sidebar: fix focus delegation to TreeView (elementary#1711) --- src/Widgets/Sidebar.vala | 1 - src/Widgets/SourceList/SourceList.vala | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index b9f7a0acc..86bcfba8e 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, diff --git a/src/Widgets/SourceList/SourceList.vala b/src/Widgets/SourceList/SourceList.vala index 85b7ecd02..ea64c1585 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 override void grab_focus () { + tree.grab_focus (); + } } }