fix: scope sidebar selection per-window, stop schema polling on focus (#1313)#1314
Merged
Conversation
…op unrelated diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Sidebar state mis-scoped.
SharedSidebarState.selectedTableswas 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, calledopenTableTab, which then redirected focus to the sibling window that already had that table open.openTableTabredirected 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).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.
DatabaseFileWatcheralready covers external file changes viaDispatchSource, so the polling was redundant.Fix
selectedTablesfromSharedSidebarState(connection-scoped) toWindowSidebarState(per-window). Each window owns its sidebar selection.redirectToSibling: Bool = falsetoopenTableTab. Default off; quick switcher opts in.refreshTablesIfStaleandreloadIfStale. TrustDatabaseFileWatcher(kqueue-based, event-driven, debounced 500ms) as the single source for picking up external file changes.DatabaseFileWatcher(watch start, event fire) so the watcher is verifiable in production.Net
-117lines of code, no hacks, no polling, no time-based heuristics. Native AppKit + Darwin file event APIs handle everything.Test plan
sqlite3 ~/test.db "CREATE TABLE x (id INT)". Sidebar shows new table within ~500ms.