chore(code/find): reimplement single replace

This commit is contained in:
Elian Doran
2025-05-12 23:52:41 +03:00
parent 690337ee40
commit b646475018
3 changed files with 19 additions and 35 deletions

View File

@@ -46,6 +46,17 @@ export class SearchHighlighter {
this.#scrollToMatchNearestSelection();
}
replaceActiveMatch(replacementText: string) {
if (!this.parsedMatches.length || this.currentFound === 0) return;
const matchIndex = this.currentFound - 1;
const match = this.parsedMatches[matchIndex];
this.view.dispatch({
changes: { from: match.from, to: match.to, insert: replacementText }
});
}
scrollToMatch(matchIndex: number) {
if (this.parsedMatches.length <= matchIndex) {
return;

View File

@@ -194,6 +194,10 @@ export default class CodeMirror extends EditorView {
this.searchPlugin?.scrollToMatch(nextFound);
}
async replace(replaceText: string) {
this.searchPlugin?.replaceActiveMatch(replaceText);
}
cleanSearch() {
if (this.searchPlugin) {
this.dispatch({