@adecore/editor 0.0.1 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +110 -0
- package/README.md +57 -0
- package/dist/attribution.d.ts +28 -0
- package/dist/attribution.js +55 -0
- package/dist/code-block.d.ts +2 -0
- package/dist/code-block.js +89 -0
- package/dist/column-selection.d.ts +9 -0
- package/dist/column-selection.js +52 -0
- package/dist/controller.d.ts +64 -0
- package/dist/controller.js +772 -0
- package/dist/editor.css +813 -0
- package/dist/engine.d.ts +2 -0
- package/dist/engine.js +610 -0
- package/dist/fake.d.ts +192 -0
- package/dist/fake.js +663 -0
- package/dist/find.d.ts +30 -0
- package/dist/find.js +108 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/input.d.ts +9 -0
- package/dist/input.js +57 -0
- package/dist/keymap-table.d.ts +102 -0
- package/dist/keymap-table.js +130 -0
- package/dist/keymap.d.ts +36 -0
- package/dist/keymap.js +163 -0
- package/dist/layout.d.ts +167 -0
- package/dist/layout.js +583 -0
- package/dist/lens.d.ts +3 -0
- package/dist/lens.js +29 -0
- package/dist/listeners.d.ts +3 -0
- package/dist/listeners.js +12 -0
- package/dist/metrics.d.ts +8 -0
- package/dist/metrics.js +54 -0
- package/dist/modifier-gesture.d.ts +24 -0
- package/dist/modifier-gesture.js +98 -0
- package/dist/native-input.d.ts +26 -0
- package/dist/native-input.js +147 -0
- package/dist/offsets.d.ts +2 -0
- package/dist/offsets.js +14 -0
- package/dist/outline.d.ts +55 -0
- package/dist/outline.js +181 -0
- package/dist/overview.d.ts +17 -0
- package/dist/overview.js +55 -0
- package/dist/paint.d.ts +86 -0
- package/dist/paint.js +481 -0
- package/dist/php-html.d.ts +9 -0
- package/dist/php-html.js +36 -0
- package/dist/pointer.d.ts +49 -0
- package/dist/pointer.js +243 -0
- package/dist/scroll-animation.d.ts +3 -0
- package/dist/scroll-animation.js +45 -0
- package/dist/scroll.d.ts +28 -0
- package/dist/scroll.js +76 -0
- package/dist/semantic.d.ts +8 -0
- package/dist/semantic.js +47 -0
- package/dist/shiki.d.ts +7 -0
- package/dist/shiki.js +106 -0
- package/dist/smart-keys.d.ts +3 -0
- package/dist/smart-keys.js +14 -0
- package/dist/testing.d.ts +34 -0
- package/dist/testing.js +117 -0
- package/dist/theme-scopes.d.ts +9 -0
- package/dist/theme-scopes.js +61 -0
- package/dist/tokens.d.ts +28 -0
- package/dist/tokens.js +152 -0
- package/dist/tracked-range.d.ts +5 -0
- package/dist/tracked-range.js +20 -0
- package/dist/types.d.ts +344 -0
- package/dist/types.js +1 -0
- package/dist/view.d.ts +383 -0
- package/dist/view.js +2134 -0
- package/package.json +63 -3
- package/src/attribution.ts +85 -0
- package/src/code-block.ts +100 -0
- package/src/column-selection.ts +63 -0
- package/src/controller.ts +838 -0
- package/src/editor.css +813 -0
- package/src/engine.ts +764 -0
- package/src/fake.ts +838 -0
- package/src/find.ts +128 -0
- package/src/index.ts +69 -0
- package/src/input.ts +63 -0
- package/src/keymap-table.ts +163 -0
- package/src/keymap.ts +204 -0
- package/src/layout.ts +754 -0
- package/src/lens.ts +32 -0
- package/src/listeners.ts +15 -0
- package/src/metrics.ts +65 -0
- package/src/modifier-gesture.ts +115 -0
- package/src/native-input.ts +179 -0
- package/src/offsets.ts +16 -0
- package/src/outline.ts +248 -0
- package/src/overview.ts +80 -0
- package/src/paint.ts +608 -0
- package/src/php-html.ts +43 -0
- package/src/pointer.ts +326 -0
- package/src/scroll-animation.ts +48 -0
- package/src/scroll.ts +102 -0
- package/src/semantic.ts +54 -0
- package/src/shiki.ts +118 -0
- package/src/smart-keys.ts +17 -0
- package/src/testing.ts +157 -0
- package/src/theme-scopes.ts +75 -0
- package/src/tokens.ts +175 -0
- package/src/tracked-range.ts +22 -0
- package/src/types.ts +659 -0
- package/src/view.ts +2437 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import type { Keymap } from './keymap-table.ts';
|
|
2
|
+
import type { EditorCommand, FoldRole } from '@adecore/editor-core';
|
|
3
|
+
|
|
4
|
+
export type { EditorCommand, FoldRole };
|
|
5
|
+
|
|
6
|
+
export type EditorFoldOutline = 'off' | 'hover' | 'always';
|
|
7
|
+
|
|
8
|
+
/* The commands that fold, which the view answers since it knows where the ranges are. */
|
|
9
|
+
export type EditorViewCommand =
|
|
10
|
+
| 'collapseRegion'
|
|
11
|
+
| 'expandRegion'
|
|
12
|
+
| 'collapseAllRegions'
|
|
13
|
+
| 'expandAllRegions'
|
|
14
|
+
| 'collapseRegionRecursively'
|
|
15
|
+
| 'expandRegionRecursively'
|
|
16
|
+
| 'foldSelection'
|
|
17
|
+
| 'collapseDocComments'
|
|
18
|
+
| 'expandDocComments'
|
|
19
|
+
| 'expandAllToLevel1'
|
|
20
|
+
| 'expandAllToLevel2'
|
|
21
|
+
| 'expandAllToLevel3'
|
|
22
|
+
| 'expandAllToLevel4'
|
|
23
|
+
| 'expandAllToLevel5'
|
|
24
|
+
| 'toggleColumnMode';
|
|
25
|
+
|
|
26
|
+
/* Everything `runCommand` runs. */
|
|
27
|
+
export type EditorRunCommand = EditorCommand | EditorViewCommand;
|
|
28
|
+
|
|
29
|
+
/* Lines to fold, zero-based. */
|
|
30
|
+
export interface EditorFoldRange {
|
|
31
|
+
readonly startLine: number;
|
|
32
|
+
readonly endLine: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* What a host keeps of an editor's folds to open the file again as it was left. */
|
|
36
|
+
export interface EditorFolds {
|
|
37
|
+
/* The ranges that are folded, the ones made of a selection included. */
|
|
38
|
+
readonly collapsed: readonly EditorFoldRange[];
|
|
39
|
+
/* The ranges made of a selection, folded or not. */
|
|
40
|
+
readonly custom: readonly EditorFoldRange[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* A Shiki theme id, the one the viewer draws the same file in. */
|
|
44
|
+
export type EditorTheme = string;
|
|
45
|
+
|
|
46
|
+
export interface EditorOptions {
|
|
47
|
+
readonly text: string;
|
|
48
|
+
/* The Shiki id `fs.read` answers with. Without one, or with one Shiki does not know, it is plain text. */
|
|
49
|
+
readonly language?: string;
|
|
50
|
+
/* The file's path, absolute or only a name. A language service reads the dialect off its extension, a `.tsx` from a `.ts`. */
|
|
51
|
+
readonly path?: string;
|
|
52
|
+
readonly theme: EditorTheme;
|
|
53
|
+
readonly readOnly?: boolean;
|
|
54
|
+
/* What a person is told on typing into a read-only editor. */
|
|
55
|
+
readonly readOnlyReason?: string;
|
|
56
|
+
readonly wrap?: boolean;
|
|
57
|
+
/* The width of a tab stop, and whether Tab inserts spaces; 4 and spaces without them. */
|
|
58
|
+
readonly indentation?: EditorIndentation;
|
|
59
|
+
/* What it does as a person types; whatever is left out is on, except the camel humps. */
|
|
60
|
+
readonly smartKeys?: Partial<EditorSmartKeys>;
|
|
61
|
+
/* A line at each indentation level, the one of the scope around the caret stronger; on unless false. */
|
|
62
|
+
readonly guides?: boolean;
|
|
63
|
+
/* Spaces drawn as dots and tabs as arrows; off unless true. */
|
|
64
|
+
readonly whitespace?: boolean;
|
|
65
|
+
/* The column to draw a line at, such as the `max_line_length` of a project; none by default. */
|
|
66
|
+
readonly rightMargin?: number | null;
|
|
67
|
+
/* When the arrow that folds a block shows in the gutter; on hover by default. */
|
|
68
|
+
readonly foldOutline?: EditorFoldOutline;
|
|
69
|
+
/* What the editor says to a person itself, in the host's words. */
|
|
70
|
+
readonly messages?: Partial<EditorMessages>;
|
|
71
|
+
/* The accessible name of the editor, such as "Commit message", in the host's language; `Code editor` without one. */
|
|
72
|
+
readonly label?: string;
|
|
73
|
+
/* The folds a host kept when the file was last open. */
|
|
74
|
+
readonly folds?: EditorFolds;
|
|
75
|
+
/* Without remembered folds, the folds of these roles fold, as they do the first time a file opens, and again as a language server names more of them. */
|
|
76
|
+
readonly foldDefaults?: readonly FoldRole[];
|
|
77
|
+
/* One-based, the line the cursor opens on. */
|
|
78
|
+
readonly line?: number;
|
|
79
|
+
/* One-based, where on that line. */
|
|
80
|
+
readonly column?: number;
|
|
81
|
+
/* In pixels, where the view opens; without it the cursor's line is brought into view. */
|
|
82
|
+
readonly scrollTop?: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* The few sentences the editor says on its own. */
|
|
86
|
+
export interface EditorMessages {
|
|
87
|
+
/* Select next occurrence went past the last one. */
|
|
88
|
+
readonly noMoreOccurrences: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* What the editor does by itself as a person types. Every one is on, except the camel humps. */
|
|
92
|
+
export interface EditorSmartKeys {
|
|
93
|
+
/* A typed bracket brings its closer, and typing the closer goes over it. */
|
|
94
|
+
readonly autoPairBrackets: boolean;
|
|
95
|
+
readonly autoPairQuotes: boolean;
|
|
96
|
+
/* A bracket or quote typed over a selection wraps it. */
|
|
97
|
+
readonly surroundSelection: boolean;
|
|
98
|
+
/* Tab steps over a closer the editor added. */
|
|
99
|
+
readonly tabOutOfClosers: boolean;
|
|
100
|
+
/* Enter works out the indentation of the new line, continues comments and closes braces. */
|
|
101
|
+
readonly smartIndentOnEnter: boolean;
|
|
102
|
+
/* A pasted block moves to the indentation of the line it lands on. */
|
|
103
|
+
readonly indentOnPaste: boolean;
|
|
104
|
+
/* A `;` typed inside a call goes to the end of the statement. */
|
|
105
|
+
readonly smartSemicolon: boolean;
|
|
106
|
+
/* Moving by word also stops inside `camelCase` and `snake_case` words. Off. */
|
|
107
|
+
readonly camelHumps: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* The range of a symbol and the kind of body it has. */
|
|
111
|
+
export interface EditorFoldSymbol {
|
|
112
|
+
readonly range: EditorRange;
|
|
113
|
+
/* `value` is a variable or property, which has a function body when its initializer is a function. */
|
|
114
|
+
readonly body: 'function' | 'method' | 'class' | 'value';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface EditorFoldHints {
|
|
118
|
+
readonly symbols?: readonly EditorFoldSymbol[];
|
|
119
|
+
readonly ranges?: readonly (EditorFoldRange & { readonly kind?: string })[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* A part of the document with a header line, such as a function, a class or a method. */
|
|
123
|
+
export interface EditorBlock {
|
|
124
|
+
/* One-based, the line its header is on. */
|
|
125
|
+
readonly startLine: number;
|
|
126
|
+
/* One-based, the last line, inclusive. */
|
|
127
|
+
readonly endLine: number;
|
|
128
|
+
/* What a breadcrumb calls it; without one the header's own text stands in. */
|
|
129
|
+
readonly name?: string;
|
|
130
|
+
/* A hint for the icon beside the name, such as `function`, `class` or `method`. */
|
|
131
|
+
readonly kind?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type EditorChangeKind = 'added' | 'modified' | 'deleted';
|
|
135
|
+
|
|
136
|
+
/* A stretch of lines that differs from the version the host compares against, drawn in the gutter and in the scroll track. */
|
|
137
|
+
export interface EditorChangeMark {
|
|
138
|
+
readonly kind: EditorChangeKind;
|
|
139
|
+
/* One-based. For `deleted` the line the removed lines were above, which is where the mark sits. */
|
|
140
|
+
readonly startLine: number;
|
|
141
|
+
/* One-based and inclusive; the same as `startLine` for `deleted`. */
|
|
142
|
+
readonly endLine: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* A color for what an agent did: the name of a custom property of the page (`--agent-1`, see
|
|
147
|
+
* `AGENT_COLORS`), which follows the theme, or any CSS color.
|
|
148
|
+
*/
|
|
149
|
+
export type EditorMarkColor = string;
|
|
150
|
+
|
|
151
|
+
/*
|
|
152
|
+
* A run of lines drawn as a bar in the gutter, three pixels wide beside the line numbers where the change
|
|
153
|
+
* marks are. Where a line has both, the bar stands in the place of the change mark, which the scroll
|
|
154
|
+
* track still shows. It follows its text through edits until the host sets the marks again.
|
|
155
|
+
*/
|
|
156
|
+
export interface EditorAttributionMark {
|
|
157
|
+
/* What `onAttributionHover` says when the pointer is on the bar. */
|
|
158
|
+
readonly id: string;
|
|
159
|
+
/* One-based, as for the change marks. */
|
|
160
|
+
readonly startLine: number;
|
|
161
|
+
/* One-based and inclusive; a line past the end is the last one. */
|
|
162
|
+
readonly endLine: number;
|
|
163
|
+
readonly color: EditorMarkColor;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* An agent's caret with its name, drawn above the text where it is writing; the editor's own caret and selection never move for it. */
|
|
167
|
+
export interface EditorRemoteCursor {
|
|
168
|
+
readonly id: string;
|
|
169
|
+
/* A line past the end is the last one, a character past the end of its line is the end of it. */
|
|
170
|
+
readonly position: EditorPosition;
|
|
171
|
+
/* What the label says, such as the agent's name. */
|
|
172
|
+
readonly name: string;
|
|
173
|
+
readonly color: EditorMarkColor;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* Lines tinted behind the text, such as the lines an agent changed in a review. */
|
|
177
|
+
export interface EditorLineHighlight {
|
|
178
|
+
/* One-based and inclusive, as for the change marks. */
|
|
179
|
+
readonly startLine: number;
|
|
180
|
+
readonly endLine: number;
|
|
181
|
+
/* The tint is this color at a low alpha, so the code keeps its colors on it in either theme. */
|
|
182
|
+
readonly color: EditorMarkColor;
|
|
183
|
+
/* A color the rows and their gutter are filled with as it stands, instead of the low alpha tint of `color`, which keeps naming the sign's color. A custom property name or any CSS color. */
|
|
184
|
+
readonly fill?: EditorMarkColor;
|
|
185
|
+
/* A character in the gutter of each line, such as `+`, in the same color. */
|
|
186
|
+
readonly sign?: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* How `renderCode` draws lines that are not part of the document. */
|
|
190
|
+
export interface EditorCodeBlockOptions {
|
|
191
|
+
/* One-based number of the first line, shown in the gutter column; without it the lines have none. */
|
|
192
|
+
readonly firstLine?: number;
|
|
193
|
+
/* A character in the gutter of each line, such as `-`. */
|
|
194
|
+
readonly sign?: string;
|
|
195
|
+
/* Tints the rows and draws the bar beside them, as a highlight and an attribution mark do for lines of the document. */
|
|
196
|
+
readonly color?: EditorMarkColor;
|
|
197
|
+
/* Per line, the character ranges (UTF-16, end exclusive) drawn with a stronger tint of `color`, such as the words a change replaced. */
|
|
198
|
+
readonly emphasis?: ReadonlyArray<ReadonlyArray<readonly [number, number]>>;
|
|
199
|
+
/* Draws the text a little faded, as lines that are gone. */
|
|
200
|
+
readonly faded?: boolean;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* The pointer is on the bar of a run. */
|
|
204
|
+
export interface EditorAttributionHover {
|
|
205
|
+
readonly id: string;
|
|
206
|
+
/* The bar on the line under the pointer, in the page's pixels, so a card placed by it is right at any canvas zoom. */
|
|
207
|
+
readonly rect: EditorRect;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* A place in the text as a language server names it: a zero-based line and a UTF-16 character. */
|
|
211
|
+
export interface EditorPosition {
|
|
212
|
+
readonly line: number;
|
|
213
|
+
readonly character: number;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface EditorRange {
|
|
217
|
+
readonly start: EditorPosition;
|
|
218
|
+
readonly end: EditorPosition;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* The range replaced, in the text as it stands after the changes listed before this one, and what takes its place. */
|
|
222
|
+
export interface EditorContentChange {
|
|
223
|
+
readonly range: EditorRange;
|
|
224
|
+
readonly text: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface EditorTextChange {
|
|
228
|
+
/* In order, so a language server can follow them one by one. */
|
|
229
|
+
readonly changes: readonly EditorContentChange[];
|
|
230
|
+
/* A person typing, one of the editor's own commands such as undo, or a change from outside. */
|
|
231
|
+
readonly source: 'input' | 'command' | 'external';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export type EditorMarkerSeverity = 'error' | 'warning' | 'info' | 'hint';
|
|
235
|
+
|
|
236
|
+
/* A range the host wants drawn as a problem: a squiggle in the text, a tick in the scroll track. It follows its text through edits until the host sets the markers again. */
|
|
237
|
+
export interface EditorMarker {
|
|
238
|
+
readonly range: EditorRange;
|
|
239
|
+
readonly severity: EditorMarkerSeverity;
|
|
240
|
+
/* Drawn faded, for code nothing uses. */
|
|
241
|
+
readonly unnecessary?: boolean;
|
|
242
|
+
/* Drawn struck through. */
|
|
243
|
+
readonly deprecated?: boolean;
|
|
244
|
+
/* What the tick of this problem in the scroll track says when the pointer rests on it, and a press on the tick goes to the problem. */
|
|
245
|
+
readonly message?: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* The kind of use a highlighted name has at the caret. */
|
|
249
|
+
export type EditorHighlightKind = 'text' | 'read' | 'write';
|
|
250
|
+
|
|
251
|
+
export interface EditorHighlight {
|
|
252
|
+
readonly range: EditorRange;
|
|
253
|
+
readonly kind: EditorHighlightKind;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* A box on the screen, in the page's pixels, so a popup placed by it is right on a canvas at any zoom. */
|
|
257
|
+
export interface EditorRect {
|
|
258
|
+
readonly left: number;
|
|
259
|
+
readonly top: number;
|
|
260
|
+
readonly right: number;
|
|
261
|
+
readonly bottom: number;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* The pointer rests on a character of the text. */
|
|
265
|
+
export interface EditorHover {
|
|
266
|
+
readonly position: EditorPosition;
|
|
267
|
+
readonly rect: EditorRect;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* A press of the primary button on a character of the text. */
|
|
271
|
+
export interface EditorClick {
|
|
272
|
+
readonly position: EditorPosition;
|
|
273
|
+
/* Cmd on macOS, Ctrl elsewhere. */
|
|
274
|
+
readonly mod: boolean;
|
|
275
|
+
readonly alt: boolean;
|
|
276
|
+
readonly shift: boolean;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Returns true when the click was taken; the editor then leaves the caret and the selection where they are. */
|
|
280
|
+
export type EditorClickHandler = (click: EditorClick) => boolean;
|
|
281
|
+
|
|
282
|
+
/* A request for the context menu, by the secondary button or its key, which the editor does not answer itself. */
|
|
283
|
+
export interface EditorContextMenu {
|
|
284
|
+
/* The character under the pointer, or the end of the line it is past. */
|
|
285
|
+
readonly position: EditorPosition;
|
|
286
|
+
/* Whether it lies in the selection, so the host knows whether to leave the selection alone. */
|
|
287
|
+
readonly inSelection: boolean;
|
|
288
|
+
/* In the page's pixels. */
|
|
289
|
+
readonly x: number;
|
|
290
|
+
readonly y: number;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* A row of the host's own DOM under a line of the text, such as the references of a name. It is not part of the document. */
|
|
294
|
+
export interface EditorWidget {
|
|
295
|
+
readonly id: string;
|
|
296
|
+
/* Zero-based; the widget sits next to this line and stays there only as long as its owner does not set its widgets again. */
|
|
297
|
+
readonly line: number;
|
|
298
|
+
/* Under the line by default; `above` puts the row over it, which a row at the top of the file needs. */
|
|
299
|
+
readonly placement?: 'above' | 'below';
|
|
300
|
+
/* The height the row has until it has been measured. */
|
|
301
|
+
readonly height?: number;
|
|
302
|
+
/* Fills the element the row is drawn in, which the editor makes again whenever the row scrolls back into view. */
|
|
303
|
+
render(container: HTMLElement): void;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/*
|
|
307
|
+
* The host's own DOM after the last character of a line of the text, such as the buttons of a change
|
|
308
|
+
* under review. It is not part of the document and not part of the row, so it takes no height and
|
|
309
|
+
* moves nothing.
|
|
310
|
+
*/
|
|
311
|
+
export interface EditorLineAction {
|
|
312
|
+
readonly id: string;
|
|
313
|
+
/* Zero-based; the action stays on its line through edits until its owner sets its actions again. */
|
|
314
|
+
readonly line: number;
|
|
315
|
+
/* Fills the element once; it is kept for as long as the action is. */
|
|
316
|
+
render(container: HTMLElement): void;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/* One thing a code vision row says, such as how many times a declaration is used. */
|
|
320
|
+
export interface EditorCodeVisionEntry {
|
|
321
|
+
readonly id: string;
|
|
322
|
+
readonly text: string;
|
|
323
|
+
/* A person for one author, several for more. */
|
|
324
|
+
readonly icon?: 'user' | 'users';
|
|
325
|
+
/* The entry was pressed; `anchor` is where it stands, in the page's pixels, for what opens beside it. */
|
|
326
|
+
activate(anchor: EditorRect): void;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/*
|
|
330
|
+
* A quiet row above a declaration, in the declaration's indentation and one code line high. A row with
|
|
331
|
+
* no entries yet still holds its height, so the text does not move when they arrive.
|
|
332
|
+
*/
|
|
333
|
+
export interface EditorCodeVision {
|
|
334
|
+
readonly id: string;
|
|
335
|
+
/* Zero-based line of the declaration; the row sits above it and follows it through edits until the host sets the rows again. */
|
|
336
|
+
readonly line: number;
|
|
337
|
+
readonly entries: readonly EditorCodeVisionEntry[];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/* Returns true when the key was taken; the editor then prevents its default and does nothing else with it. */
|
|
341
|
+
export type EditorKeyHandler = (event: KeyboardEvent) => boolean;
|
|
342
|
+
|
|
343
|
+
/*
|
|
344
|
+
* The ranges a language server knows around each position asked, the smallest first and each larger than
|
|
345
|
+
* the one before; null when it has none to give, which sends Extend Selection to the editor's own rule.
|
|
346
|
+
*/
|
|
347
|
+
export type EditorSelectionRanges = (positions: readonly EditorPosition[]) => Promise<readonly (readonly EditorRange[])[] | null>;
|
|
348
|
+
|
|
349
|
+
/* A range of text the language servers classified, by the TextMate scopes the editor's theme colors it by. */
|
|
350
|
+
export interface EditorSemanticToken {
|
|
351
|
+
readonly line: number;
|
|
352
|
+
readonly character: number;
|
|
353
|
+
readonly length: number;
|
|
354
|
+
/* Outermost first, as a grammar would have reported them. */
|
|
355
|
+
readonly scopes: readonly string[];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/* How a theme draws a piece of code. The font style is Shiki's flags: 1 italic, 2 bold, 4 underline, 8 strikethrough. */
|
|
359
|
+
export interface ScopeStyle {
|
|
360
|
+
readonly color: string;
|
|
361
|
+
readonly fontStyle: number;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/* What the current theme draws a scope stack in, or undefined where it says nothing and the grammar's color stays. */
|
|
365
|
+
export type ScopeColors = (scopes: readonly string[]) => ScopeStyle | undefined;
|
|
366
|
+
|
|
367
|
+
/* The scope colors of a theme, or null when there is none. May load the theme, so it is async. */
|
|
368
|
+
export type ScopeColorSource = (theme: EditorTheme) => Promise<ScopeColors | null>;
|
|
369
|
+
|
|
370
|
+
/* Text drawn between two characters of a line, such as the type of a variable or the name of a parameter. It is not part of the document. */
|
|
371
|
+
export interface EditorInlayHint {
|
|
372
|
+
readonly position: EditorPosition;
|
|
373
|
+
readonly label: string;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/*
|
|
377
|
+
* A suggestion drawn after the caret in the editor's ghost color, which is not part of the document. It
|
|
378
|
+
* may span lines. Any edit of the text takes it away, so the host sets it again for the text it was made for.
|
|
379
|
+
*/
|
|
380
|
+
export interface EditorGhostText {
|
|
381
|
+
/* Where the suggestion would be inserted; the caret stays in front of it. */
|
|
382
|
+
readonly position: EditorPosition;
|
|
383
|
+
readonly text: string;
|
|
384
|
+
/* Fills the element drawn after the end of the first line's text, such as the keys that take the suggestion. */
|
|
385
|
+
readonly accessory?: (container: HTMLElement) => void;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* A button in the gutter on one line, such as the lightbulb that offers code actions. */
|
|
389
|
+
export interface EditorGutterAction {
|
|
390
|
+
/* Zero-based. */
|
|
391
|
+
readonly line: number;
|
|
392
|
+
readonly label: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/* A small button in the gutter on one line that the host keeps apart from the code action, such as the mark of a saved inline edit. */
|
|
396
|
+
export interface EditorGutterMarker {
|
|
397
|
+
/* What `onGutterMarker` says when it is pressed. */
|
|
398
|
+
readonly id: string;
|
|
399
|
+
/* Zero-based; it stays on this line until the host sets its markers again. */
|
|
400
|
+
readonly line: number;
|
|
401
|
+
readonly label: string;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/*
|
|
405
|
+
* How the view follows a caret that was moved from outside. `relative` keeps it in view with a line
|
|
406
|
+
* of margin, `center` puts a target out of view a third from the top and leaves one in view alone, and
|
|
407
|
+
* `centerDown` and `centerUp` do the same for a step through results that goes one way, so each next one
|
|
408
|
+
* lands where the eye expects it.
|
|
409
|
+
*/
|
|
410
|
+
export type EditorReveal = 'relative' | 'center' | 'centerDown' | 'centerUp';
|
|
411
|
+
|
|
412
|
+
export interface EditorIndentation {
|
|
413
|
+
readonly tabSize: number;
|
|
414
|
+
readonly insertSpaces: boolean;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/* What a find bar asks the editor; the editor's own matcher reads it. */
|
|
418
|
+
export interface EditorFindQuery {
|
|
419
|
+
readonly text: string;
|
|
420
|
+
readonly caseSensitive: boolean;
|
|
421
|
+
readonly wholeWord: boolean;
|
|
422
|
+
readonly regex: boolean;
|
|
423
|
+
/* Only the text that was selected when this turned on is searched, however the selection moves after. */
|
|
424
|
+
readonly inSelection?: boolean;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export interface EditorFindState {
|
|
428
|
+
readonly count: number;
|
|
429
|
+
/* Zero-based; null without a match. */
|
|
430
|
+
readonly current: number | null;
|
|
431
|
+
/* The search is in the selection and nothing was selected. */
|
|
432
|
+
readonly noSelection?: boolean;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface EditorReplaceOptions {
|
|
436
|
+
/* The replacement takes the case of the text it replaces: `Foo` becomes `Bar`, `FOO` becomes `BAR`. */
|
|
437
|
+
readonly preserveCase?: boolean;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/*
|
|
441
|
+
* A range that follows the text through edits. `get` is the range where it is now, or null once an edit
|
|
442
|
+
* touched it: one that replaces text inside it or lands strictly between its ends. Text inserted exactly
|
|
443
|
+
* at an end leaves the text of the range as it was, so the range survives it, moving behind text inserted
|
|
444
|
+
* at its start and staying put for text inserted at its end. A disposed range is null.
|
|
445
|
+
*/
|
|
446
|
+
export interface EditorTrackedRange {
|
|
447
|
+
get(): EditorRange | null;
|
|
448
|
+
dispose(): void;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface Editor {
|
|
452
|
+
getText(): string;
|
|
453
|
+
/* A change from outside, such as a reload after `fs.changed` or another surface's edit. It is never
|
|
454
|
+
reported as a change, and the cursor and the scroll stay put wherever the text around them did. */
|
|
455
|
+
setText(text: string): void;
|
|
456
|
+
onChange(listener: () => void): () => void;
|
|
457
|
+
/* Every change of the text, `setText` and undo included, with what changed in the positions a language server expects. */
|
|
458
|
+
onTextChange(listener: (change: EditorTextChange) => void): () => void;
|
|
459
|
+
/* An offset past the end, or a character past the end of its line, lands on the end. */
|
|
460
|
+
positionAt(offset: number): EditorPosition;
|
|
461
|
+
offsetAt(position: EditorPosition): number;
|
|
462
|
+
/* The text of a range, such as the word before the caret. */
|
|
463
|
+
textInRange(range: EditorRange): string;
|
|
464
|
+
/* Mod+S from inside the editor; what happens then is the client's. */
|
|
465
|
+
onSave(listener: () => void): () => void;
|
|
466
|
+
/* The focus left the editor and every widget of its own, such as its suggestions. */
|
|
467
|
+
onBlur(listener: () => void): () => void;
|
|
468
|
+
/* Puts the cursor at the start of a one-based line and scrolls it into view, a third from the top when it was out of view. */
|
|
469
|
+
revealLine(line: number, reveal?: EditorReveal): void;
|
|
470
|
+
/* Marks every match and moves to the first one from the cursor on; null takes the marks away. The
|
|
471
|
+
count comes back through `onFind`, and again whenever an edit changes it. */
|
|
472
|
+
find(query: EditorFindQuery | null): void;
|
|
473
|
+
findStep(direction: 1 | -1): void;
|
|
474
|
+
/* Replaces the match the find is on, with `$1` and the like expanded for a regular expression, and moves to the next one. False when there is none or the editor is read only. */
|
|
475
|
+
replace(replacement: string, options?: EditorReplaceOptions): boolean;
|
|
476
|
+
/* Replaces every match in one undo step, and says how many there were. */
|
|
477
|
+
replaceAll(replacement: string, options?: EditorReplaceOptions): number;
|
|
478
|
+
/* What a regular expression replacement writes for the match the find is on, drawn under it while the find is open; null takes it away. */
|
|
479
|
+
setReplacePreview(replacement: string | null, options?: EditorReplaceOptions): void;
|
|
480
|
+
/* Ends the find with a caret on every match, the one the find was on last, and says how many there were. */
|
|
481
|
+
selectFindMatches(): number;
|
|
482
|
+
/* Selects the next match of a query from the cursor, or the one before, going round at the ends, without a find bar. False when there is none. */
|
|
483
|
+
findFromCursor(query: EditorFindQuery, direction: 1 | -1): boolean;
|
|
484
|
+
onFind(listener: (state: EditorFindState) => void): () => void;
|
|
485
|
+
/* Takes the marks away and selects the match the find was on, so the cursor is where it stopped. */
|
|
486
|
+
endFind(): void;
|
|
487
|
+
setWrap(wrap: boolean): void;
|
|
488
|
+
setIndentation(indentation: EditorIndentation): void;
|
|
489
|
+
/* Changes what it does as a person types; the keys left out stay as they are. */
|
|
490
|
+
setSmartKeys(keys: Partial<EditorSmartKeys>): void;
|
|
491
|
+
setGuides(guides: boolean): void;
|
|
492
|
+
setWhitespace(whitespace: boolean): void;
|
|
493
|
+
/* The column to draw a line at; null takes it away. */
|
|
494
|
+
setRightMargin(column: number | null): void;
|
|
495
|
+
setFoldOutline(outline: EditorFoldOutline): void;
|
|
496
|
+
setLabel(label: string): void;
|
|
497
|
+
/* What a language server knows about the folds: the bodies of symbols and the ranges it folds. They follow their text through edits until set again; null forgets them. */
|
|
498
|
+
setFoldHints(hints: EditorFoldHints | null): void;
|
|
499
|
+
/* Marks that follow their lines through edits until the host sets them again. */
|
|
500
|
+
setChangeMarks(marks: readonly EditorChangeMark[]): void;
|
|
501
|
+
/* The blocks sticky scroll and the breadcrumb go by. The editor reads them from brackets and
|
|
502
|
+
indentation until the host has better, such as a language server's symbols; null goes back. */
|
|
503
|
+
setBlocks(blocks: readonly EditorBlock[] | null): void;
|
|
504
|
+
/* The named blocks around the caret, outermost first, said again only when they change. */
|
|
505
|
+
onScope(listener: (scope: readonly EditorBlock[]) => void): () => void;
|
|
506
|
+
/* Bars in the gutter for the lines an agent wrote, replacing the ones set before. */
|
|
507
|
+
setAttributionMarks(marks: readonly EditorAttributionMark[]): void;
|
|
508
|
+
/*
|
|
509
|
+
* Carets of agents with their names, replacing the ones set before. Each follows its text through
|
|
510
|
+
* edits until the host sets them again, takes no pointer and sits over the text, with the name above
|
|
511
|
+
* the caret or under it where the view has no room above.
|
|
512
|
+
*/
|
|
513
|
+
setRemoteCursors(cursors: readonly EditorRemoteCursor[]): void;
|
|
514
|
+
/* Lines tinted behind the text, replacing the ones set before. They follow their text through edits until set again, and cost one mapping of two offsets per highlight. */
|
|
515
|
+
setLineHighlights(highlights: readonly EditorLineHighlight[]): void;
|
|
516
|
+
/*
|
|
517
|
+
* Fills a widget row's element with lines of code that are not in the document, such as the lines an
|
|
518
|
+
* agent removed, in the editor's face and colors for the language, a gutter column as wide as the
|
|
519
|
+
* editor's and a row as high as a line. Call it from `EditorWidget.render`.
|
|
520
|
+
*/
|
|
521
|
+
renderCode(container: HTMLElement, text: string, options?: EditorCodeBlockOptions): void;
|
|
522
|
+
/* The pointer rests on a bar, or null when it left it or the bar is gone. */
|
|
523
|
+
onAttributionHover(listener: (hover: EditorAttributionHover | null) => void): () => void;
|
|
524
|
+
/* Problems to draw, replacing the ones set before. */
|
|
525
|
+
setMarkers(markers: readonly EditorMarker[]): void;
|
|
526
|
+
/* The other uses of the name at the caret, drawn as soft marks until the next edit. */
|
|
527
|
+
setHighlights(highlights: readonly EditorHighlight[]): void;
|
|
528
|
+
/* A range drawn as a link, underlined with the pointer on it, until the host sets another or the text is edited; null takes it away. */
|
|
529
|
+
setLink(range: EditorRange | null): void;
|
|
530
|
+
/* Colors by what the language servers know, over what the grammar made of the text; null takes them away. */
|
|
531
|
+
setSemanticTokens(tokens: readonly EditorSemanticToken[] | null): void;
|
|
532
|
+
/* Hints to draw as soft pills in the text, replacing the ones set before. They follow their text through edits until set again. */
|
|
533
|
+
setInlayHints(hints: readonly EditorInlayHint[]): void;
|
|
534
|
+
/* A suggestion after the caret, replacing the one before; null takes it away. Any change of the text takes it away as well. */
|
|
535
|
+
setGhostText(ghost: EditorGhostText | null): void;
|
|
536
|
+
/* One button in the gutter, replacing the one before; null takes it away. It stays on its line until the host sets it again. */
|
|
537
|
+
setGutterAction(action: EditorGutterAction | null): void;
|
|
538
|
+
/* The button was pressed; the zero-based line it is on. */
|
|
539
|
+
onGutterAction(listener: (line: number) => void): () => void;
|
|
540
|
+
/* The markers of one owner (`default` without one), replacing the ones it set before and leaving every other owner's alone. An empty list takes them away. */
|
|
541
|
+
setGutterMarkers(markers: readonly EditorGutterMarker[], owner?: string): void;
|
|
542
|
+
/* A marker was pressed; its id. */
|
|
543
|
+
onGutterMarker(listener: (id: string) => void): () => void;
|
|
544
|
+
getCaret(): EditorPosition;
|
|
545
|
+
/* In pixels, what `scrollTop` on mounting takes back. */
|
|
546
|
+
getScrollTop(): number;
|
|
547
|
+
/* Which lines are folded, for `folds` on mounting. */
|
|
548
|
+
getFolds(): EditorFolds;
|
|
549
|
+
/* The primary selection, start before end; empty at the caret. */
|
|
550
|
+
getSelection(): EditorRange;
|
|
551
|
+
/* Every selection, the primary one last. */
|
|
552
|
+
getSelections(): EditorRange[];
|
|
553
|
+
getIndentation(): EditorIndentation;
|
|
554
|
+
/* Moves the one caret and scrolls it into view. */
|
|
555
|
+
setCaret(position: EditorPosition, reveal?: EditorReveal): void;
|
|
556
|
+
/* Replaces the selections with one over the range, the caret at its end, and scrolls it into view. */
|
|
557
|
+
setSelection(range: EditorRange, reveal?: EditorReveal): void;
|
|
558
|
+
/* Replaces the selections with these, in the order given: the last is the primary one, as for the newest caret, and is scrolled into view. An empty list changes nothing. */
|
|
559
|
+
setSelections(ranges: readonly EditorRange[], reveal?: EditorReveal): void;
|
|
560
|
+
/* The caret moved or the text under it changed. */
|
|
561
|
+
onCaret(listener: (position: EditorPosition) => void): () => void;
|
|
562
|
+
/* The pointer moved onto another character, or null when it left the text. */
|
|
563
|
+
onHover(listener: (hover: EditorHover | null) => void): () => void;
|
|
564
|
+
/* The character cell at a position in screen coordinates, or null where the editor has no layout. */
|
|
565
|
+
rectAt(position: EditorPosition): EditorRect | null;
|
|
566
|
+
/* The lines in view, from the start of the first to the end of the last. */
|
|
567
|
+
getVisibleRange(): EditorRange;
|
|
568
|
+
/* The editor scrolled or changed size, so whatever is placed by `rectAt` is somewhere else. */
|
|
569
|
+
onViewChange(listener: () => void): () => void;
|
|
570
|
+
/*
|
|
571
|
+
* Rows of the host's own DOM next to lines of the text, replacing the ones the same owner set before.
|
|
572
|
+
* Owners never take each other's rows away, so a peek, the review of an agent's change and a conflict
|
|
573
|
+
* can all be up at once. Without an owner the rows are `default`'s. Rows next to the same line stand
|
|
574
|
+
* in the order of their owners' names, and within an owner in the order it gave them, whichever owner
|
|
575
|
+
* set its rows last. An empty list takes the owner's rows away.
|
|
576
|
+
*/
|
|
577
|
+
setWidgets(widgets: readonly EditorWidget[], owner?: string): void;
|
|
578
|
+
/* The actions of one owner (`default` without one), replacing the ones it set before and leaving every other owner's alone. A line that a fold hides has none. */
|
|
579
|
+
setLineActions(actions: readonly EditorLineAction[], owner?: string): void;
|
|
580
|
+
/* The code vision rows above declarations, replacing the ones set before. Separate from the widgets, which they never displace. */
|
|
581
|
+
setCodeVision(rows: readonly EditorCodeVision[]): void;
|
|
582
|
+
/* Handlers see a press of the primary button before the editor does, the first to take it winning. */
|
|
583
|
+
onClick(handler: EditorClickHandler): () => void;
|
|
584
|
+
/* The context menu was asked for. The editor draws none of its own and does not move the caret. */
|
|
585
|
+
onContextMenu(listener: (menu: EditorContextMenu) => void): () => void;
|
|
586
|
+
/* Handlers see a key before the editor does, the first to take it winning. */
|
|
587
|
+
onKeyDown(handler: EditorKeyHandler): () => void;
|
|
588
|
+
/* Extend Selection grows through these ranges, where the host has them, and Shrink Selection walks back; null returns to the editor's own rule. */
|
|
589
|
+
setSelectionRanges(provider: EditorSelectionRanges | null): void;
|
|
590
|
+
/* Follows a range through every change of the text, `setText` and undo included, until it is disposed. Costs one mapping of two offsets per change. */
|
|
591
|
+
trackRange(range: EditorRange): EditorTrackedRange;
|
|
592
|
+
/* Replaces ranges of the current text at once, as one step of the undo history. */
|
|
593
|
+
applyEdits(edits: readonly EditorContentChange[]): boolean;
|
|
594
|
+
setTheme(theme: EditorTheme): void;
|
|
595
|
+
/* Reads the code face off the page again, after the page changed its size, family or ligatures. */
|
|
596
|
+
refreshFont(): void;
|
|
597
|
+
setReadOnly(readOnly: boolean, reason?: string): void;
|
|
598
|
+
/* Runs an editing command on every caret, as its key would. False when it changed nothing. */
|
|
599
|
+
runCommand(command: EditorRunCommand): boolean;
|
|
600
|
+
focus(): void;
|
|
601
|
+
dispose(): void;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export interface EditorEngine {
|
|
605
|
+
/* The element is sized by its parent; the editor follows it. Import the Adecore theme and editor CSS to color the chrome. */
|
|
606
|
+
mount(element: HTMLElement, options: EditorOptions): Editor;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/* A shortcut: `mod` is Cmd on macOS and Ctrl elsewhere, `ctrl` and `meta` the physical keys. */
|
|
610
|
+
export interface KeyChord {
|
|
611
|
+
readonly mod: boolean;
|
|
612
|
+
readonly ctrl: boolean;
|
|
613
|
+
readonly meta: boolean;
|
|
614
|
+
readonly alt: boolean;
|
|
615
|
+
readonly shift: boolean;
|
|
616
|
+
/* An uppercase letter, a digit, a punctuation mark or a named key such as `ArrowLeft`. */
|
|
617
|
+
readonly key: string;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/* One stretch of a colored line. The tokens of a line add up to its length. */
|
|
621
|
+
export interface LineToken {
|
|
622
|
+
readonly length: number;
|
|
623
|
+
/* Any CSS color; empty for the editor's own text color. */
|
|
624
|
+
readonly color: string;
|
|
625
|
+
/* Bit flags as Shiki writes them: 1 italic, 2 bold, 4 underline, 8 strikethrough. */
|
|
626
|
+
readonly fontStyle: number;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export interface TokenizedLine {
|
|
630
|
+
readonly tokens: readonly LineToken[];
|
|
631
|
+
/* What the next line starts from; only the tokenizer that made it reads it. */
|
|
632
|
+
readonly state: unknown;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/*
|
|
636
|
+
* The coloring seam. A grammar needs the state the line before it ended in, so an edit recolors from
|
|
637
|
+
* the changed line on, and stops as soon as a line ends in the state it ended in before.
|
|
638
|
+
*/
|
|
639
|
+
export interface LineTokenizer {
|
|
640
|
+
/* A null state starts the document. */
|
|
641
|
+
tokenizeLine(text: string, state: unknown): TokenizedLine;
|
|
642
|
+
sameState(a: unknown, b: unknown): boolean;
|
|
643
|
+
/* True once, when the grammar was rebuilt and the states handed out before it are void. */
|
|
644
|
+
stale?(): boolean;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/* A tokenizer for a language in a theme, or null when there is no grammar for it. May load the grammar, so it is async; `text` is the document, for the embedded languages it names. */
|
|
648
|
+
export type TokenizerSource = (language: string | undefined, theme: EditorTheme, text?: string) => Promise<LineTokenizer | null>;
|
|
649
|
+
|
|
650
|
+
export interface SmartEditorEngineOptions {
|
|
651
|
+
readonly keymap?: Keymap;
|
|
652
|
+
readonly tokenizer: TokenizerSource;
|
|
653
|
+
/* Without it semantic tokens are ignored and the grammar's colors stand. */
|
|
654
|
+
readonly scopeColors?: ScopeColorSource;
|
|
655
|
+
/* The app's shortcuts that work from anywhere, a text field included; the editor lets them pass untouched. */
|
|
656
|
+
readonly handBack?: readonly KeyChord[];
|
|
657
|
+
/* Whether the physical Ctrl and Meta of a shortcut are macOS's. */
|
|
658
|
+
readonly apple?: boolean;
|
|
659
|
+
}
|