aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/findOccurrences.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/editor/findOccurrences.ts')
-rw-r--r--subprojects/frontend/src/editor/findOccurrences.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/subprojects/frontend/src/editor/findOccurrences.ts b/subprojects/frontend/src/editor/findOccurrences.ts
index d7aae8d1..08c078c2 100644
--- a/subprojects/frontend/src/editor/findOccurrences.ts
+++ b/subprojects/frontend/src/editor/findOccurrences.ts
@@ -1,4 +1,9 @@
1import { type Range, RangeSet, type TransactionSpec } from '@codemirror/state'; 1import {
2 type Range,
3 RangeSet,
4 type TransactionSpec,
5 type EditorState,
6} from '@codemirror/state';
2import { Decoration } from '@codemirror/view'; 7import { Decoration } from '@codemirror/view';
3 8
4import defineDecorationSetExtension from './defineDecorationSetExtension'; 9import defineDecorationSetExtension from './defineDecorationSetExtension';
@@ -34,4 +39,25 @@ export function setOccurrences(
34 return setOccurrencesInteral(rangeSet); 39 return setOccurrencesInteral(rangeSet);
35} 40}
36 41
42export function isCursorWithinOccurence(state: EditorState): boolean {
43 const occurrences = state.field(findOccurrences, false);
44 if (occurrences === undefined) {
45 return false;
46 }
47 const {
48 selection: {
49 main: { from, to },
50 },
51 } = state;
52 let found = false;
53 occurrences.between(from, to, (decorationFrom, decorationTo) => {
54 if (decorationFrom <= from && to <= decorationTo) {
55 found = true;
56 return false;
57 }
58 return undefined;
59 });
60 return found;
61}
62
37export default findOccurrences; 63export default findOccurrences;