Skip to content

Commit 2e7c553

Browse files
authored
Add capability to select next occurrence (#820)
1 parent b8581ef commit 2e7c553

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

CoreEditor/src/bridge/web/search.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
updateQuery,
77
updateHasSelection,
88
selectAllOccurrences,
9+
selectNextOccurrence,
910
findNext,
1011
findPrevious,
1112
replaceNext,
@@ -30,6 +31,7 @@ export interface WebModuleSearch extends WebModule {
3031
replaceNext(): void;
3132
replaceAll(): void;
3233
selectAllOccurrences(): void;
34+
selectNextOccurrence(): void;
3335
numberOfMatches(): CodeGen_Int;
3436
}
3537

@@ -76,6 +78,10 @@ export class WebModuleSearchImpl implements WebModuleSearch {
7678
selectAllOccurrences();
7779
}
7880

81+
selectNextOccurrence(): void {
82+
selectNextOccurrence();
83+
}
84+
7985
numberOfMatches(): CodeGen_Int {
8086
return numberOfMatches();
8187
}

CoreEditor/src/modules/search/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
findNext as findNextCommand,
44
findPrevious as findPreviousCommand,
55
replaceNext as replaceNextCommand,
6+
selectNextOccurrence as selectNextOccurrenceCommand,
67
} from '@codemirror/search';
78

89
import { Command } from '@codemirror/view';
@@ -117,6 +118,10 @@ export function selectAllOccurrences() {
117118
}
118119
}
119120

121+
export function selectNextOccurrence() {
122+
selectNextOccurrenceCommand(window.editor);
123+
}
124+
120125
export function numberOfMatches(): CodeGen_Int {
121126
const query = getSearchQuery(window.editor.state);
122127
const ranges = rangesFromQuery(query);

MarkEditKit/Sources/Bridge/Web/Generated/WebBridgeSearch.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public final class WebBridgeSearch {
112112
webView?.invoke(path: "webModules.search.selectAllOccurrences", completion: completion)
113113
}
114114

115+
public func selectNextOccurrence(completion: ((Result<Void, WKWebView.InvokeError>) -> Void)? = nil) {
116+
webView?.invoke(path: "webModules.search.selectNextOccurrence", completion: completion)
117+
}
118+
115119
public func numberOfMatches() async throws -> Int {
116120
return try await withCheckedThrowingContinuation { continuation in
117121
webView?.invoke(path: "webModules.search.numberOfMatches") { result in

MarkEditMac/Base.lproj/Main.storyboard

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ Gw
574574
<action selector="selectAllOccurrences:" target="Ady-hI-5gd" id="83F-Vk-zez"/>
575575
</connections>
576576
</menuItem>
577+
<menuItem title="Select Next Occurrence" keyEquivalent="d" id="VIj-UD-bGA">
578+
<connections>
579+
<action selector="selectNextOccurrence:" target="Ady-hI-5gd" id="d1k-Qg-XA4"/>
580+
</connections>
581+
</menuItem>
577582
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
578583
<connections>
579584
<action selector="scrollToSelection:" target="Ady-hI-5gd" id="2gs-Ni-NAC"/>

MarkEditMac/Sources/Editor/Controllers/EditorViewController+Menu.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ extension EditorViewController {
333333
selectAllOccurrences()
334334
}
335335

336+
@IBAction func selectNextOccurrence(_ sender: Any?) {
337+
selectNextOccurrence()
338+
}
339+
336340
@IBAction func scrollToSelection(_ sender: Any?) {
337341
bridge.selection.scrollToSelection()
338342
}

MarkEditMac/Sources/Editor/Controllers/EditorViewController+TextFinder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ extension EditorViewController {
196196
bridge.search.selectAllOccurrences()
197197
}
198198

199+
func selectNextOccurrence() {
200+
bridge.search.selectNextOccurrence()
201+
}
202+
199203
func performSearchOperation(_ operation: SearchOperation) {
200204
bridge.search.performOperation(operation: operation)
201205

MarkEditMac/mul.lproj/Main.xcstrings

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,30 @@
37453745
}
37463746
}
37473747
},
3748+
"VIj-UD-bGA.title" : {
3749+
"comment" : "Class = \"NSMenuItem\"; title = \"Select Next Occurrence\"; ObjectID = \"VIj-UD-bGA\";",
3750+
"extractionState" : "extracted_with_value",
3751+
"localizations" : {
3752+
"en" : {
3753+
"stringUnit" : {
3754+
"state" : "new",
3755+
"value" : "Select Next Occurrence"
3756+
}
3757+
},
3758+
"zh-Hans" : {
3759+
"stringUnit" : {
3760+
"state" : "translated",
3761+
"value" : "选择下个相同项"
3762+
}
3763+
},
3764+
"zh-Hant" : {
3765+
"stringUnit" : {
3766+
"state" : "translated",
3767+
"value" : "選擇下個相同項"
3768+
}
3769+
}
3770+
}
3771+
},
37483772
"vmV-6d-7jI.title" : {
37493773
"comment" : "Class = \"NSMenuItem\"; title = \"Make Upper Case\"; ObjectID = \"vmV-6d-7jI\";",
37503774
"extractionState" : "extracted_with_value",

0 commit comments

Comments
 (0)