Skip to content

fix: auto-focus SQL editor on new tab and restore cursor on tab switch#498

Merged
datlechin merged 1 commit intomainfrom
fix/editor-auto-focus
Mar 29, 2026
Merged

fix: auto-focus SQL editor on new tab and restore cursor on tab switch#498
datlechin merged 1 commit intomainfrom
fix/editor-auto-focus

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

  • Auto-focus the SQL editor when opening a new query tab so users can type immediately without clicking
  • Restore cursor blink when switching between editor tabs

Root Cause

  • No auto-focus: prepareCoordinator never called makeFirstResponder on the editor's text view, and SourceEditorState() initializes with nil cursor positions — so even with focus, insertText had no insertion point
  • Missing cursor on tab switch: resignKeyWindow calls removeCursors() destroying cursor subviews, but becomeKeyWindow only resets the blink timer without recreating them

Changes

SQLEditorCoordinator.swift:

  • In prepareCoordinator: call makeFirstResponder then setCursorPositions (order matters — cursor view creation guards on isFirstResponder)
  • Add NSWindow.didBecomeKeyNotification observer to re-apply cursor positions when window regains key status

Test plan

  • Open a connection → first tab editor is auto-focused with blinking cursor, can type immediately
  • Cmd+T to open second tab → editor is auto-focused
  • Switch between tabs → cursor blinks correctly on each tab
  • Typing works on all tabs without clicking first

@datlechin datlechin force-pushed the fix/editor-auto-focus branch from 87d5516 to 9c85de3 Compare March 29, 2026 11:14
@datlechin datlechin force-pushed the fix/editor-auto-focus branch from 9c85de3 to 711c66a Compare March 29, 2026 11:16
@datlechin datlechin merged commit dacbab8 into main Mar 29, 2026
2 checks passed
@datlechin datlechin deleted the fix/editor-auto-focus branch March 29, 2026 11: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.

1 participant