Skip to content

fix(datagrid): focus the switcher search field when a filter input is being edited#1596

Merged
datlechin merged 1 commit into
mainfrom
fix/1575-connection-search-focus
Jun 5, 2026
Merged

fix(datagrid): focus the switcher search field when a filter input is being edited#1596
datlechin merged 1 commit into
mainfrom
fix/1575-connection-search-focus

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #1575

Problem

With a column filter input focused, opening the connection switcher left the cursor stuck in the filter field. Typing never reached the popover's search field.

Root cause

FilterValueTextField's coordinator re-asserted makeFirstResponder on the main window on every SwiftUI update pass while focusedFilterId matched. The switcher popover lives in a separate window, so AppKit never resigned the filter field, focusedFilterId never cleared, and the filter field kept reclaiming focus against the popover. The search field's own claim was a one-shot DispatchQueue.main.async fired from makeNSView while field.window was still nil, and it never made the popover window key, so key events stayed routed to the main window.

Fix

  • FilterValueTextField: new FilterFocusState value type. Focus is claimed once per transition instead of re-asserted by polling, and released when the main window resigns key (NSWindow.didResignKeyNotification). The filter field no longer fights any popover, panel, or sheet.
  • NativeSearchField: the focusOnAppear claim moved to viewDidMoveToWindow, where the window is guaranteed non-nil, and now calls makeKey() so key events route to the popover window. This also hardens the database switcher and quick switcher, which share this component.
  • MainContentCommandActions: openConnectionSwitcher() and openDatabaseSwitcher() call makeFirstResponder(nil) first, the documented way to end editing. Pending filter text is committed, not discarded.

This matches the platform contract documented by NSSearchToolbarItem.beginSearchInteraction() ("moves the keyboard focus to the search field") and the HIG guidance to start dedicated search areas focused.

Tests

  • New FilterFocusStateTests covers every transition of the focus state machine, including the exact regression: a repeated request must not re-claim focus. 7/7 passed.
  • Existing FilterValueTextFieldTests still pass (28/28).
  • swiftlint lint --strict clean on changed files.
  • No UI automation for this flow: asserting AXFocused across an NSPopover window is not deterministic in CI (the popover window must be key before accessibility queries are valid).

Manual verification

  1. Open a table, open the filter panel, click into the filter value input.
  2. Open the connection switcher (toolbar button or Cmd+Opt+C). The search field has the cursor; typing filters immediately.
  3. Same for the database switcher (Cmd+K).
  4. Esc dismisses the popover; the filter text is intact.

@datlechin datlechin merged commit c484aaf into main Jun 5, 2026
4 checks passed
@datlechin datlechin deleted the fix/1575-connection-search-focus branch June 5, 2026 19:08
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.

Focus issue in connection search

1 participant