fix(tabs): name the tab after the SQL file when opening from disk (#1220)#1448
Merged
Conversation
4620715 to
08eb10e
Compare
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.
Fixes the follow-up reported on #1220: opening a
.sqlscript via File > Open (or Finder, oropen file.sql) named the tab "SQL Query" instead of the file name.Root cause
The CLAUDE.md "Window tab titles" invariant calls out two resolution sites that must stay in sync. They were out of sync for the file case:
MainSplitViewController.init's title cascade had branches fortabTitle,tableName, and the connection language fallback, but no branch forpayload.sourceFileURL. A file-open payload fell through to"{language} Query".updateWindowTitleAndFileState()did have asourceFileURLbranch, but it only runs ononChange(of: selectedTabId)/ structure-change. Neither fires on the first frame of a newly opened window whose single tab was populated insideinit(SwiftUI sees the value already set; no change to observe). So the wrong title stuck.Favorites and table tabs worked because they pass
tabTitle/tableNameexplicitly.TabRouter.openSQLFiledid not.Fix
sourceFileURLbranch to the resolution cascade, so all file-open paths get a correct title at first frame, not justTabRouter.openSQLFile.static func MainSplitViewController.resolveDefaultTitle(payload:queryLanguageName:)so the invariant is now covered by unit tests, not just careful reading.QueryTab.fileDisplayTitle(for:)helper that wrapsFileManager.default.displayName(atPath:). This is the native API NSDocument / TextEdit / Xcode use; it respects the user's "Show all filename extensions" Finder preference, unlike the hand-rolledurl.deletingPathExtension().lastPathComponentit replaces.String(format: String(localized: "%@ Query"), …)), matching whatupdateWindowTitleAndFileStatealready does. The init path was the only place still using"\(langName) Query"literal interpolation.Tests
TableProTests/Services/MainSplitViewControllerTitleTests.swiftcovers every branch ofresolveDefaultTitle, theQueryTab.fileDisplayTitlehelper, andQueryTabManager.addTabwithsourceFileURL. The key regression test asserts asourceFileURLpayload no longer resolves to"PostgreSQL Query"or"SQL Query".EditorTabPayloadTests.initFromQueryTabnow assertspayload.tabTitle == tab.title(the gap that would let a restore-path regression slip through), and a new test covers file-backed tab round-trip.Considered and rejected
The simpler "remove the
intent == .newEmptyTabguard so the init reads the created tab's title for all intents" approach would make table tabs in non-default schemas showauth.userson the first frame and then flip to bareusersafter a tab switch, becauseupdateWindowTitleAndFileStateusestableContext.tableName, nottab.title. The explicitsourceFileURLbranch changes no other tab type's behavior.