Skip to content

fix: auto-selection of first item fails with fast input in Database Switcher (#714) - #715

Merged
datlechin merged 1 commit into
mainfrom
fix/database-switcher-selection
Apr 13, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/database-switcher-selection

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Fix selectedDatabase never updating when search text changes in Database Switcher — caused stale selection on fast typing
  • Move keyboard navigation logic (moveUp/moveDown) from View into ViewModel as synchronous methods, matching QuickSwitcher pattern
  • Fix same stale-selection bug in Foreign Key popover
  • Re-select after Phase 2 metadata load to handle re-sorting

Closes #714

Root cause

DatabaseSwitcherViewModel.searchText had no didSet observer. selectedDatabase was set exactly once during preselectDatabase() at load time and never updated when the filter changed. When typing fast, selectedDatabase pointed to an item no longer in the filtered list.

The QuickSwitcher didn't have this bug because it uses didSet { updateFilter() } on searchText and always ends with selectedItemId = filteredItems.first?.id.

Changes

File Change
DatabaseSwitcherViewModel.swift Add didSet on searchText to auto-select first filtered result; add synchronous moveUp()/moveDown(); call preselectDatabase() after Phase 2 metadata load
DatabaseSwitcherSheet.swift Remove moveSelection(up:) with async Task wrapper; call ViewModel methods directly
ForeignKeyPopoverContentView.swift Add .onChange(of: searchText) to reset selectedId to first filtered value

Test plan

  • Open Database Switcher, type quickly — first result should always be selected
  • Clear text, type slowly — same behavior
  • Arrow keys should navigate immediately (no one-frame lag)
  • Press Return — should open the visually highlighted database
  • Open FK column popover, type to filter — selection should track first result

@datlechin
datlechin merged commit 7f9cba3 into main Apr 13, 2026
2 checks passed
@datlechin
datlechin deleted the fix/database-switcher-selection branch April 13, 2026 02:56
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.

Auto-selection of first item fails with fast input in Open Database Switcher

1 participant