fix(editor): focus new editor tab on cold start (#1765)#1767
Merged
Conversation
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.
Follow-up to #1766 (merged). On the first ⌘T after a cold app launch the new editor still didn't get keyboard focus (first line was highlighted but no caret); you had to click into the editor once, after which later new tabs focused correctly.
Root cause
In #1766 the focus-claim latch was armed from
SQLEditorView's.onAppear.prepareCoordinatorclaims focus from a 50ms-deferred task that starts duringmakeNSView, which runs before.onAppear. On a warm app the view appears within 50ms so the latch is armed in time; on a cold first launch the view appears later than 50ms, so the deferred task runs first, sees no pending claim, falls through to the oldfirstResponder == nilbranch, and the sidebar filter (auto-assigned first responder on a fresh window) keeps focus.Fix
Arm the latch in
bodyagain, which runs synchronously beforemakeNSViewstarts the deferred task, sofocusClaimPendingis always set before it's read, regardless of cold/warm timing. Arming via the one-shotscheduleEditorFocusClaim()(which only ever sets the flag true, cleared on consume ordestroy()) means a body re-render can't clear it early.Also added OSLog instrumentation under
com.TablePro / SQLEditorCoordinatorto confirm the path:Editor focus claim: pending=… isKey=… responderBefore=… made=…Editor focus claim skipped: hasWindow=… destroyed=… pending=…Notes
swiftlint lint --strictclean on the changed files.Editor focus claimlines).