aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-25 00:14:51 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-25 00:14:51 +0200
commit71491e03468795404751d2edfe58ce78714a5ed1 (patch)
tree14131145cdd704b606f3677e61981be6ab921241 /subprojects/frontend/src/editor
parentfix(frontend): editor font thickness (diff)
downloadrefinery-71491e03468795404751d2edfe58ce78714a5ed1.tar.gz
refinery-71491e03468795404751d2edfe58ce78714a5ed1.tar.zst
refinery-71491e03468795404751d2edfe58ce78714a5ed1.zip
refactor(frontend): xtext update improvements
Diffstat (limited to 'subprojects/frontend/src/editor')
-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;