mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
chore(code/find): update current found
This commit is contained in:
@@ -22,11 +22,13 @@ export function createSearchHighlighter(view: EditorView, searchTerm: string, ma
|
||||
|
||||
return ViewPlugin.fromClass(class SearchHighlighter {
|
||||
matches!: RangeSet<Decoration>;
|
||||
currentFound: number;
|
||||
totalFound: number;
|
||||
private parsedMatches: Match[];
|
||||
|
||||
constructor(public view: EditorView) {
|
||||
this.parsedMatches = [];
|
||||
this.currentFound = 0;
|
||||
this.totalFound = 0;
|
||||
this.updateSearchData(view);
|
||||
}
|
||||
@@ -57,26 +59,27 @@ export function createSearchHighlighter(view: EditorView, searchTerm: string, ma
|
||||
return;
|
||||
}
|
||||
|
||||
this.scrollTo(this.parsedMatches[matchIndex]);
|
||||
}
|
||||
|
||||
scrollToMatchNearestSelection() {
|
||||
const cursorPos = this.view.state.selection.main.head;
|
||||
for (const match of this.parsedMatches) {
|
||||
if (match.from >= cursorPos) {
|
||||
this.scrollTo(match);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private scrollTo(match: Match) {
|
||||
const match = this.parsedMatches[matchIndex];
|
||||
this.currentFound = matchIndex + 1;
|
||||
this.view.dispatch({
|
||||
effects: EditorView.scrollIntoView(match.from, { y: "center" }),
|
||||
scrollIntoView: true
|
||||
});
|
||||
}
|
||||
|
||||
scrollToMatchNearestSelection() {
|
||||
const cursorPos = this.view.state.selection.main.head;
|
||||
let index = 0;
|
||||
for (const match of this.parsedMatches) {
|
||||
if (match.from >= cursorPos) {
|
||||
this.scrollToMatch(index);
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@@ -185,7 +185,8 @@ export default class CodeMirror extends EditorView {
|
||||
}
|
||||
|
||||
return {
|
||||
totalFound: instance?.totalFound ?? 0
|
||||
totalFound: instance?.totalFound ?? 0,
|
||||
currentFound: instance?.currentFound ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user