fix(code/find): clean up search

This commit is contained in:
Elian Doran 2025-05-12 22:17:10 +03:00
parent da6cb71c6a
commit 77fe100591
No known key found for this signature in database
2 changed files with 10 additions and 23 deletions

View File

@ -51,29 +51,7 @@ export default class FindInCode {
async findBoxClosed(totalFound: number, currentFound: number) { async findBoxClosed(totalFound: number, currentFound: number) {
const codeEditor = await this.getCodeEditor(); const codeEditor = await this.getCodeEditor();
codeEditor?.cleanSearch();
if (codeEditor && totalFound > 0) {
const doc = codeEditor.doc;
const pos = this.findResult?.[currentFound].find();
// Note setting the selection sets the cursor to
// the end of the selection and scrolls it into
// view
if (pos) {
doc.setSelection(pos.from, pos.to);
}
// Clear all markers
codeEditor.operation(() => {
if (!this.findResult) {
return;
}
for (let i = 0; i < this.findResult.length; ++i) {
let marker = this.findResult[i];
marker.clear();
}
});
}
this.findResult = null;
codeEditor?.focus(); codeEditor?.focus();
} }
async replace(replaceText: string) { async replace(replaceText: string) {

View File

@ -194,6 +194,15 @@ export default class CodeMirror extends EditorView {
this.searchPlugin?.scrollToMatch(nextFound); this.searchPlugin?.scrollToMatch(nextFound);
} }
cleanSearch() {
if (this.searchPlugin) {
this.dispatch({
effects: this.searchHighlightCompartment.reconfigure([])
});
this.searchPlugin = null;
}
}
async setMimeType(mime: string) { async setMimeType(mime: string) {
let newExtension: Extension[] = []; let newExtension: Extension[] = [];