Skip to content

Commit 56f37c0

Browse files
committed
Renamed find panel cancel actions to dismiss.
1 parent 114c6e9 commit 56f37c0

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ContentView: View {
2424
@State private var cursorPositions: [CursorPosition] = [.init(line: 1, column: 1)]
2525
@AppStorage("systemCursor") private var useSystemCursor: Bool = false
2626
@State private var isInLongParse = false
27+
@State private var settingsIsPresented: Bool = false
2728
@State private var treeSitterClient = TreeSitterClient()
2829

2930
init(document: Binding<CodeEditSourceEditorExampleDocument>, fileURL: URL?) {
@@ -49,21 +50,24 @@ struct ContentView: View {
4950
)
5051
.overlay(alignment: .bottom) {
5152
HStack {
52-
Toggle("Wrap Lines", isOn: $wrapLines)
53-
.toggleStyle(.button)
54-
.buttonStyle(.accessoryBar)
55-
if #available(macOS 14, *) {
56-
Toggle("Use System Cursor", isOn: $useSystemCursor)
57-
.toggleStyle(.button)
58-
.buttonStyle(.accessoryBar)
59-
} else {
60-
Toggle("Use System Cursor", isOn: $useSystemCursor)
61-
.disabled(true)
62-
.help("macOS 14 required")
63-
.toggleStyle(.button)
64-
.buttonStyle(.accessoryBar)
53+
Menu {
54+
Toggle("Wrap Lines", isOn: $wrapLines)
55+
if #available(macOS 14, *) {
56+
Toggle("Use System Cursor", isOn: $useSystemCursor)
57+
} else {
58+
Toggle("Use System Cursor", isOn: $useSystemCursor)
59+
.disabled(true)
60+
.help("macOS 14 required")
61+
}
62+
} label: {}
63+
.background {
64+
Image(systemName: "switch.2")
65+
.foregroundStyle(.secondary)
66+
.font(.system(size: 13.5, weight: .regular))
6567
}
66-
68+
.menuStyle(.borderlessButton)
69+
.menuIndicator(.hidden)
70+
.frame(maxWidth: 18, alignment: .center)
6771
Spacer()
6872
Group {
6973
if isInLongParse {

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ extension TextViewController {
159159
self.searchController?.showFindPanel()
160160
return nil
161161
case (0, "\u{1b}"): // Escape key
162-
self.searchController?.findPanel.cancel()
162+
self.searchController?.findPanel.dismiss()
163163
return nil
164164
case (_, _):
165165
return event

Sources/CodeEditSourceEditor/Find/FindPanelDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
protocol FindPanelDelegate: AnyObject {
1111
func findPanelOnSubmit()
12-
func findPanelOnCancel()
12+
func findPanelOnDismiss()
1313
func findPanelDidUpdate(_ searchText: String)
1414
func findPanelPrevButtonClicked()
1515
func findPanelNextButtonClicked()

Sources/CodeEditSourceEditor/Find/FindViewController.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ final class FindViewController: NSViewController {
1616
private var findMatches: [NSRange] = []
1717
private var currentFindMatchIndex: Int = 0
1818
private var findText: String = ""
19-
2019
private var findPanelVerticalConstraint: NSLayoutConstraint!
21-
2220
private(set) public var isShowingFindPanel: Bool = false
2321

2422
init(target: FindPanelTarget, childView: NSView) {
@@ -178,15 +176,6 @@ final class FindViewController: NSViewController {
178176
// MARK: - Toggle find panel
179177

180178
extension FindViewController {
181-
/// Toggle the find panel
182-
func toggleFindPanel() {
183-
if isShowingFindPanel {
184-
hideFindPanel()
185-
} else {
186-
showFindPanel()
187-
}
188-
}
189-
190179
/// Show the find panel
191180
func showFindPanel(animated: Bool = true) {
192181
if isShowingFindPanel {
@@ -260,9 +249,15 @@ extension FindViewController: FindPanelDelegate {
260249
findPanelNextButtonClicked()
261250
}
262251

263-
func findPanelOnCancel() {
252+
func findPanelOnDismiss() {
264253
if isShowingFindPanel {
265254
hideFindPanel()
255+
// Ensure text view becomes first responder after hiding
256+
if let textViewController = target as? TextViewController {
257+
DispatchQueue.main.async {
258+
_ = textViewController.textView.window?.makeFirstResponder(textViewController.textView)
259+
}
260+
}
266261
}
267262
}
268263

Sources/CodeEditSourceEditor/Find/PanelView/FindPanel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final class FindPanel: NSView {
8484
func addEventMonitor() {
8585
eventMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event -> NSEvent? in
8686
if event.keyCode == 53 { // if esc pressed
87-
self?.cancel()
87+
self?.dismiss()
8888
return nil // do not play "beep" sound
8989
}
9090
return event
@@ -100,8 +100,8 @@ final class FindPanel: NSView {
100100

101101
// MARK: - Public Methods
102102

103-
func cancel() {
104-
viewModel.onCancel()
103+
func dismiss() {
104+
viewModel.onDismiss()
105105
}
106106

107107
func updateMatchCount(_ count: Int) {

Sources/CodeEditSourceEditor/Find/PanelView/FindPanelView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct FindPanelView: View {
6565
}
6666
.controlGroupStyle(PanelControlGroupStyle())
6767
.fixedSize()
68-
Button(action: viewModel.onCancel) {
68+
Button(action: viewModel.onDismiss) {
6969
Text("Done")
7070
.padding(.horizontal, 5)
7171
}

Sources/CodeEditSourceEditor/Find/PanelView/FindPanelViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class FindPanelViewModel: ObservableObject {
3333
delegate?.findPanelOnSubmit()
3434
}
3535

36-
func onCancel() {
37-
delegate?.findPanelOnCancel()
36+
func onDismiss() {
37+
delegate?.findPanelOnDismiss()
3838
}
3939

4040
func setFocus(_ focused: Bool) {

Tests/CodeEditSourceEditorTests/Mock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ enum Mock {
6262
isEditable: true,
6363
isSelectable: true,
6464
letterSpacing: 1.0,
65-
useSystemCursor: false
65+
useSystemCursor: false,
66+
bracketPairEmphasis: .flash
6667
)
6768
}
6869

0 commit comments

Comments
 (0)