-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
selectLeft.ts
18 lines (17 loc) · 992 Bytes
/
selectLeft.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { TreeNode } from '../../../SyntaxTreeComponents/Nodes/Base/TreeNode';
import { Placeholder } from '../../../SyntaxTreeComponents/Placeholder/Placeholder';
import { KeyboardMemory } from '../../KeyboardMemory';
import { setSelectionDiff } from './helpers/setSelectionDiff';
export function selectLeft(k: KeyboardMemory): void {
const oldDiffWithCurrent = k.selectionDiff ?? 0;
if ((k.current instanceof TreeNode && k.current.parentPlaceholder.nodes.indexOf(k.current) + oldDiffWithCurrent >= 0) || (k.current instanceof Placeholder && oldDiffWithCurrent > 0)) {
setSelectionDiff(k, oldDiffWithCurrent - 1);
} else if (
k.inclusiveSelectionLeftBorder instanceof TreeNode &&
k.inclusiveSelectionLeftBorder.parentPlaceholder.nodes.indexOf(k.inclusiveSelectionLeftBorder) == 0 &&
k.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode != null
) {
k.current = k.inclusiveSelectionLeftBorder.parentPlaceholder.parentNode;
setSelectionDiff(k, -1);
}
}