mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
chore(code/find): reimplement replace all
This commit is contained in:
parent
b646475018
commit
3ace3d9ed9
@ -61,23 +61,7 @@ export default class FindInCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async replaceAll(replaceText: string) {
|
async replaceAll(replaceText: string) {
|
||||||
if (!this.findResult || this.findResult.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const codeEditor = await this.getCodeEditor();
|
const codeEditor = await this.getCodeEditor();
|
||||||
const doc = codeEditor?.doc;
|
codeEditor?.replaceAll(replaceText);
|
||||||
codeEditor?.operation(() => {
|
|
||||||
if (!this.findResult) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let currentFound = 0; currentFound < this.findResult.length; currentFound++) {
|
|
||||||
let marker = this.findResult[currentFound];
|
|
||||||
let pos = marker.find();
|
|
||||||
doc?.replaceRange(replaceText, pos.from, pos.to);
|
|
||||||
marker.clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.findResult = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,18 @@ export class SearchHighlighter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replaceAll(replacementText: string) {
|
||||||
|
if (!this.parsedMatches.length) return;
|
||||||
|
|
||||||
|
this.view.dispatch({
|
||||||
|
changes: this.parsedMatches.map(change => ({
|
||||||
|
from: change.from,
|
||||||
|
to: change.to,
|
||||||
|
insert: replacementText
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
scrollToMatch(matchIndex: number) {
|
scrollToMatch(matchIndex: number) {
|
||||||
if (this.parsedMatches.length <= matchIndex) {
|
if (this.parsedMatches.length <= matchIndex) {
|
||||||
return;
|
return;
|
||||||
|
@ -198,6 +198,10 @@ export default class CodeMirror extends EditorView {
|
|||||||
this.searchPlugin?.replaceActiveMatch(replaceText);
|
this.searchPlugin?.replaceActiveMatch(replaceText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async replaceAll(replaceText: string) {
|
||||||
|
this.searchPlugin?.replaceAll(replaceText);
|
||||||
|
}
|
||||||
|
|
||||||
cleanSearch() {
|
cleanSearch() {
|
||||||
if (this.searchPlugin) {
|
if (this.searchPlugin) {
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user