File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
Sources/CodeEditSourceEditor Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,11 @@ extension TextViewController {
122122 if let localEventMonitor = self . localEvenMonitor {
123123 NSEvent . removeMonitor ( localEventMonitor)
124124 }
125- self . localEvenMonitor = NSEvent . addLocalMonitorForEvents ( matching: . keyDown) { [ weak self] event -> NSEvent ? in
125+ setUpKeyBindings ( eventMonitor: & self . localEvenMonitor)
126+ }
127+
128+ func setUpKeyBindings( eventMonitor: inout Any ? ) {
129+ eventMonitor = NSEvent . addLocalMonitorForEvents ( matching: . keyDown) { [ weak self] event -> NSEvent ? in
126130 guard self ? . view. window? . firstResponder == self ? . textView else { return event }
127131 let modifierFlags = event. modifierFlags. intersection ( . deviceIndependentFlagsMask)
128132
@@ -142,6 +146,7 @@ extension TextViewController {
142146 }
143147 }
144148 }
149+
145150 func handleCommand( event: NSEvent , modifierFlags: UInt ) -> NSEvent ? {
146151 let commandKey = NSEvent . ModifierFlags. command. rawValue
147152
Original file line number Diff line number Diff line change @@ -289,7 +289,7 @@ extension FindViewController: FindPanelDelegate {
289289 }
290290 }
291291
292- func searchFile( query: String ) {
292+ func searchFile( query: String , respectCursorPosition : Bool = true ) {
293293 guard let target = target,
294294 let emphasizeAPI = target. emphasizeAPI else {
295295 findPanel. searchDelegate? . findPanelUpdateMatchCount ( 0 )
@@ -324,7 +324,7 @@ extension FindViewController: FindPanelDelegate {
324324 findPanel. searchDelegate? . findPanelUpdateMatchCount ( searchResults. count)
325325
326326 // Get the nearest match to either the cursor or visible area
327- let activeIndex = getNearestHighlightIndex ( matchRanges: searchResults) ?? 0
327+ let activeIndex = respectCursorPosition ? getNearestHighlightIndex ( matchRanges: searchResults) ?? 0 : 0
328328
329329 emphasizeAPI. emphasizeRanges ( ranges: searchResults, activeIndex: activeIndex)
330330
@@ -356,7 +356,7 @@ extension FindViewController: FindPanelDelegate {
356356
357357 // Binary search for the nearest match
358358 var left = 0 , right = matchRanges. count - 1
359- var bestIndex : Int ? = nil
359+ var bestIndex : Int ?
360360 var bestDiff = Int . max
361361
362362 while left <= right {
You can’t perform that action at this time.
0 commit comments