-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Placeholder.ts
27 lines (25 loc) · 1.11 KB
/
Placeholder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { LatexConfiguration } from '../../LatexConfiguration';
import { KeyboardMemory } from '../../KeyboardEngine/KeyboardMemory';
import { TreeNode } from '../Nodes/Base/TreeNode';
import { BranchingNode } from '../Nodes/Base/BranchingNode';
import { concatLatex } from '../../helpers/stringhelpers/concatLatex';
export class Placeholder {
parentNode: BranchingNode | null = null;
nodes: TreeNode[] = [];
getLatex(k: KeyboardMemory, latexConfiguration: LatexConfiguration): string {
const concatNodes = () => concatLatex(...this.nodes.map((node) => node.getLatex(k, latexConfiguration)));
if (k.inclusiveSelectionLeftBorder === this) {
return concatLatex(latexConfiguration.selectionHightlightStart, concatNodes());
} else if (this === k.current) {
if (this.nodes.length == 0) {
return latexConfiguration.activePlaceholderLatex;
} else {
return concatLatex(latexConfiguration.activePlaceholderLatex, concatNodes());
}
} else if (this.nodes.length == 0) {
return latexConfiguration.passivePlaceholderLatex;
} else {
return concatNodes();
}
}
}