Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions TablePro/Views/Editor/SQLEditorCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ final class SQLEditorCoordinator: TextViewCoordinator, TextViewDelegate {
EditorEventRouter.shared.register(self, textView: textView)

if !self.isDestroyed, let window = textView.window {
if self.focusClaimPending {
let claimPending = self.focusClaimPending
let responderName = window.firstResponder.map { String(describing: type(of: $0)) } ?? "nil"
var made = false
if claimPending {
self.focusClaimPending = false
window.makeFirstResponder(textView)
made = window.makeFirstResponder(textView)
} else if window.firstResponder == nil || window.firstResponder === window {
window.makeFirstResponder(textView)
made = window.makeFirstResponder(textView)
}
Self.logger.debug("Editor focus claim: pending=\(claimPending) isKey=\(window.isKeyWindow) responderBefore=\(responderName, privacy: .public) made=\(made)")
} else {
Self.logger.debug("Editor focus claim skipped: hasWindow=\(textView.window != nil) destroyed=\(self.isDestroyed) pending=\(self.focusClaimPending)")
}
if controller.cursorPositions.isEmpty {
controller.setCursorPositions([CursorPosition(range: NSRange(location: 0, length: 0))])
Expand Down
8 changes: 3 additions & 5 deletions TablePro/Views/Editor/SQLEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct SQLEditorView: View {
coordinator.databaseType = databaseType
coordinator.tabID = tabID
coordinator.connectionId = connectionId
if claimFocusOnAppear {
coordinator.scheduleEditorFocusClaim()
}

return SourceEditor(
$text,
Expand All @@ -60,11 +63,6 @@ struct SQLEditorView: View {
completionDelegate: completionAdapter
)
.accessibilityLabel(String(localized: "SQL query editor"))
.onAppear {
if claimFocusOnAppear {
coordinator.scheduleEditorFocusClaim()
}
}
.onChange(of: editorState.cursorPositions) { _, newValue in
guard let positions = newValue else { return }
// Skip cursor propagation when the editor doesn't have focus
Expand Down
Loading