Skip to content

fix: scope sidebar selection per-window, stop schema polling on focus (#1313)#1314

Merged
datlechin merged 7 commits into
mainfrom
debug/1313-tab-focus-logs
May 18, 2026
Merged

fix: scope sidebar selection per-window, stop schema polling on focus (#1313)#1314
datlechin merged 7 commits into
mainfrom
debug/1313-tab-focus-logs

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Fixes #1313 (Cmd+T on SQLite jumps focus back to previous tab) and removes the redundant focus-based schema polling that caused sidebar flicker.

Root cause

Two unrelated issues that compounded:

  1. Sidebar state mis-scoped. SharedSidebarState.selectedTables was shared at the connection level, so a new window mounted with the previously-clicked table already selected. SwiftUI's .onChange(of: tables) fired during mount, called openTableTab, which then redirected focus to the sibling window that already had that table open.

  2. openTableTab redirected to siblings unconditionally. Even sidebar clicks were redirected, stealing focus from the window the user was looking at. The redirect only makes sense for cross-window navigation (e.g. quick switcher).

  3. Schema was polled on every window-becomes-key event for file-based databases (SQLite, DuckDB), causing the sidebar to flash every time the user switched windows. DatabaseFileWatcher already covers external file changes via DispatchSource, so the polling was redundant.

Fix

  • Move selectedTables from SharedSidebarState (connection-scoped) to WindowSidebarState (per-window). Each window owns its sidebar selection.
  • Add redirectToSibling: Bool = false to openTableTab. Default off; quick switcher opts in.
  • Remove refreshTablesIfStale and reloadIfStale. Trust DatabaseFileWatcher (kqueue-based, event-driven, debounced 500ms) as the single source for picking up external file changes.
  • Add INFO logs to DatabaseFileWatcher (watch start, event fire) so the watcher is verifiable in production.

Net -117 lines of code, no hacks, no polling, no time-based heuristics. Native AppKit + Darwin file event APIs handle everything.

Test plan

  • Open SQLite, click a table (preview tab), press Cmd+T. New window keeps focus, sidebar does not flash.
  • Open SQLite, modify file via sqlite3 ~/test.db "CREATE TABLE x (id INT)". Sidebar shows new table within ~500ms.
  • Click a table in window A; window B's sidebar selection unchanged.
  • Cmd+P (quick switcher) → find a table open in another window → Enter. Focus jumps to that window (existing UX preserved).
  • Switch focus between windows of the same SQLite connection. No sidebar flicker.
  • Repeat on DuckDB (also file-based).
  • Regression: open MySQL/PostgreSQL connection, browse tables, Cmd+T works as before.

@datlechin datlechin merged commit 7469676 into main May 18, 2026
2 checks passed
@datlechin datlechin deleted the debug/1313-tab-focus-logs branch May 18, 2026 07:17
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.

SQLite new query tab auto jump to other tab

1 participant