diff options
Diffstat (limited to 'subprojects/frontend/src/editor/findOccurrences.ts')
-rw-r--r-- | subprojects/frontend/src/editor/findOccurrences.ts | 28 |
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 @@ | |||
1 | import { type Range, RangeSet, type TransactionSpec } from '@codemirror/state'; | 1 | import { |
2 | type Range, | ||
3 | RangeSet, | ||
4 | type TransactionSpec, | ||
5 | type EditorState, | ||
6 | } from '@codemirror/state'; | ||
2 | import { Decoration } from '@codemirror/view'; | 7 | import { Decoration } from '@codemirror/view'; |
3 | 8 | ||
4 | import defineDecorationSetExtension from './defineDecorationSetExtension'; | 9 | import defineDecorationSetExtension from './defineDecorationSetExtension'; |
@@ -34,4 +39,25 @@ export function setOccurrences( | |||
34 | return setOccurrencesInteral(rangeSet); | 39 | return setOccurrencesInteral(rangeSet); |
35 | } | 40 | } |
36 | 41 | ||
42 | export 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 | |||
37 | export default findOccurrences; | 63 | export default findOccurrences; |