Skip to content

Commit

Permalink
Add capability to select next occurrence (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Jan 18, 2025
1 parent b8581ef commit 2e7c553
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CoreEditor/src/bridge/web/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
updateQuery,
updateHasSelection,
selectAllOccurrences,
selectNextOccurrence,
findNext,
findPrevious,
replaceNext,
Expand All @@ -30,6 +31,7 @@ export interface WebModuleSearch extends WebModule {
replaceNext(): void;
replaceAll(): void;
selectAllOccurrences(): void;
selectNextOccurrence(): void;
numberOfMatches(): CodeGen_Int;
}

Expand Down Expand Up @@ -76,6 +78,10 @@ export class WebModuleSearchImpl implements WebModuleSearch {
selectAllOccurrences();
}

selectNextOccurrence(): void {
selectNextOccurrence();
}

numberOfMatches(): CodeGen_Int {
return numberOfMatches();
}
Expand Down
5 changes: 5 additions & 0 deletions CoreEditor/src/modules/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
findNext as findNextCommand,
findPrevious as findPreviousCommand,
replaceNext as replaceNextCommand,
selectNextOccurrence as selectNextOccurrenceCommand,
} from '@codemirror/search';

import { Command } from '@codemirror/view';
Expand Down Expand Up @@ -117,6 +118,10 @@ export function selectAllOccurrences() {
}
}

export function selectNextOccurrence() {
selectNextOccurrenceCommand(window.editor);
}

export function numberOfMatches(): CodeGen_Int {
const query = getSearchQuery(window.editor.state);
const ranges = rangesFromQuery(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public final class WebBridgeSearch {
webView?.invoke(path: "webModules.search.selectAllOccurrences", completion: completion)
}

public func selectNextOccurrence(completion: ((Result<Void, WKWebView.InvokeError>) -> Void)? = nil) {
webView?.invoke(path: "webModules.search.selectNextOccurrence", completion: completion)
}

public func numberOfMatches() async throws -> Int {
return try await withCheckedThrowingContinuation { continuation in
webView?.invoke(path: "webModules.search.numberOfMatches") { result in
Expand Down
5 changes: 5 additions & 0 deletions MarkEditMac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ Gw
<action selector="selectAllOccurrences:" target="Ady-hI-5gd" id="83F-Vk-zez"/>
</connections>
</menuItem>
<menuItem title="Select Next Occurrence" keyEquivalent="d" id="VIj-UD-bGA">
<connections>
<action selector="selectNextOccurrence:" target="Ady-hI-5gd" id="d1k-Qg-XA4"/>
</connections>
</menuItem>
<menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
<connections>
<action selector="scrollToSelection:" target="Ady-hI-5gd" id="2gs-Ni-NAC"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ extension EditorViewController {
selectAllOccurrences()
}

@IBAction func selectNextOccurrence(_ sender: Any?) {
selectNextOccurrence()
}

@IBAction func scrollToSelection(_ sender: Any?) {
bridge.selection.scrollToSelection()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ extension EditorViewController {
bridge.search.selectAllOccurrences()
}

func selectNextOccurrence() {
bridge.search.selectNextOccurrence()
}

func performSearchOperation(_ operation: SearchOperation) {
bridge.search.performOperation(operation: operation)

Expand Down
24 changes: 24 additions & 0 deletions MarkEditMac/mul.lproj/Main.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3745,6 +3745,30 @@
}
}
},
"VIj-UD-bGA.title" : {
"comment" : "Class = \"NSMenuItem\"; title = \"Select Next Occurrence\"; ObjectID = \"VIj-UD-bGA\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Select Next Occurrence"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "选择下个相同项"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "選擇下個相同項"
}
}
}
},
"vmV-6d-7jI.title" : {
"comment" : "Class = \"NSMenuItem\"; title = \"Make Upper Case\"; ObjectID = \"vmV-6d-7jI\";",
"extractionState" : "extracted_with_value",
Expand Down

0 comments on commit 2e7c553

Please sign in to comment.