Skip to content

fix(lists): give clicked lists keyboard focus and make Return and Delete work in AppKit lists - #4175

Merged
datlechin merged 2 commits into
mainfrom
fix/swiftui-list-click-focus
Nov 10, 2026
Merged

datlechin merged 2 commits into
mainfrom
fix/swiftui-list-click-focus

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • On macOS 27, clicking a SwiftUI List or Table row selects it, but the backing NSTableView never becomes first responder (FB25239926, Apple forum thread 845762).
    • The selection draws grey and arrow keys go to whatever had focus.
    • onDeleteCommand, onCopyCommand, onKeyPress and Return primaryAction never fire after a click.
    • A SwiftUI App window fails the same way, so the AppKit lifecycle is not the cause.
  • New TableClickFocus fixes all 36 SwiftUI list and table sites in one place, with no call site edited.
    • It is a local mouse-down/mouse-up monitor, installed next to KeyRepeatFilter, on macOS 27 only.
    • After SwiftUI handles a click's mouse-up, it makes the table under the click first responder. On an already selected row, it does this at mouse-down.
    • It never overrides a focus the click itself moved to another view.
    • It leaves alone: Control-clicks, controls that take focus themselves, tables that refuse focus, windows behind a sheet or modal, and every table class defined by AppKit or by the app, since those take focus in NSTableView.mouseDown.
  • Return and Delete did nothing in the Welcome connection list, Favorites, the object browser and the connections strip. NSTableView.keyDown never interprets those keys, so their insertNewline(_:) and deleteBackward(_:) handlers never ran.
    • New NSTableView.interpretCommandKey(_:), used by SidebarOutlineView and WorkspaceRailTableView, sends unmodified Return, Enter, Delete and Forward Delete through interpretKeyEvents.
    • It does so only when the table or a responder above it handles the command. Otherwise the key travels up as before, so Return still reaches a default button, such as Save in the JSON editor's tree view.
  • A List inside a grouped Form never scrolls, so rows past the height cap could not be reached. The host list, attached databases and SQLite extensions lists now grow to fit every row, and the Form scrolls.
  • Behavior change: in the database type chooser and the Restore Database picker, clicking a row now moves focus to the list, as a native table does.
  • Rewrote the comments in FavoritesOutlineView, SidebarRootShape, FavoritesTabView and AppearanceSettingsView, and the example in .claude/rules/ui-lifecycle.md. They blamed the bare NSHostingController for this bug.

Test plan

  • TableClickFocusTests (10 cases): an unselected row is claimed after mouse-up and a selected row at mouse-down. A focus the click itself moves elsewhere stays there, and one it leaves vacant goes to the table. A Control-click, a text field in a row, an AppKit table, an app table whose cell takes the hit, and a table that refuses focus are left alone. A real SwiftUI List row is claimed; that case is gated on a host probe, since SwiftUI's view tree is private.
  • TableCommandKeyTests (6 cases): Return, Enter, Delete and Forward Delete reach their commands. Shift-modified keys and Down are left to the table. A Return nobody answers travels up, and Return on the connections strip reaches its controller.
  • ListClickFocusUITests: click a connection form section, check that the list holds the keyboard, then press Up and check that the selection moves. The CI runner is on macOS 26, where the bug does not exist, so there this only pins the flow.
  • WelcomeConnectionListUITests.testReturnOnASelectedConnectionOpensIt: fails on main (Return did nothing) and passes here.
  • Measured in a standalone harness on macOS 27.0.1:
    • Clicks: 60 of 60 took focus on both List and Table (baseline 0 of 60). Re-click, double-click and Cmd-click work. AppKit tables behave the same with and without the monitor.
    • Form list with 14 rows: with the cap, rows 7 to 14 cannot be reached. Without it, all 14 show and Down scrolls the Form to keep the selection visible.

@datlechin
datlechin merged commit 176779c into main Nov 10, 2026
10 checks passed
@datlechin
datlechin deleted the fix/swiftui-list-click-focus branch November 10, 2026 10:55
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.

1 participant