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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Installing or updating a plugin right after updating TablePro now refetches the current plugin list first, so it no longer fails against a stale cached list (the error a restart used to clear). (#1380)
- Pressing Esc to close the Raw SQL filter suggestions, or to clear a search field, no longer also exits fullscreen. (#1403)

## [0.44.0] - 2026-05-23

Expand Down
49 changes: 33 additions & 16 deletions TablePro/Views/Filter/FilterValueTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ struct FilterValueTextField: NSViewRepresentable {
return (ns.replacingCharacters(in: range, with: insertText), caret)
}

enum SuggestionKeyOutcome: Equatable {
case moveSelection(Int)
case accept(submitting: Bool)
case dismiss
case passThrough
}

static func suggestionKeyOutcome(for key: KeyCode?, submitsOnAccept: Bool) -> SuggestionKeyOutcome {
switch key {
case .downArrow: return .moveSelection(1)
case .upArrow: return .moveSelection(-1)
case .return: return .accept(submitting: submitsOnAccept)
case .tab: return .accept(submitting: false)
case .escape: return .dismiss
default: return .passThrough
}
}

func makeNSView(context: Context) -> NSTextField {
let textField = SubstitutionDisabledTextField()
textField.bezelStyle = .roundedBezel
Expand Down Expand Up @@ -176,6 +194,10 @@ struct FilterValueTextField: NSViewRepresentable {
text.wrappedValue = textView.string
return true
}
if commandSelector == #selector(NSResponder.cancelOperation(_:)) {
dismissSuggestions()
return true
}
return false
}

Expand Down Expand Up @@ -291,25 +313,20 @@ struct FilterValueTextField: NSViewRepresentable {
nsEvent.window?.firstResponder === textField.currentEditor()
else { return nsEvent }

switch nsEvent.semanticKeyCode {
case .downArrow:
self.moveSelection(by: 1)
return nil
case .upArrow:
self.moveSelection(by: -1)
return nil
case .return:
self.acceptCurrentSelection(submitting: self.submitsOnAccept)
return nil
case .tab:
self.acceptCurrentSelection(submitting: false)
return nil
case .escape:
switch FilterValueTextField.suggestionKeyOutcome(
for: nsEvent.semanticKeyCode,
submitsOnAccept: self.submitsOnAccept
) {
case .moveSelection(let delta):
self.moveSelection(by: delta)
case .accept(let submitting):
self.acceptCurrentSelection(submitting: submitting)
case .dismiss:
self.dismissSuggestions()
return nsEvent
default:
case .passThrough:
return nsEvent
}
return nil
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions TablePro/Views/Sidebar/NativeSearchField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ struct NativeSearchField: NSViewRepresentable {
if !field.stringValue.isEmpty {
field.stringValue = ""
text.wrappedValue = ""
return true
}
return false
return true
}
if commandSelector == #selector(NSResponder.moveUp(_:)), let onMoveUp {
onMoveUp()
Expand Down
20 changes: 20 additions & 0 deletions TableProTests/Views/Filter/FilterValueTextFieldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,24 @@ struct FilterValueTextFieldTests {
)
#expect(result == nil)
}

@Test("Escape dismisses the suggestions and is consumed, not passed through")
func testKeyOutcome_escapeDismisses() {
#expect(FilterValueTextField.suggestionKeyOutcome(for: .escape, submitsOnAccept: true) == .dismiss)
#expect(FilterValueTextField.suggestionKeyOutcome(for: .escape, submitsOnAccept: false) == .dismiss)
}

@Test("Arrow and accept keys map to consuming outcomes")
func testKeyOutcome_navigationAndAccept() {
#expect(FilterValueTextField.suggestionKeyOutcome(for: .downArrow, submitsOnAccept: false) == .moveSelection(1))
#expect(FilterValueTextField.suggestionKeyOutcome(for: .upArrow, submitsOnAccept: false) == .moveSelection(-1))
#expect(FilterValueTextField.suggestionKeyOutcome(for: .return, submitsOnAccept: true) == .accept(submitting: true))
#expect(FilterValueTextField.suggestionKeyOutcome(for: .tab, submitsOnAccept: true) == .accept(submitting: false))
}

@Test("Unhandled keys pass through unchanged")
func testKeyOutcome_passThrough() {
#expect(FilterValueTextField.suggestionKeyOutcome(for: .space, submitsOnAccept: true) == .passThrough)
#expect(FilterValueTextField.suggestionKeyOutcome(for: nil, submitsOnAccept: true) == .passThrough)
}
}
Loading