Skip to content

fix(tabs): keep focus in the listing after switching tabs with the mouse - #1932

Merged
l0gicgate merged 4 commits into
lgse:mainfrom
Bluesboy:fix/1929-tab-focus
Oct 30, 2026
Merged

l0gicgate merged 4 commits into
lgse:mainfrom
Bluesboy:fix/1929-tab-focus

Conversation

@Bluesboy

@Bluesboy Bluesboy commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Returning to a tab could leave keyboard focus outside the file listing (#1929), in two ways:

  • Leaving a tab with the mouse. A tab button is a plain gtk::Button, so a click focuses it before clicked runs TabWindow::select. select saved that button as the focus of the tab being left, and returning to the tab grabbed it again. The strip is shared chrome, always mapped and focusable, so the grab succeeded and the fallback to focus_active() never ran.
  • A restored tab's first show. A restored session selects its tabs before their listings load, so focus_active() finds no column to focus and GTK puts its default focus on the first focusable widget, the footer's shortcuts button. Selecting the next tab saved that button as the left tab's focus, since it is inside the tab, and the tab's first show restored it, so the first Ctrl+Shift+ to a restored tab landed on the footer.

select now saves the window's focus only when it is inside the tab's browser view (is_ancestor(&previous.content.browser.widget())). Focus anywhere else, on the tab strip or in the tab's footer or header, is dropped, so returning to the tab falls back to focus_active() and the listing. Focus inside the browser, such as an open filter, is saved and restored as before.

Tests, both failing without the change:

  • ui::window::composition::tabs::tests::returning_to_a_tab_left_by_a_tab_button_focuses_its_listing focuses a tab button the way a click does, leaves the tab and returns to it.
  • ui::window::composition::tabs::tests::a_restored_tab_shown_for_the_first_time_focuses_its_listing restores three tabs and shows the two that were never shown.

a_restored_session_opens_with_focus_in_the_listing guards the launch itself, which already focused the listing. wait_until_or lets the focus tests name the widget that holds focus when they time out.

Visual evidence

Before the change (1.1.0, AUR): after switching tabs, the tab button keeps the focus ring and j/k do nothing.

recording_20261030_024055_1080p.mp4

With the first commit only: after Ctrl+Shift+4 to a restored tab, the footer's shortcuts button has the focus ring.

recording_20261030_034625_1080p.mp4

How to test

  1. Open two tabs, A and B, and focus the file listing in A.
  2. Click tab B in the tab strip, then click tab A, and press Down.
  3. With Restore open tabs on, quit Strata with three tabs open and launch it again.
  4. Switch to each tab that was not active at launch with Ctrl+Shift+ and press Down.
  5. Focus the filter field with Ctrl+F, switch tabs with Ctrl+Tab and back with Ctrl+Shift+Tab.

Expected result: after steps 2 and 4 the cursor moves in the listing without clicking a column or pressing Tab. After step 5 focus is back in the filter field.

Related issue

Closes #1929

A tab button is a plain GtkButton, so a click focuses it before `clicked`
selects the tab. `TabWindow::select` then saved that button as the focus
of the tab being left, and returning to the tab grabbed it again: the
strip is shared chrome, always mapped and focusable, so the fallback to
the listing never ran and keyboard focus stayed on the tab strip.

Only save focus that is inside the tab's own content, so returning to a
tab left by a click falls back to `focus_active()` and the listing.

Closes lgse#1929
@github-actions github-actions Bot added the fix label Oct 28, 2026
@JoeJoeflyn

Copy link
Copy Markdown
Collaborator

can you attach a video or images

Bluesboy and others added 3 commits October 30, 2026 03:38
A restored session selects its tabs before their listings load, so
`focus_active()` finds no column to focus and GTK puts its default focus
on the first focusable widget, the footer's shortcuts button. Selecting
the next tab saved that button as the left tab's focus, since it is
inside the tab, and the tab's first show restored it.

Save focus only when it is inside the tab's browser view. Focus in the
tab's footer or header now falls back to `focus_active()` and the
listing, as focus on the tab strip already did.

Refs lgse#1929
Saving focus only inside the browser view dropped focus in the tab's
sidebar or preview drawer, so a keyboard user returning to a tab landed
in the listing instead of where they left. Save focus in any of the
tab's panes and still drop it on the strip, header and footer.

Refs lgse#1929
@l0gicgate
l0gicgate merged commit 41070b5 into lgse:main Oct 30, 2026
11 checks passed
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main at 7a095a91e. No conflicts.

Review against the description and #1929.

  • Tab-button click leaving focus on the strip: confirmed fixed. returning_to_a_tab_left_by_a_tab_button_focuses_its_listing fails without the filter in TabWindow::select.
  • Restored tab's first show landing on the footer's shortcuts button: confirmed fixed. a_restored_tab_shown_for_the_first_time_focuses_its_listing fails without the filter.
  • Filter-field focus is still restored after a keyboard tab switch: confirmed (filter_focus regressions pass).
  • @JoeJoeflyn asked for a video or images. The PR body now includes before/after recordings, so this is addressed.

Fixes pushed

  • 99d8346b1 fix(tabs): keep sidebar and preview focus when switching tabs. Each tab has its own sidebar and preview drawer, and both sit beside browser.widget(), not inside it. The browser-only filter therefore dropped focus there: a keyboard user in the sidebar or preview who switched with Ctrl+Tab and came back landed in the listing. Before this PR, focus returned to where they left it. The filter now keeps focus that is inside the browser, sidebar or preview, and still drops it on the strip, header and footer. New test: returning_to_a_tab_restores_focus_in_its_sidebar (it fails with the browser-only filter).

Tests removed

  • None. a_restored_session_opens_with_focus_in_the_listing passes without the fix, but it is the only test of focus on a restored launch, so it stays.

Validation

  • ./scripts/test-headless.py composition::tabs::tests: 32 passed
  • ./scripts/test-headless.py filter_focus: 13 passed
  • Mutation checks: browser-only filter → the sidebar test fails; no filter → both PR fix tests fail
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy: clean
  • Not run: qa.sh, because the PR touches no QA scenarios.

CI: all checks green. QA scenarios are skipped on PRs (dispatch only).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching tabs with the mouse leaves keyboard focus on the tab strip

3 participants