@jupyterlab/codeeditor 0.19.1-alpha.0 → 0.19.1

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/lib/editor.d.ts CHANGED
@@ -1,532 +1,532 @@
1
- import { JSONObject } from '@phosphor/coreutils';
2
- import { IDisposable } from '@phosphor/disposable';
3
- import { ISignal } from '@phosphor/signaling';
4
- import { IChangedArgs } from '@jupyterlab/coreutils';
5
- import { IModelDB, IObservableMap, IObservableString } from '@jupyterlab/observables';
6
- /**
7
- * A namespace for code editors.
8
- *
9
- * #### Notes
10
- * - A code editor is a set of common assumptions which hold for all concrete editors.
11
- * - Changes in implementations of the code editor should only be caused by changes in concrete editors.
12
- * - Common JLab services which are based on the code editor should belong to `IEditorServices`.
13
- */
14
- export declare namespace CodeEditor {
15
- /**
16
- * A zero-based position in the editor.
17
- */
18
- interface IPosition extends JSONObject {
19
- /**
20
- * The cursor line number.
21
- */
22
- readonly line: number;
23
- /**
24
- * The cursor column number.
25
- */
26
- readonly column: number;
27
- }
28
- /**
29
- * The dimension of an element.
30
- */
31
- interface IDimension {
32
- /**
33
- * The width of an element in pixels.
34
- */
35
- readonly width: number;
36
- /**
37
- * The height of an element in pixels.
38
- */
39
- readonly height: number;
40
- }
41
- /**
42
- * An interface describing editor state coordinates.
43
- */
44
- interface ICoordinate extends JSONObject, ClientRect {
45
- }
46
- /**
47
- * A range.
48
- */
49
- interface IRange extends JSONObject {
50
- /**
51
- * The position of the first character in the current range.
52
- *
53
- * #### Notes
54
- * If this position is greater than [end] then the range is considered
55
- * to be backward.
56
- */
57
- readonly start: IPosition;
58
- /**
59
- * The position of the last character in the current range.
60
- *
61
- * #### Notes
62
- * If this position is less than [start] then the range is considered
63
- * to be backward.
64
- */
65
- readonly end: IPosition;
66
- }
67
- /**
68
- * A selection style.
69
- */
70
- interface ISelectionStyle extends JSONObject {
71
- /**
72
- * A class name added to a selection.
73
- */
74
- className: string;
75
- /**
76
- * A display name added to a selection.
77
- */
78
- displayName: string;
79
- /**
80
- * A color for UI elements.
81
- */
82
- color: string;
83
- }
84
- /**
85
- * The default selection style.
86
- */
87
- const defaultSelectionStyle: ISelectionStyle;
88
- /**
89
- * A text selection.
90
- */
91
- interface ITextSelection extends IRange {
92
- /**
93
- * The uuid of the text selection owner.
94
- */
95
- readonly uuid: string;
96
- /**
97
- * The style of this selection.
98
- */
99
- readonly style: ISelectionStyle;
100
- }
101
- /**
102
- * An interface for a text token, such as a word, keyword, or variable.
103
- */
104
- interface IToken {
105
- /**
106
- * The value of the token.
107
- */
108
- value: string;
109
- /**
110
- * The offset of the token in the code editor.
111
- */
112
- offset: number;
113
- /**
114
- * An optional type for the token.
115
- */
116
- type?: string;
117
- }
118
- /**
119
- * An interface to manage selections by selection owners.
120
- *
121
- * #### Definitions
122
- * - a user code that has an associated uuid is called a selection owner, see `CodeEditor.ISelectionOwner`
123
- * - a selection belongs to a selection owner only if it is associated with the owner by an uuid, see `CodeEditor.ITextSelection`
124
- *
125
- * #### Read access
126
- * - any user code can observe any selection
127
- *
128
- * #### Write access
129
- * - if a user code is a selection owner then:
130
- * - it can change selections belonging to it
131
- * - but it must not change selections belonging to other selection owners
132
- * - otherwise it must not change any selection
133
- */
134
- /**
135
- * An editor model.
136
- */
137
- interface IModel extends IDisposable {
138
- /**
139
- * A signal emitted when a property changes.
140
- */
141
- mimeTypeChanged: ISignal<IModel, IChangedArgs<string>>;
142
- /**
143
- * The text stored in the model.
144
- */
145
- readonly value: IObservableString;
146
- /**
147
- * A mime type of the model.
148
- *
149
- * #### Notes
150
- * It is never `null`, the default mime type is `text/plain`.
151
- */
152
- mimeType: string;
153
- /**
154
- * The currently selected code.
155
- */
156
- readonly selections: IObservableMap<ITextSelection[]>;
157
- /**
158
- * The underlying `IModelDB` instance in which model
159
- * data is stored.
160
- */
161
- readonly modelDB: IModelDB;
162
- }
163
- /**
164
- * The default implementation of the editor model.
165
- */
166
- class Model implements IModel {
167
- /**
168
- * Construct a new Model.
169
- */
170
- constructor(options?: Model.IOptions);
171
- /**
172
- * The underlying `IModelDB` instance in which model
173
- * data is stored.
174
- */
175
- readonly modelDB: IModelDB;
176
- /**
177
- * A signal emitted when a mimetype changes.
178
- */
179
- readonly mimeTypeChanged: ISignal<this, IChangedArgs<string>>;
180
- /**
181
- * Get the value of the model.
182
- */
183
- readonly value: IObservableString;
184
- /**
185
- * Get the selections for the model.
186
- */
187
- readonly selections: IObservableMap<ITextSelection[]>;
188
- /**
189
- * A mime type of the model.
190
- */
191
- mimeType: string;
192
- /**
193
- * Whether the model is disposed.
194
- */
195
- readonly isDisposed: boolean;
196
- /**
197
- * Dispose of the resources used by the model.
198
- */
199
- dispose(): void;
200
- private _onMimeTypeChanged;
201
- private _isDisposed;
202
- private _mimeTypeChanged;
203
- }
204
- /**
205
- * A selection owner.
206
- */
207
- interface ISelectionOwner {
208
- /**
209
- * The uuid of this selection owner.
210
- */
211
- uuid: string;
212
- /**
213
- * Returns the primary position of the cursor, never `null`.
214
- */
215
- getCursorPosition(): IPosition;
216
- /**
217
- * Set the primary position of the cursor.
218
- *
219
- * @param position - The new primary position.
220
- *
221
- * #### Notes
222
- * This will remove any secondary cursors.
223
- */
224
- setCursorPosition(position: IPosition): void;
225
- /**
226
- * Returns the primary selection, never `null`.
227
- */
228
- getSelection(): IRange;
229
- /**
230
- * Set the primary selection.
231
- *
232
- * @param selection - The desired selection range.
233
- *
234
- * #### Notes
235
- * This will remove any secondary cursors.
236
- */
237
- setSelection(selection: IRange): void;
238
- /**
239
- * Gets the selections for all the cursors, never `null` or empty.
240
- */
241
- getSelections(): IRange[];
242
- /**
243
- * Sets the selections for all the cursors.
244
- *
245
- * @param selections - The new selections.
246
- *
247
- * #### Notes
248
- * Cursors will be removed or added, as necessary.
249
- * Passing an empty array resets a cursor position to the start of a
250
- * document.
251
- */
252
- setSelections(selections: IRange[]): void;
253
- }
254
- /**
255
- * A keydown handler type.
256
- *
257
- * #### Notes
258
- * Return `true` to prevent the default handling of the event by the
259
- * editor.
260
- */
261
- type KeydownHandler = (instance: IEditor, event: KeyboardEvent) => boolean;
262
- /**
263
- * The location of requested edges.
264
- */
265
- type EdgeLocation = 'top' | 'bottom';
266
- /**
267
- * A widget that provides a code editor.
268
- */
269
- interface IEditor extends ISelectionOwner, IDisposable {
270
- /**
271
- * A signal emitted when either the top or bottom edge is requested.
272
- */
273
- readonly edgeRequested: ISignal<IEditor, EdgeLocation>;
274
- /**
275
- * The default selection style for the editor.
276
- */
277
- selectionStyle: CodeEditor.ISelectionStyle;
278
- /**
279
- * The DOM node that hosts the editor.
280
- */
281
- readonly host: HTMLElement;
282
- /**
283
- * The model used by the editor.
284
- */
285
- readonly model: IModel;
286
- /**
287
- * The height of a line in the editor in pixels.
288
- */
289
- readonly lineHeight: number;
290
- /**
291
- * The widget of a character in the editor in pixels.
292
- */
293
- readonly charWidth: number;
294
- /**
295
- * Get the number of lines in the eidtor.
296
- */
297
- readonly lineCount: number;
298
- /**
299
- * Get a config option for the editor.
300
- */
301
- getOption<K extends keyof IConfig>(option: K): IConfig[K];
302
- /**
303
- * Set a config option for the editor.
304
- */
305
- setOption<K extends keyof IConfig>(option: K, value: IConfig[K]): void;
306
- /**
307
- * Returns the content for the given line number.
308
- *
309
- * @param line - The line of interest.
310
- *
311
- * @returns The value of the line.
312
- *
313
- * #### Notes
314
- * Lines are 0-based, and accessing a line out of range returns
315
- * `undefined`.
316
- */
317
- getLine(line: number): string | undefined;
318
- /**
319
- * Find an offset for the given position.
320
- *
321
- * @param position - The position of interest.
322
- *
323
- * @returns The offset at the position, clamped to the extent of the
324
- * editor contents.
325
- */
326
- getOffsetAt(position: IPosition): number;
327
- /**
328
- * Find a position for the given offset.
329
- *
330
- * @param offset - The offset of interest.
331
- *
332
- * @returns The position at the offset, clamped to the extent of the
333
- * editor contents.
334
- */
335
- getPositionAt(offset: number): IPosition | undefined;
336
- /**
337
- * Undo one edit (if any undo events are stored).
338
- */
339
- undo(): void;
340
- /**
341
- * Redo one undone edit.
342
- */
343
- redo(): void;
344
- /**
345
- * Clear the undo history.
346
- */
347
- clearHistory(): void;
348
- /**
349
- * Brings browser focus to this editor text.
350
- */
351
- focus(): void;
352
- /**
353
- * Test whether the editor has keyboard focus.
354
- */
355
- hasFocus(): boolean;
356
- /**
357
- * Explicitly blur the editor.
358
- */
359
- blur(): void;
360
- /**
361
- * Repaint the editor.
362
- *
363
- * #### Notes
364
- * A repainted editor should fit to its host node.
365
- */
366
- refresh(): void;
367
- /**
368
- * Resize the editor to fit its host node.
369
- */
370
- resizeToFit(): void;
371
- /**
372
- * Add a keydown handler to the editor.
373
- *
374
- * @param handler - A keydown handler.
375
- *
376
- * @returns A disposable that can be used to remove the handler.
377
- */
378
- addKeydownHandler(handler: KeydownHandler): IDisposable;
379
- /**
380
- * Set the size of the editor.
381
- *
382
- * @param size - The desired size.
383
- *
384
- * #### Notes
385
- * Use `null` if the size is unknown.
386
- */
387
- setSize(size: IDimension | null): void;
388
- /**
389
- * Reveals the given position in the editor.
390
- *
391
- * @param position - The desired position to reveal.
392
- */
393
- revealPosition(position: IPosition): void;
394
- /**
395
- * Reveals the given selection in the editor.
396
- *
397
- * @param position - The desired selection to reveal.
398
- */
399
- revealSelection(selection: IRange): void;
400
- /**
401
- * Get the window coordinates given a cursor position.
402
- *
403
- * @param position - The desired position.
404
- *
405
- * @returns The coordinates of the position.
406
- */
407
- getCoordinateForPosition(position: IPosition): ICoordinate;
408
- /**
409
- * Get the cursor position given window coordinates.
410
- *
411
- * @param coordinate - The desired coordinate.
412
- *
413
- * @returns The position of the coordinates, or null if not
414
- * contained in the editor.
415
- */
416
- getPositionForCoordinate(coordinate: ICoordinate): IPosition | null;
417
- /**
418
- * Inserts a new line at the cursor position and indents it.
419
- */
420
- newIndentedLine(): void;
421
- /**
422
- * Gets the token at a given position.
423
- */
424
- getTokenForPosition(position: IPosition): IToken;
425
- /**
426
- * Gets the list of tokens for the editor model.
427
- */
428
- getTokens(): IToken[];
429
- }
430
- /**
431
- * A factory used to create a code editor.
432
- */
433
- type Factory = (options: IOptions) => CodeEditor.IEditor;
434
- /**
435
- * The configuration options for an editor.
436
- */
437
- interface IConfig {
438
- /**
439
- * User preferred font family for text editors.
440
- */
441
- fontFamily: string | null;
442
- /**
443
- * User preferred size in pixel of the font used in text editors.
444
- */
445
- fontSize: number | null;
446
- /**
447
- * User preferred text line height, as a multiplier of font size.
448
- */
449
- lineHeight: number | null;
450
- /**
451
- * Whether line numbers should be displayed.
452
- */
453
- lineNumbers: boolean;
454
- /**
455
- * Control the line wrapping of the editor. Possible values are:
456
- * - "off", lines will never wrap.
457
- * - "on", lines will wrap at the viewport border.
458
- * - "wordWrapColumn", lines will wrap at `wordWrapColumn`.
459
- * - "bounded", lines will wrap at minimum between viewport width and wordWrapColumn.
460
- */
461
- lineWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
462
- /**
463
- * Whether the editor is read-only.
464
- */
465
- readOnly: boolean;
466
- /**
467
- * The number of spaces a tab is equal to.
468
- */
469
- tabSize: number;
470
- /**
471
- * Whether to insert spaces when pressing Tab.
472
- */
473
- insertSpaces: boolean;
474
- /**
475
- * Whether to highlight matching brackets when one of them is selected.
476
- */
477
- matchBrackets: boolean;
478
- /**
479
- * Whether to automatically close brackets after opening them.
480
- */
481
- autoClosingBrackets: boolean;
482
- /**
483
- * The column where to break text line.
484
- */
485
- wordWrapColumn: number;
486
- }
487
- /**
488
- * The default configuration options for an editor.
489
- */
490
- let defaultConfig: IConfig;
491
- /**
492
- * The options used to initialize an editor.
493
- */
494
- interface IOptions {
495
- /**
496
- * The host widget used by the editor.
497
- */
498
- host: HTMLElement;
499
- /**
500
- * The model used by the editor.
501
- */
502
- model: IModel;
503
- /**
504
- * The desired uuid for the editor.
505
- */
506
- uuid?: string;
507
- /**
508
- * The default selection style for the editor.
509
- */
510
- selectionStyle?: Partial<CodeEditor.ISelectionStyle>;
511
- /**
512
- * The configuration options for the editor.
513
- */
514
- config?: Partial<IConfig>;
515
- }
516
- namespace Model {
517
- interface IOptions {
518
- /**
519
- * The initial value of the model.
520
- */
521
- value?: string;
522
- /**
523
- * The mimetype of the model.
524
- */
525
- mimeType?: string;
526
- /**
527
- * An optional modelDB for storing model state.
528
- */
529
- modelDB?: IModelDB;
530
- }
531
- }
532
- }
1
+ import { JSONObject } from '@phosphor/coreutils';
2
+ import { IDisposable } from '@phosphor/disposable';
3
+ import { ISignal } from '@phosphor/signaling';
4
+ import { IChangedArgs } from '@jupyterlab/coreutils';
5
+ import { IModelDB, IObservableMap, IObservableString } from '@jupyterlab/observables';
6
+ /**
7
+ * A namespace for code editors.
8
+ *
9
+ * #### Notes
10
+ * - A code editor is a set of common assumptions which hold for all concrete editors.
11
+ * - Changes in implementations of the code editor should only be caused by changes in concrete editors.
12
+ * - Common JLab services which are based on the code editor should belong to `IEditorServices`.
13
+ */
14
+ export declare namespace CodeEditor {
15
+ /**
16
+ * A zero-based position in the editor.
17
+ */
18
+ interface IPosition extends JSONObject {
19
+ /**
20
+ * The cursor line number.
21
+ */
22
+ readonly line: number;
23
+ /**
24
+ * The cursor column number.
25
+ */
26
+ readonly column: number;
27
+ }
28
+ /**
29
+ * The dimension of an element.
30
+ */
31
+ interface IDimension {
32
+ /**
33
+ * The width of an element in pixels.
34
+ */
35
+ readonly width: number;
36
+ /**
37
+ * The height of an element in pixels.
38
+ */
39
+ readonly height: number;
40
+ }
41
+ /**
42
+ * An interface describing editor state coordinates.
43
+ */
44
+ interface ICoordinate extends JSONObject, ClientRect {
45
+ }
46
+ /**
47
+ * A range.
48
+ */
49
+ interface IRange extends JSONObject {
50
+ /**
51
+ * The position of the first character in the current range.
52
+ *
53
+ * #### Notes
54
+ * If this position is greater than [end] then the range is considered
55
+ * to be backward.
56
+ */
57
+ readonly start: IPosition;
58
+ /**
59
+ * The position of the last character in the current range.
60
+ *
61
+ * #### Notes
62
+ * If this position is less than [start] then the range is considered
63
+ * to be backward.
64
+ */
65
+ readonly end: IPosition;
66
+ }
67
+ /**
68
+ * A selection style.
69
+ */
70
+ interface ISelectionStyle extends JSONObject {
71
+ /**
72
+ * A class name added to a selection.
73
+ */
74
+ className: string;
75
+ /**
76
+ * A display name added to a selection.
77
+ */
78
+ displayName: string;
79
+ /**
80
+ * A color for UI elements.
81
+ */
82
+ color: string;
83
+ }
84
+ /**
85
+ * The default selection style.
86
+ */
87
+ const defaultSelectionStyle: ISelectionStyle;
88
+ /**
89
+ * A text selection.
90
+ */
91
+ interface ITextSelection extends IRange {
92
+ /**
93
+ * The uuid of the text selection owner.
94
+ */
95
+ readonly uuid: string;
96
+ /**
97
+ * The style of this selection.
98
+ */
99
+ readonly style: ISelectionStyle;
100
+ }
101
+ /**
102
+ * An interface for a text token, such as a word, keyword, or variable.
103
+ */
104
+ interface IToken {
105
+ /**
106
+ * The value of the token.
107
+ */
108
+ value: string;
109
+ /**
110
+ * The offset of the token in the code editor.
111
+ */
112
+ offset: number;
113
+ /**
114
+ * An optional type for the token.
115
+ */
116
+ type?: string;
117
+ }
118
+ /**
119
+ * An interface to manage selections by selection owners.
120
+ *
121
+ * #### Definitions
122
+ * - a user code that has an associated uuid is called a selection owner, see `CodeEditor.ISelectionOwner`
123
+ * - a selection belongs to a selection owner only if it is associated with the owner by an uuid, see `CodeEditor.ITextSelection`
124
+ *
125
+ * #### Read access
126
+ * - any user code can observe any selection
127
+ *
128
+ * #### Write access
129
+ * - if a user code is a selection owner then:
130
+ * - it can change selections belonging to it
131
+ * - but it must not change selections belonging to other selection owners
132
+ * - otherwise it must not change any selection
133
+ */
134
+ /**
135
+ * An editor model.
136
+ */
137
+ interface IModel extends IDisposable {
138
+ /**
139
+ * A signal emitted when a property changes.
140
+ */
141
+ mimeTypeChanged: ISignal<IModel, IChangedArgs<string>>;
142
+ /**
143
+ * The text stored in the model.
144
+ */
145
+ readonly value: IObservableString;
146
+ /**
147
+ * A mime type of the model.
148
+ *
149
+ * #### Notes
150
+ * It is never `null`, the default mime type is `text/plain`.
151
+ */
152
+ mimeType: string;
153
+ /**
154
+ * The currently selected code.
155
+ */
156
+ readonly selections: IObservableMap<ITextSelection[]>;
157
+ /**
158
+ * The underlying `IModelDB` instance in which model
159
+ * data is stored.
160
+ */
161
+ readonly modelDB: IModelDB;
162
+ }
163
+ /**
164
+ * The default implementation of the editor model.
165
+ */
166
+ class Model implements IModel {
167
+ /**
168
+ * Construct a new Model.
169
+ */
170
+ constructor(options?: Model.IOptions);
171
+ /**
172
+ * The underlying `IModelDB` instance in which model
173
+ * data is stored.
174
+ */
175
+ readonly modelDB: IModelDB;
176
+ /**
177
+ * A signal emitted when a mimetype changes.
178
+ */
179
+ readonly mimeTypeChanged: ISignal<this, IChangedArgs<string>>;
180
+ /**
181
+ * Get the value of the model.
182
+ */
183
+ readonly value: IObservableString;
184
+ /**
185
+ * Get the selections for the model.
186
+ */
187
+ readonly selections: IObservableMap<ITextSelection[]>;
188
+ /**
189
+ * A mime type of the model.
190
+ */
191
+ mimeType: string;
192
+ /**
193
+ * Whether the model is disposed.
194
+ */
195
+ readonly isDisposed: boolean;
196
+ /**
197
+ * Dispose of the resources used by the model.
198
+ */
199
+ dispose(): void;
200
+ private _onMimeTypeChanged;
201
+ private _isDisposed;
202
+ private _mimeTypeChanged;
203
+ }
204
+ /**
205
+ * A selection owner.
206
+ */
207
+ interface ISelectionOwner {
208
+ /**
209
+ * The uuid of this selection owner.
210
+ */
211
+ uuid: string;
212
+ /**
213
+ * Returns the primary position of the cursor, never `null`.
214
+ */
215
+ getCursorPosition(): IPosition;
216
+ /**
217
+ * Set the primary position of the cursor.
218
+ *
219
+ * @param position - The new primary position.
220
+ *
221
+ * #### Notes
222
+ * This will remove any secondary cursors.
223
+ */
224
+ setCursorPosition(position: IPosition): void;
225
+ /**
226
+ * Returns the primary selection, never `null`.
227
+ */
228
+ getSelection(): IRange;
229
+ /**
230
+ * Set the primary selection.
231
+ *
232
+ * @param selection - The desired selection range.
233
+ *
234
+ * #### Notes
235
+ * This will remove any secondary cursors.
236
+ */
237
+ setSelection(selection: IRange): void;
238
+ /**
239
+ * Gets the selections for all the cursors, never `null` or empty.
240
+ */
241
+ getSelections(): IRange[];
242
+ /**
243
+ * Sets the selections for all the cursors.
244
+ *
245
+ * @param selections - The new selections.
246
+ *
247
+ * #### Notes
248
+ * Cursors will be removed or added, as necessary.
249
+ * Passing an empty array resets a cursor position to the start of a
250
+ * document.
251
+ */
252
+ setSelections(selections: IRange[]): void;
253
+ }
254
+ /**
255
+ * A keydown handler type.
256
+ *
257
+ * #### Notes
258
+ * Return `true` to prevent the default handling of the event by the
259
+ * editor.
260
+ */
261
+ type KeydownHandler = (instance: IEditor, event: KeyboardEvent) => boolean;
262
+ /**
263
+ * The location of requested edges.
264
+ */
265
+ type EdgeLocation = 'top' | 'bottom';
266
+ /**
267
+ * A widget that provides a code editor.
268
+ */
269
+ interface IEditor extends ISelectionOwner, IDisposable {
270
+ /**
271
+ * A signal emitted when either the top or bottom edge is requested.
272
+ */
273
+ readonly edgeRequested: ISignal<IEditor, EdgeLocation>;
274
+ /**
275
+ * The default selection style for the editor.
276
+ */
277
+ selectionStyle: CodeEditor.ISelectionStyle;
278
+ /**
279
+ * The DOM node that hosts the editor.
280
+ */
281
+ readonly host: HTMLElement;
282
+ /**
283
+ * The model used by the editor.
284
+ */
285
+ readonly model: IModel;
286
+ /**
287
+ * The height of a line in the editor in pixels.
288
+ */
289
+ readonly lineHeight: number;
290
+ /**
291
+ * The widget of a character in the editor in pixels.
292
+ */
293
+ readonly charWidth: number;
294
+ /**
295
+ * Get the number of lines in the eidtor.
296
+ */
297
+ readonly lineCount: number;
298
+ /**
299
+ * Get a config option for the editor.
300
+ */
301
+ getOption<K extends keyof IConfig>(option: K): IConfig[K];
302
+ /**
303
+ * Set a config option for the editor.
304
+ */
305
+ setOption<K extends keyof IConfig>(option: K, value: IConfig[K]): void;
306
+ /**
307
+ * Returns the content for the given line number.
308
+ *
309
+ * @param line - The line of interest.
310
+ *
311
+ * @returns The value of the line.
312
+ *
313
+ * #### Notes
314
+ * Lines are 0-based, and accessing a line out of range returns
315
+ * `undefined`.
316
+ */
317
+ getLine(line: number): string | undefined;
318
+ /**
319
+ * Find an offset for the given position.
320
+ *
321
+ * @param position - The position of interest.
322
+ *
323
+ * @returns The offset at the position, clamped to the extent of the
324
+ * editor contents.
325
+ */
326
+ getOffsetAt(position: IPosition): number;
327
+ /**
328
+ * Find a position for the given offset.
329
+ *
330
+ * @param offset - The offset of interest.
331
+ *
332
+ * @returns The position at the offset, clamped to the extent of the
333
+ * editor contents.
334
+ */
335
+ getPositionAt(offset: number): IPosition | undefined;
336
+ /**
337
+ * Undo one edit (if any undo events are stored).
338
+ */
339
+ undo(): void;
340
+ /**
341
+ * Redo one undone edit.
342
+ */
343
+ redo(): void;
344
+ /**
345
+ * Clear the undo history.
346
+ */
347
+ clearHistory(): void;
348
+ /**
349
+ * Brings browser focus to this editor text.
350
+ */
351
+ focus(): void;
352
+ /**
353
+ * Test whether the editor has keyboard focus.
354
+ */
355
+ hasFocus(): boolean;
356
+ /**
357
+ * Explicitly blur the editor.
358
+ */
359
+ blur(): void;
360
+ /**
361
+ * Repaint the editor.
362
+ *
363
+ * #### Notes
364
+ * A repainted editor should fit to its host node.
365
+ */
366
+ refresh(): void;
367
+ /**
368
+ * Resize the editor to fit its host node.
369
+ */
370
+ resizeToFit(): void;
371
+ /**
372
+ * Add a keydown handler to the editor.
373
+ *
374
+ * @param handler - A keydown handler.
375
+ *
376
+ * @returns A disposable that can be used to remove the handler.
377
+ */
378
+ addKeydownHandler(handler: KeydownHandler): IDisposable;
379
+ /**
380
+ * Set the size of the editor.
381
+ *
382
+ * @param size - The desired size.
383
+ *
384
+ * #### Notes
385
+ * Use `null` if the size is unknown.
386
+ */
387
+ setSize(size: IDimension | null): void;
388
+ /**
389
+ * Reveals the given position in the editor.
390
+ *
391
+ * @param position - The desired position to reveal.
392
+ */
393
+ revealPosition(position: IPosition): void;
394
+ /**
395
+ * Reveals the given selection in the editor.
396
+ *
397
+ * @param position - The desired selection to reveal.
398
+ */
399
+ revealSelection(selection: IRange): void;
400
+ /**
401
+ * Get the window coordinates given a cursor position.
402
+ *
403
+ * @param position - The desired position.
404
+ *
405
+ * @returns The coordinates of the position.
406
+ */
407
+ getCoordinateForPosition(position: IPosition): ICoordinate;
408
+ /**
409
+ * Get the cursor position given window coordinates.
410
+ *
411
+ * @param coordinate - The desired coordinate.
412
+ *
413
+ * @returns The position of the coordinates, or null if not
414
+ * contained in the editor.
415
+ */
416
+ getPositionForCoordinate(coordinate: ICoordinate): IPosition | null;
417
+ /**
418
+ * Inserts a new line at the cursor position and indents it.
419
+ */
420
+ newIndentedLine(): void;
421
+ /**
422
+ * Gets the token at a given position.
423
+ */
424
+ getTokenForPosition(position: IPosition): IToken;
425
+ /**
426
+ * Gets the list of tokens for the editor model.
427
+ */
428
+ getTokens(): IToken[];
429
+ }
430
+ /**
431
+ * A factory used to create a code editor.
432
+ */
433
+ type Factory = (options: IOptions) => CodeEditor.IEditor;
434
+ /**
435
+ * The configuration options for an editor.
436
+ */
437
+ interface IConfig {
438
+ /**
439
+ * User preferred font family for text editors.
440
+ */
441
+ fontFamily: string | null;
442
+ /**
443
+ * User preferred size in pixel of the font used in text editors.
444
+ */
445
+ fontSize: number | null;
446
+ /**
447
+ * User preferred text line height, as a multiplier of font size.
448
+ */
449
+ lineHeight: number | null;
450
+ /**
451
+ * Whether line numbers should be displayed.
452
+ */
453
+ lineNumbers: boolean;
454
+ /**
455
+ * Control the line wrapping of the editor. Possible values are:
456
+ * - "off", lines will never wrap.
457
+ * - "on", lines will wrap at the viewport border.
458
+ * - "wordWrapColumn", lines will wrap at `wordWrapColumn`.
459
+ * - "bounded", lines will wrap at minimum between viewport width and wordWrapColumn.
460
+ */
461
+ lineWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
462
+ /**
463
+ * Whether the editor is read-only.
464
+ */
465
+ readOnly: boolean;
466
+ /**
467
+ * The number of spaces a tab is equal to.
468
+ */
469
+ tabSize: number;
470
+ /**
471
+ * Whether to insert spaces when pressing Tab.
472
+ */
473
+ insertSpaces: boolean;
474
+ /**
475
+ * Whether to highlight matching brackets when one of them is selected.
476
+ */
477
+ matchBrackets: boolean;
478
+ /**
479
+ * Whether to automatically close brackets after opening them.
480
+ */
481
+ autoClosingBrackets: boolean;
482
+ /**
483
+ * The column where to break text line.
484
+ */
485
+ wordWrapColumn: number;
486
+ }
487
+ /**
488
+ * The default configuration options for an editor.
489
+ */
490
+ let defaultConfig: IConfig;
491
+ /**
492
+ * The options used to initialize an editor.
493
+ */
494
+ interface IOptions {
495
+ /**
496
+ * The host widget used by the editor.
497
+ */
498
+ host: HTMLElement;
499
+ /**
500
+ * The model used by the editor.
501
+ */
502
+ model: IModel;
503
+ /**
504
+ * The desired uuid for the editor.
505
+ */
506
+ uuid?: string;
507
+ /**
508
+ * The default selection style for the editor.
509
+ */
510
+ selectionStyle?: Partial<CodeEditor.ISelectionStyle>;
511
+ /**
512
+ * The configuration options for the editor.
513
+ */
514
+ config?: Partial<IConfig>;
515
+ }
516
+ namespace Model {
517
+ interface IOptions {
518
+ /**
519
+ * The initial value of the model.
520
+ */
521
+ value?: string;
522
+ /**
523
+ * The mimetype of the model.
524
+ */
525
+ mimeType?: string;
526
+ /**
527
+ * An optional modelDB for storing model state.
528
+ */
529
+ modelDB?: IModelDB;
530
+ }
531
+ }
532
+ }