Skip to content

fix(editor): focus new editor tab on cold start (#1765)#1767

Merged
datlechin merged 2 commits into
mainfrom
fix/new-tab-focus-coldstart
Jun 25, 2026
Merged

fix(editor): focus new editor tab on cold start (#1765)#1767
datlechin merged 2 commits into
mainfrom
fix/new-tab-focus-coldstart

Conversation

@datlechin

Copy link
Copy Markdown
Member

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. prepareCoordinator claims focus from a 50ms-deferred task that starts during makeNSView, 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 old firstResponder == nil branch, and the sidebar filter (auto-assigned first responder on a fresh window) keeps focus.

Fix

Arm the latch in body again, which runs synchronously before makeNSView starts the deferred task, so focusClaimPending is always set before it's read, regardless of cold/warm timing. Arming via the one-shot scheduleEditorFocusClaim() (which only ever sets the flag true, cleared on consume or destroy()) means a body re-render can't clear it early.

Also added OSLog instrumentation under com.TablePro / SQLEditorCoordinator to confirm the path:

  • Editor focus claim: pending=… isKey=… responderBefore=… made=…
  • Editor focus claim skipped: hasWindow=… destroyed=… pending=…

Notes

  • swiftlint lint --strict clean on the changed files.
  • The build is verified by the user; please reproduce the cold-start ⌘T and confirm the caret lands in the editor (Console will show the Editor focus claim lines).

@datlechin datlechin merged commit cfd8055 into main Jun 25, 2026
2 checks passed
@datlechin datlechin deleted the fix/new-tab-focus-coldstart branch June 25, 2026 08:12
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.

1 participant