/
EditorDriverInterface.ts
105 lines (88 loc) · 2.58 KB
/
EditorDriverInterface.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
export interface EditorDriverParams {
/**
* An array of HTML class names to apply to the editor's main DOM element.
*/
classNames: string[];
/**
* Whether the editor should be initially disabled.
*/
disabled: boolean;
/**
* An optional placeholder for the editor.
*/
placeholder: string;
/**
* An optional initial value for the editor.
*/
value: string;
/**
* This is separate from inputListeners since the full serialized content will be passed to it.
* It is considered private API, and should not be used/modified by extensions not implementing
* EditorDriverInterface.
*/
oninput: Function;
/**
* Each of these functions will be called on click, input, and keyup.
* No arguments will be passed.
*/
inputListeners: Function[];
/**
* This function will be called if submission is triggered programmatically via keybind.
* No arguments should be passed.
*/
onsubmit: Function;
}
export default interface EditorDriverInterface {
/**
* Focus the editor and place the cursor at the given position.
*/
moveCursorTo(position: number): void;
/**
* Get the selected range of the editor.
*/
getSelectionRange(): Array<number>;
/**
* Get the last N characters from the current "text block".
*
* A textarea-based driver would just return the last N characters,
* but more advanced implementations might restrict to the current block.
*
* This is useful for monitoring recent user input to trigger autocomplete.
*/
getLastNChars(n: number): string;
/**
* Insert content into the editor at the position of the cursor.
*/
insertAtCursor(text: string, escape: boolean): void;
/**
* Insert content into the editor at the given position.
*/
insertAt(pos: number, text: string, escape: boolean): void;
/**
* Insert content into the editor between the given positions.
*
* If the start and end positions are different, any text between them will be
* overwritten.
*/
insertBetween(start: number, end: number, text: string, escape: boolean): void;
/**
* Replace existing content from the start to the current cursor position.
*/
replaceBeforeCursor(start: number, text: string, escape: boolean): void;
/**
* Get left and top coordinates of the caret relative to the editor viewport.
*/
getCaretCoordinates(position: number): { left: number; top: number };
/**
* Set the disabled status of the editor.
*/
disabled(disabled: boolean): void;
/**
* Focus on the editor.
*/
focus(): void;
/**
* Destroy the editor
*/
destroy(): void;
}