Skip to content

fix(windows): keep every window's key view loop current so Tab reaches each pane - #2916

Merged
datlechin merged 1 commit into
mainfrom
fix/window-key-view-loop
Sep 16, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/window-key-view-loop

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #2904.

Root cause

TabWindowController.makeEditorWindow() left NSWindow.autorecalculatesKeyViewLoop at its default of false, and MainSplitViewController.viewWillAppear computed the key view loop exactly once. Every pane in a connection window is an NSHostingController installed into a WorkspacePaneHost, and SwiftUI builds its content later still, so nothing on the detail side ever entered the loop. SidebarContainerViewController papered over one hop of it by hand, assigning searchField.nextKeyView on every show(), which was the only reason the filter field could reach its own list.

The reported symptom was the small half. Measured on the shipping Debug build, driven through the accessibility API (macOS 27, Full Keyboard Access off, a SQLite connection with a table tab open):

Before
Tab from the sidebar filter reaches the object list
The whole key view loop sidebar-filter -> object list -> connections rail -> sidebar-filter, a closed 3-stop cycle
SQL editor, data grid, inspector, assistant, tab strip never a Tab stop
Ctrl+F6 nothing

So Tab and Down into the list already worked, and docs/features/keyboard-shortcuts.mdx already documented Down. What did not work was leaving the sidebar at all. A keyboard-only user could not reach the editor or the grid.

Reproduced in a compiled AppKit harness of the same shape (NSWindow -> NSSplitViewController -> WorkspacePaneHost -> NSHostingController -> NSViewRepresentable -> NSScrollView -> NSOutlineView, panes installed after the window is on screen):

  • With the loop calculated once, outline.nextValidKeyView is nil and the tab walk is dead.
  • window.recalculateKeyViewLoop() after the panes exist repairs it to Outline -> Grid -> editor.
  • Setting autorecalculatesKeyViewLoop = true at window creation, with no explicit recalculate anywhere, produces the correct loop and keeps it correct across a pane swap, which is what a connection or tab switch does.

The fix

One property replaces three mechanisms. NSWindow.keepsKeyViewLoopCurrent() sets autorecalculatesKeyViewLoop = true, and the one-shot recalculateKeyViewLoop() plus both hand-maintained searchField.nextKeyView assignments are gone. A recalculation discards an explicit nextKeyView anyway, measured, so keeping them meant two mechanisms fighting over one link.

It is not one window. Every window TablePro builds programmatically had the same defect and now carries the same line: the connection window, the connection form, Welcome, Settings, Compare & Sync, the inspector, the value viewer, What's New, and the three simple windows built through NSWindow.titled. The connection form is the most keyboard-heavy screen in the app.

Cost, measured: on a 636-view window, 200 rounds of adding and removing a subview took 98.6ms with the property off and 81.6ms with it on. AppKit coalesces the recalculation rather than running one per subview change. This mattered because of the NSTableView subview-churn invariant in CLAUDE.md, where one layout pass cost 518ms.

A View > Focus submenu, extending the one focus command the app already had:

Command Shortcut
Focus Sidebar Filter Ctrl+Option+Cmd+F (unchanged)
Focus Object List Ctrl+Option+Cmd+L
Focus Editor Ctrl+Option+Cmd+E
Focus Results Ctrl+Option+Cmd+R
Focus Inspector Ctrl+Option+Cmd+I
Focus Assistant Ctrl+Option+Cmd+A

Each reveals its pane before focusing it, because makeFirstResponder accepts a hidden view and reports success. Each dims when the pane it names is not there. The target is found in the selected workspace's own pane subtree rather than tracked: EditorEventRouter is window-scoped and returns an arbitrary editor when several are registered, so a window hosting several connections would have focused the wrong one.

No "Move Focus to Next Area" command. There is no macOS system shortcut for moving focus between panes inside a window. Read from the macOS 27 system table DefaultShortcutsTable.xml, section keyboardnavigation, key 97 (F6) with modifier 262144 is "Move focus to the floating window", not "next pane". Tab is the mechanism, and it is what this change repairs.

Also in this PR

MainSplitViewController+MenuValidation.isEnabled ended in default: return true with no arm for clearSelection, and nothing forced a new menu item to have an arm, so the new Focus commands would have shipped permanently enabled with a green suite. isEnabled is now resolvedEnablement -> Bool? (nil means the window does not own the command) with isEnabled preserving the old ?? true behaviour, so no existing caller or test changed. MenuValidationCoverageTests fails if any command the window owns lacks an arm.

That guard found a second pre-existing gap while it was being written: zoomIn: and zoomOut: had no arm either. Both now have explicit ones.

Tests

  • EditorWindowChromeTests: the real window from makeEditorWindow() keeps its key view loop current. This is the regression guard for the root cause.
  • MenuValidationCoverageTests: every command the window owns is decided rather than left enabled by default; clearSelection needs a connection; each Focus command follows its own pane's readiness.
  • NSViewDescendantsTests: the subtree searches, including that the key-view search skips what Tab skips.
  • FocusCommandMenuTests: the submenu's contents, shortcuts, identifiers and shared modifier.
  • WindowFocusUITests: each Focus command moves focus; Tab reaches the object list; Tab reaches the data grid outside the sidebar.

WindowFocusUITests compiles and its runner launches, but it could not be executed on this machine: every XCUITest run fails with Timed out while enabling automation mode, which is an unanswered macOS UI-automation prompt. An untouched control suite (ConnectionWindowChromeUITests) fails identically, so this is the environment and not the suite. It needs a run on CI or on an unlocked machine.

Verification

Build PASS · 96/96 unit tests PASS · docs/scripts/check-writing-style.sh PASS · docs/scripts/check-docs-against-source.py PASS · swiftlint --strict clean over every changed file except one pre-existing type_body_length violation in MainContentCommandActions.swift, which is byte-identical to main.

Reviewed by Codex, which found seven issues. All were acted on. The one worth naming: the docs draft claimed Shift+Tab leaves the SQL editor, and TextViewController.handleTab returns nil for Shift+Tab unconditionally, so it always outdents and never reaches the key view loop. That would have shipped a documented shortcut that cannot work.

@mintlify

mintlify Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 16, 2026, 6:44 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@datlechin
datlechin merged commit 7d49703 into main Sep 16, 2026
9 checks passed
@datlechin
datlechin deleted the fix/window-key-view-loop branch September 16, 2026 06:53

This branch was successfully deployed

1 active deployment
staging - docs — fcd60c86 Deployed Sep 16, 2026 by mintlify[bot]
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.

Add keybind to focus sidebar filter result

1 participant