Skip to content

Feature/sidebar focus#1719

Open
Dipanshusinghh wants to merge 4 commits into
elementary:masterfrom
Dipanshusinghh:feature/sidebar-focus
Open

Feature/sidebar focus#1719
Dipanshusinghh wants to merge 4 commits into
elementary:masterfrom
Dipanshusinghh:feature/sidebar-focus

Conversation

@Dipanshusinghh
Copy link
Copy Markdown
Contributor

Summary

This PR fixes the keyboard accessibility issue where the project sidebar could not be focused via keyboard navigation.

Changes Made

  • Made Code.Sidebar focusable by setting can_focus = true.
  • Added ACTION_FOCUS_SIDEBAR (action-focus-sidebar) to MainWindow.
  • Bound <Control><Alt>Left to focus the sidebar directly (and opens it automatically if it is currently hidden).

Fixes #1711

Allows users to move keyboard focus directly to the projects sidebar using <Control><Alt>Left, improving accessibility and full keyboard navigation.
Copy link
Copy Markdown
Collaborator

@jeremypw jeremypw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this does not seem to work yet - focus remains with the document for me. Not sure why yet, but it does work if you focus the choose_project_button instead. So its something to do with making sure the treeview within the SourceList gets (and retains) the final focus.

Also may need a matching hotkey to return focus to the document but that can be addressed later.

I notice that if you do focus the choose_project_button then you can reach other widgets in the headerbar by using the standard Tab and <Shift>Tab keys. But not the actionbar.

Comment thread src/Widgets/Sidebar.vala Outdated
construct {
orientation = Gtk.Orientation.VERTICAL;
get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
can_focus = true;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this right - Sidebar is a container (Grid) which cannot have keyboard focus itself

@Dipanshusinghh Dipanshusinghh force-pushed the feature/sidebar-focus branch from 0916dbb to 9f37b0e Compare May 17, 2026 16:47
@Dipanshusinghh
Copy link
Copy Markdown
Contributor Author

Dipanshusinghh commented May 17, 2026

@jeremypw Thanks for the detailed review and for pointing out the root cause!

You are completely right. Sidebar is a Gtk.Grid container and shouldn't have can_focus = true. The issue with the focus not reaching the actual treeview happens because calling grab_focus() on the SourceList (which is a Gtk.ScrolledWindow) doesn't automatically pass the focus down to its child Gtk.TreeView

I have addressed the requested changes:-.

  1. Removed can_focus = true; from Code.Sidebar
  2. Overridden grab_focus() in Code.Widgets.SourceList to explicitly call tree.grab_focus(), ensuring the underlying Gtk.TreeView gets and retains the final keyboard focus

Regarding the shortcut to return focus to the document and the Actionbar tab navigation, I agree that those can be addressed in a separate follow-up PR as enhancements

Thanks again!

@jeremypw
Copy link
Copy Markdown
Collaborator

@Dipanshusinghh Still not working for me I am afraid. It is possible to make the sourcelist have keyboard focus by starting and then cancelling a rename operation on one of the items. After that you can move the cursor up and down with the keyboard. However, then pressing the action-focus-sidebar shortcut causes the tree to lose keyboard focus for some reason.

Copy link
Copy Markdown
Collaborator

@jeremypw jeremypw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A have made a couple of suggestions that should get this working (as long as there is a selected item in the sidebar at least.

Comment thread src/Widgets/SourceList/SourceList.vala Outdated
@@ -2937,5 +2937,9 @@ public class SourceList : Gtk.ScrolledWindow {

return null;
}

public override void grab_focus () {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be public new void grab_focus ()

Comment thread src/Widgets/Sidebar.vala Outdated

public void focus_sidebar () {
if (stack.visible_child != null) {
stack.visible_child.grab_focus ();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check the visible child is a SourceList and then cast it to that type in order to ensure the modified grab_focus method works as expected.

@Dipanshusinghh Dipanshusinghh force-pushed the feature/sidebar-focus branch from 9f37b0e to 3f704fe Compare May 18, 2026 14:05
@Dipanshusinghh
Copy link
Copy Markdown
Contributor Author

@jeremypw I have updated the PR with the exact changes you suggested

  1. Changed grab_focus() in SourceList.vala to public new void grab_focus() to properly shadow the parent container method
  2. Updated focus_sidebar() in Sidebar.vala to explicitly check if (stack.visible_child is Code.Widgets.SourceList) and cast it before calling grab_focus(). This successfully delegates the final keyboard focus to the internal Gtk.TreeView

Tested and verified. Thanks again for the excellent guidance and help in getting this right

Copy link
Copy Markdown
Collaborator

@jeremypw jeremypw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as expected now - thanks! I think we ought to implement the reverse action in this PR though on second thoughts.

There are some other issues with keyboard focus control - in particular switching from doc to terminal and back but they can wait.

I notice that once you are out of the doc/terminal focus pair, other widgets can be reached with the standard Tab/Shift-Tab keys, so that's good.

@jeremypw
Copy link
Copy Markdown
Collaborator

You need to merge in the updated master branch - I cannot do that.

Dipanshusinghh and others added 2 commits May 18, 2026 21:56
…entary#1711)

Binds <Control><Alt>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.
@Dipanshusinghh
Copy link
Copy Markdown
Contributor Author

@jeremypw I have updated the PR as requested:

  1. Added ACTION_FOCUS_DOCUMENT (action-focus-document) bound to <Control><Alt>Right in MainWindow.vala to implement the reverse action (returning focus from the project sidebar back to the active text document).
  2. Merged the updated master branch into feature/sidebar-focus.
    Everything is fully up-to-date and ready to merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar difficult to focus using keyboard

2 participants