Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/editorBrowser.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IKeyboardEvent } from '../../base/browser/keyboardEvent.js';
7
import { IMouseEvent, IMouseWheelEvent } from '../../base/browser/mouseEvent.js';
8
import { IBoundarySashes } from '../../base/browser/ui/sash/sash.js';
9
import { Event } from '../../base/common/event.js';
10
import { IEditorConstructionOptions } from './config/editorConfiguration.js';
11
import { ConfigurationChangedEvent, EditorLayoutInfo, EditorOption, FindComputedEditorOptionValueById, IComputedEditorOptions, IDiffEditorOptions, IEditorOptions, OverviewRulerPosition } from '../common/config/editorOptions.js';
12
import { IDimension } from '../common/core/2d/dimension.js';
13
import { IPosition, Position } from '../common/core/position.js';
14
import { IRange, Range } from '../common/core/range.js';
15
import { Selection } from '../common/core/selection.js';
16
import { IWordAtPosition } from '../common/core/wordHelper.js';
17
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from '../common/cursorEvents.js';
18
import { IDiffComputationResult, ILineChange } from '../common/diff/legacyLinesDiffComputer.js';
19
import * as editorCommon from '../common/editorCommon.js';
20
import { GlyphMarginLane, ICursorStateComputer, IIdentifiedSingleEditOperation, IModelDecoration, IModelDeltaDecoration, ITextModel, PositionAffinity } from '../common/model.js';
21
import { InjectedText } from '../common/modelLineProjectionData.js';
22
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelFontChangedEvent, ModelLineHeightChangedEvent } from '../common/textModelEvents.js';
23
import { IEditorWhitespace, IViewModel } from '../common/viewModel.js';
24
import { OverviewRulerZone } from '../common/viewModel/overviewZoneManager.js';
25
import { MenuId } from '../../platform/actions/common/actions.js';
26
import { IContextKeyService } from '../../platform/contextkey/common/contextkey.js';
27
import { ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';
28
import { TextEdit } from '../common/core/edits/textEdit.js';
29
import { TextModelEditSource } from '../common/textModelEditSource.js';
30
31
/**
32
* A view zone is a full horizontal rectangle that 'pushes' text down.
33
* The editor reserves space for view zones when rendering.
34
*/
35
export interface IViewZone {
36
/**
37
* The line number after which this zone should appear.
38
* Use 0 to place a view zone before the first line number.
39
*/
40
afterLineNumber: number;
41
/**
42
* The column after which this zone should appear.
43
* If not set, the maxLineColumn of `afterLineNumber` will be used.
44
* This is relevant for wrapped lines.
45
*/
46
afterColumn?: number;
47
/**
48
* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.
49
*/
50
afterColumnAffinity?: PositionAffinity;
51
/**
52
* Render the zone even when its line is hidden.
53
*/
54
showInHiddenAreas?: boolean;
55
/**
56
* Tiebreaker that is used when multiple view zones want to be after the same line.
57
* Defaults to `afterColumn` otherwise 10000;
58
*/
59
ordinal?: number;
60
/**
61
* Suppress mouse down events.
62
* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.
63
* Defaults to false
64
*/
65
suppressMouseDown?: boolean;
66
/**
67
* The height in lines of the view zone.
68
* If specified, `heightInPx` will be used instead of this.
69
* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.
70
*/
71
heightInLines?: number;
72
/**
73
* The height in px of the view zone.
74
* If this is set, the editor will give preference to it rather than `heightInLines` above.
75
* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.
76
*/
77
heightInPx?: number;
78
/**
79
* The minimum width in px of the view zone.
80
* If this is set, the editor will ensure that the scroll width is >= than this value.
81
*/
82
minWidthInPx?: number;
83
/**
84
* The dom node of the view zone
85
*/
86
domNode: HTMLElement;
87
/**
88
* An optional dom node for the view zone that will be placed in the margin area.
89
*/
90
marginDomNode?: HTMLElement | null;
91
/**
92
* Callback which gives the relative top of the view zone as it appears (taking scrolling into account).
93
*/
94
onDomNodeTop?: (top: number) => void;
95
/**
96
* Callback which gives the height in pixels of the view zone.
97
*/
98
onComputedHeight?: (height: number) => void;
99
}
100
/**
101
* An accessor that allows for zones to be added or removed.
102
*/
103
export interface IViewZoneChangeAccessor {
104
/**
105
* Create a new view zone.
106
* @param zone Zone to create
107
* @return A unique identifier to the view zone.
108
*/
109
addZone(zone: IViewZone): string;
110
/**
111
* Remove a zone
112
* @param id A unique identifier to the view zone, as returned by the `addZone` call.
113
*/
114
removeZone(id: string): void;
115
/**
116
* Change a zone's position.
117
* The editor will rescan the `afterLineNumber` and `afterColumn` properties of a view zone.
118
*/
119
layoutZone(id: string): void;
120
}
121
122
/**
123
* A positioning preference for rendering content widgets.
124
*/
125
export const enum ContentWidgetPositionPreference {
126
/**
127
* Place the content widget exactly at a position
128
*/
129
EXACT,
130
/**
131
* Place the content widget above a position
132
*/
133
ABOVE,
134
/**
135
* Place the content widget below a position
136
*/
137
BELOW
138
}
139
/**
140
* A position for rendering content widgets.
141
*/
142
export interface IContentWidgetPosition {
143
/**
144
* Desired position which serves as an anchor for placing the content widget.
145
* The widget will be placed above, at, or below the specified position, based on the
146
* provided preference. The widget will always touch this position.
147
*
148
* Given sufficient horizontal space, the widget will be placed to the right of the
149
* passed in position. This can be tweaked by providing a `secondaryPosition`.
150
*
151
* @see preference
152
* @see secondaryPosition
153
*/
154
position: IPosition | null;
155
/**
156
* Optionally, a secondary position can be provided to further define the placing of
157
* the content widget. The secondary position must have the same line number as the
158
* primary position. If possible, the widget will be placed such that it also touches
159
* the secondary position.
160
*/
161
secondaryPosition?: IPosition | null;
162
/**
163
* Placement preference for position, in order of preference.
164
*/
165
preference: ContentWidgetPositionPreference[];
166
167
/**
168
* Placement preference when multiple view positions refer to the same (model) position.
169
* This plays a role when injected text is involved.
170
*/
171
positionAffinity?: PositionAffinity;
172
}
173
/**
174
* A content widget renders inline with the text and can be easily placed 'near' an editor position.
175
*/
176
export interface IContentWidget {
177
/**
178
* Render this content widget in a location where it could overflow the editor's view dom node.
179
*/
180
allowEditorOverflow?: boolean;
181
/**
182
* Call preventDefault() on mousedown events that target the content widget.
183
*/
184
suppressMouseDown?: boolean;
185
/**
186
* Get a unique identifier of the content widget.
187
*/
188
getId(): string;
189
/**
190
* Get the dom node of the content widget.
191
*/
192
getDomNode(): HTMLElement;
193
/**
194
* Get the placement of the content widget.
195
* If null is returned, the content widget will be placed off screen.
196
*/
197
getPosition(): IContentWidgetPosition | null;
198
/**
199
* Optional function that is invoked before rendering
200
* the content widget. If a dimension is returned the editor will
201
* attempt to use it.
202
*/
203
beforeRender?(): IDimension | null;
204
/**
205
* Optional function that is invoked after rendering the content
206
* widget. Is being invoked with the selected position preference
207
* or `null` if not rendered.
208
*/
209
afterRender?(position: ContentWidgetPositionPreference | null, coordinate: IContentWidgetRenderedCoordinate | null): void;
210
}
211
212
/**
213
* Coordinatees passed in {@link IContentWidget.afterRender}
214
*/
215
export interface IContentWidgetRenderedCoordinate {
216
/**
217
* Top position relative to the editor content.
218
*/
219
readonly top: number;
220
221
/**
222
* Left position relative to the editor content.
223
*/
224
readonly left: number;
225
}
226
227
/**
228
* A positioning preference for rendering overlay widgets.
229
*/
230
export const enum OverlayWidgetPositionPreference {
231
/**
232
* Position the overlay widget in the top right corner
233
*/
234
TOP_RIGHT_CORNER,
235
236
/**
237
* Position the overlay widget in the bottom right corner
238
*/
239
BOTTOM_RIGHT_CORNER,
240
241
/**
242
* Position the overlay widget in the top center
243
*/
244
TOP_CENTER
245
}
246
247
248
/**
249
* Represents editor-relative coordinates of an overlay widget.
250
*/
251
export interface IOverlayWidgetPositionCoordinates {
252
/**
253
* The top position for the overlay widget, relative to the editor.
254
*/
255
top: number;
256
/**
257
* The left position for the overlay widget, relative to the editor.
258
*/
259
left: number;
260
}
261
262
/**
263
* A position for rendering overlay widgets.
264
*/
265
export interface IOverlayWidgetPosition {
266
/**
267
* The position preference for the overlay widget.
268
*/
269
preference: OverlayWidgetPositionPreference | IOverlayWidgetPositionCoordinates | null;
270
271
/**
272
* When set, stacks with other overlay widgets with the same preference,
273
* in an order determined by the ordinal value.
274
*/
275
stackOridinal?: number;
276
}
277
/**
278
* An overlay widgets renders on top of the text.
279
*/
280
export interface IOverlayWidget {
281
/**
282
* Event fired when the widget layout changes.
283
*/
284
onDidLayout?: Event<void>;
285
/**
286
* Render this overlay widget in a location where it could overflow the editor's view dom node.
287
*/
288
allowEditorOverflow?: boolean;
289
/**
290
* Get a unique identifier of the overlay widget.
291
*/
292
getId(): string;
293
/**
294
* Get the dom node of the overlay widget.
295
*/
296
getDomNode(): HTMLElement;
297
/**
298
* Get the placement of the overlay widget.
299
* If null is returned, the overlay widget is responsible to place itself.
300
*/
301
getPosition(): IOverlayWidgetPosition | null;
302
/**
303
* The editor will ensure that the scroll width is >= than this value.
304
*/
305
getMinContentWidthInPx?(): number;
306
}
307
308
/**
309
* A glyph margin widget renders in the editor glyph margin.
310
*/
311
export interface IGlyphMarginWidget {
312
/**
313
* Get a unique identifier of the glyph widget.
314
*/
315
getId(): string;
316
/**
317
* Get the dom node of the glyph widget.
318
*/
319
getDomNode(): HTMLElement;
320
/**
321
* Get the placement of the glyph widget.
322
*/
323
getPosition(): IGlyphMarginWidgetPosition;
324
}
325
326
/**
327
* A position for rendering glyph margin widgets.
328
*/
329
export interface IGlyphMarginWidgetPosition {
330
/**
331
* The glyph margin lane where the widget should be shown.
332
*/
333
lane: GlyphMarginLane;
334
/**
335
* The priority order of the widget, used for determining which widget
336
* to render when there are multiple.
337
*/
338
zIndex: number;
339
/**
340
* The editor range that this widget applies to.
341
*/
342
range: IRange;
343
}
344
345
/**
346
* Type of hit element with the mouse in the editor.
347
*/
348
export const enum MouseTargetType {
349
/**
350
* Mouse is on top of an unknown element.
351
*/
352
UNKNOWN,
353
/**
354
* Mouse is on top of the textarea used for input.
355
*/
356
TEXTAREA,
357
/**
358
* Mouse is on top of the glyph margin
359
*/
360
GUTTER_GLYPH_MARGIN,
361
/**
362
* Mouse is on top of the line numbers
363
*/
364
GUTTER_LINE_NUMBERS,
365
/**
366
* Mouse is on top of the line decorations
367
*/
368
GUTTER_LINE_DECORATIONS,
369
/**
370
* Mouse is on top of the whitespace left in the gutter by a view zone.
371
*/
372
GUTTER_VIEW_ZONE,
373
/**
374
* Mouse is on top of text in the content.
375
*/
376
CONTENT_TEXT,
377
/**
378
* Mouse is on top of empty space in the content (e.g. after line text or below last line)
379
*/
380
CONTENT_EMPTY,
381
/**
382
* Mouse is on top of a view zone in the content.
383
*/
384
CONTENT_VIEW_ZONE,
385
/**
386
* Mouse is on top of a content widget.
387
*/
388
CONTENT_WIDGET,
389
/**
390
* Mouse is on top of the decorations overview ruler.
391
*/
392
OVERVIEW_RULER,
393
/**
394
* Mouse is on top of a scrollbar.
395
*/
396
SCROLLBAR,
397
/**
398
* Mouse is on top of an overlay widget.
399
*/
400
OVERLAY_WIDGET,
401
/**
402
* Mouse is outside of the editor.
403
*/
404
OUTSIDE_EDITOR,
405
}
406
export interface IBaseMouseTarget {
407
/**
408
* The target element
409
*/
410
readonly element: HTMLElement | null;
411
/**
412
* The 'approximate' editor position
413
*/
414
readonly position: Position | null;
415
/**
416
* Desired mouse column (e.g. when position.column gets clamped to text length -- clicking after text on a line).
417
*/
418
readonly mouseColumn: number;
419
/**
420
* The 'approximate' editor range
421
*/
422
readonly range: Range | null;
423
}
424
export interface IMouseTargetUnknown extends IBaseMouseTarget {
425
readonly type: MouseTargetType.UNKNOWN;
426
}
427
export interface IMouseTargetTextarea extends IBaseMouseTarget {
428
readonly type: MouseTargetType.TEXTAREA;
429
readonly position: null;
430
readonly range: null;
431
}
432
export interface IMouseTargetMarginData {
433
readonly isAfterLines: boolean;
434
readonly glyphMarginLeft: number;
435
readonly glyphMarginWidth: number;
436
readonly glyphMarginLane?: GlyphMarginLane;
437
readonly lineNumbersWidth: number;
438
readonly offsetX: number;
439
}
440
export interface IMouseTargetMargin extends IBaseMouseTarget {
441
readonly type: MouseTargetType.GUTTER_GLYPH_MARGIN | MouseTargetType.GUTTER_LINE_NUMBERS | MouseTargetType.GUTTER_LINE_DECORATIONS;
442
readonly position: Position;
443
readonly range: Range;
444
readonly detail: IMouseTargetMarginData;
445
}
446
export interface IMouseTargetViewZoneData {
447
readonly viewZoneId: string;
448
readonly positionBefore: Position | null;
449
readonly positionAfter: Position | null;
450
readonly position: Position;
451
readonly afterLineNumber: number;
452
}
453
export interface IMouseTargetViewZone extends IBaseMouseTarget {
454
readonly type: MouseTargetType.GUTTER_VIEW_ZONE | MouseTargetType.CONTENT_VIEW_ZONE;
455
readonly position: Position;
456
readonly range: Range;
457
readonly detail: IMouseTargetViewZoneData;
458
}
459
export interface IMouseTargetContentTextData {
460
readonly mightBeForeignElement: boolean;
461
/**
462
* @internal
463
*/
464
readonly injectedText: InjectedText | null;
465
}
466
export interface IMouseTargetContentText extends IBaseMouseTarget {
467
readonly type: MouseTargetType.CONTENT_TEXT;
468
readonly position: Position;
469
readonly range: Range;
470
readonly detail: IMouseTargetContentTextData;
471
}
472
export interface IMouseTargetContentEmptyData {
473
readonly isAfterLines: boolean;
474
readonly horizontalDistanceToText?: number;
475
}
476
export interface IMouseTargetContentEmpty extends IBaseMouseTarget {
477
readonly type: MouseTargetType.CONTENT_EMPTY;
478
readonly position: Position;
479
readonly range: Range;
480
readonly detail: IMouseTargetContentEmptyData;
481
}
482
export interface IMouseTargetContentWidget extends IBaseMouseTarget {
483
readonly type: MouseTargetType.CONTENT_WIDGET;
484
readonly position: null;
485
readonly range: null;
486
readonly detail: string;
487
}
488
export interface IMouseTargetOverlayWidget extends IBaseMouseTarget {
489
readonly type: MouseTargetType.OVERLAY_WIDGET;
490
readonly position: null;
491
readonly range: null;
492
readonly detail: string;
493
}
494
export interface IMouseTargetScrollbar extends IBaseMouseTarget {
495
readonly type: MouseTargetType.SCROLLBAR;
496
readonly position: Position;
497
readonly range: Range;
498
}
499
export interface IMouseTargetOverviewRuler extends IBaseMouseTarget {
500
readonly type: MouseTargetType.OVERVIEW_RULER;
501
}
502
export interface IMouseTargetOutsideEditor extends IBaseMouseTarget {
503
readonly type: MouseTargetType.OUTSIDE_EDITOR;
504
readonly outsidePosition: 'above' | 'below' | 'left' | 'right';
505
readonly outsideDistance: number;
506
}
507
/**
508
* Target hit with the mouse in the editor.
509
*/
510
export type IMouseTarget = (
511
IMouseTargetUnknown
512
| IMouseTargetTextarea
513
| IMouseTargetMargin
514
| IMouseTargetViewZone
515
| IMouseTargetContentText
516
| IMouseTargetContentEmpty
517
| IMouseTargetContentWidget
518
| IMouseTargetOverlayWidget
519
| IMouseTargetScrollbar
520
| IMouseTargetOverviewRuler
521
| IMouseTargetOutsideEditor
522
);
523
/**
524
* A mouse event originating from the editor.
525
*/
526
export interface IEditorMouseEvent {
527
readonly event: IMouseEvent;
528
readonly target: IMouseTarget;
529
}
530
export interface IPartialEditorMouseEvent {
531
readonly event: IMouseEvent;
532
readonly target: IMouseTarget | null;
533
}
534
535
/**
536
* A paste event originating from the editor.
537
*/
538
export interface IPasteEvent {
539
readonly range: Range;
540
readonly languageId: string | null;
541
readonly clipboardEvent?: ClipboardEvent;
542
}
543
544
/**
545
* @internal
546
*/
547
export interface PastePayload {
548
text: string;
549
pasteOnNewLine: boolean;
550
multicursorText: string[] | null;
551
mode: string | null;
552
clipboardEvent?: ClipboardEvent;
553
}
554
555
/**
556
* An overview ruler
557
* @internal
558
*/
559
export interface IOverviewRuler {
560
getDomNode(): HTMLElement;
561
dispose(): void;
562
setZones(zones: OverviewRulerZone[]): void;
563
setLayout(position: OverviewRulerPosition): void;
564
}
565
566
/**
567
* Editor aria options.
568
* @internal
569
*/
570
export interface IEditorAriaOptions {
571
activeDescendant: string | undefined;
572
role?: string;
573
}
574
575
export interface IDiffEditorConstructionOptions extends IDiffEditorOptions, IEditorConstructionOptions {
576
/**
577
* Place overflow widgets inside an external DOM node.
578
* Defaults to an internal DOM node.
579
*/
580
overflowWidgetsDomNode?: HTMLElement;
581
582
/**
583
* Aria label for original editor.
584
*/
585
originalAriaLabel?: string;
586
587
/**
588
* Aria label for modified editor.
589
*/
590
modifiedAriaLabel?: string;
591
}
592
593
/**
594
* A rich code editor.
595
*/
596
export interface ICodeEditor extends editorCommon.IEditor {
597
/**
598
* This editor is used as an alternative to an <input> box, i.e. as a simple widget.
599
* @internal
600
*/
601
readonly isSimpleWidget: boolean;
602
/**
603
* The context menu ID that should be used to lookup context menu actions.
604
* @internal
605
*/
606
readonly contextMenuId: MenuId;
607
/**
608
* The editor's scoped context key service.
609
* @internal
610
*/
611
readonly contextKeyService: IContextKeyService;
612
/**
613
* An event emitted when the content of the current model has changed.
614
* @event
615
*/
616
readonly onDidChangeModelContent: Event<IModelContentChangedEvent>;
617
/**
618
* An event emitted when the language of the current model has changed.
619
* @event
620
*/
621
readonly onDidChangeModelLanguage: Event<IModelLanguageChangedEvent>;
622
/**
623
* An event emitted when the language configuration of the current model has changed.
624
* @event
625
*/
626
readonly onDidChangeModelLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;
627
/**
628
* An event emitted when the options of the current model has changed.
629
* @event
630
*/
631
readonly onDidChangeModelOptions: Event<IModelOptionsChangedEvent>;
632
/**
633
* An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`)
634
* @event
635
*/
636
readonly onDidChangeConfiguration: Event<ConfigurationChangedEvent>;
637
/**
638
* An event emitted when the cursor position has changed.
639
* @event
640
*/
641
readonly onDidChangeCursorPosition: Event<ICursorPositionChangedEvent>;
642
/**
643
* An event emitted when the cursor selection has changed.
644
* @event
645
*/
646
readonly onDidChangeCursorSelection: Event<ICursorSelectionChangedEvent>;
647
/**
648
* An event emitted when the model of this editor is about to change (e.g. from `editor.setModel()`).
649
* @event
650
*/
651
readonly onWillChangeModel: Event<editorCommon.IModelChangedEvent>;
652
/**
653
* An event emitted when the model of this editor has changed (e.g. `editor.setModel()`).
654
* @event
655
*/
656
readonly onDidChangeModel: Event<editorCommon.IModelChangedEvent>;
657
/**
658
* An event emitted when the decorations of the current model have changed.
659
* @event
660
*/
661
readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent>;
662
/**
663
* An event emitted when the tokens of the current model have changed.
664
* @internal
665
*/
666
readonly onDidChangeModelTokens: Event<IModelTokensChangedEvent>;
667
/**
668
* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).
669
* @event
670
*/
671
readonly onDidFocusEditorText: Event<void>;
672
/**
673
* An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).
674
* @event
675
*/
676
readonly onDidBlurEditorText: Event<void>;
677
/**
678
* An event emitted when the text inside this editor or an editor widget gained focus.
679
* @event
680
*/
681
readonly onDidFocusEditorWidget: Event<void>;
682
/**
683
* An event emitted when the text inside this editor or an editor widget lost focus.
684
* @event
685
*/
686
readonly onDidBlurEditorWidget: Event<void>;
687
/**
688
* An event emitted before interpreting typed characters (on the keyboard).
689
* @event
690
* @internal
691
*/
692
readonly onWillType: Event<string>;
693
/**
694
* An event emitted after interpreting typed characters (on the keyboard).
695
* @event
696
* @internal
697
*/
698
readonly onDidType: Event<string>;
699
/**
700
* Boolean indicating whether input is in composition
701
*/
702
readonly inComposition: boolean;
703
/**
704
* An event emitted after composition has started.
705
*/
706
readonly onDidCompositionStart: Event<void>;
707
/**
708
* An event emitted after composition has ended.
709
*/
710
readonly onDidCompositionEnd: Event<void>;
711
/**
712
* An event emitted when editing failed because the editor is read-only.
713
* @event
714
*/
715
readonly onDidAttemptReadOnlyEdit: Event<void>;
716
/**
717
* An event emitted when users paste text in the editor.
718
* @event
719
*/
720
readonly onDidPaste: Event<IPasteEvent>;
721
/**
722
* An event emitted on a "mouseup".
723
* @event
724
*/
725
readonly onMouseUp: Event<IEditorMouseEvent>;
726
/**
727
* An event emitted on a "mousedown".
728
* @event
729
*/
730
readonly onMouseDown: Event<IEditorMouseEvent>;
731
/**
732
* An event emitted on a "mousedrag".
733
* @internal
734
* @event
735
*/
736
readonly onMouseDrag: Event<IEditorMouseEvent>;
737
/**
738
* An event emitted on a "mousedrop".
739
* @internal
740
* @event
741
*/
742
readonly onMouseDrop: Event<IPartialEditorMouseEvent>;
743
/**
744
* An event emitted on a "mousedropcanceled".
745
* @internal
746
* @event
747
*/
748
readonly onMouseDropCanceled: Event<void>;
749
/**
750
* An event emitted when content is dropped into the editor.
751
* @internal
752
* @event
753
*/
754
readonly onDropIntoEditor: Event<{ readonly position: IPosition; readonly event: DragEvent }>;
755
/**
756
* An event emitted on a "contextmenu".
757
* @event
758
*/
759
readonly onContextMenu: Event<IEditorMouseEvent>;
760
/**
761
* An event emitted on a "mousemove".
762
* @event
763
*/
764
readonly onMouseMove: Event<IEditorMouseEvent>;
765
/**
766
* An event emitted on a "mouseleave".
767
* @event
768
*/
769
readonly onMouseLeave: Event<IPartialEditorMouseEvent>;
770
/**
771
* An event emitted on a "mousewheel"
772
* @event
773
* @internal
774
*/
775
readonly onMouseWheel: Event<IMouseWheelEvent>;
776
/**
777
* An event emitted on a "keyup".
778
* @event
779
*/
780
readonly onKeyUp: Event<IKeyboardEvent>;
781
/**
782
* An event emitted on a "keydown".
783
* @event
784
*/
785
readonly onKeyDown: Event<IKeyboardEvent>;
786
/**
787
* An event emitted when the layout of the editor has changed.
788
* @event
789
*/
790
readonly onDidLayoutChange: Event<EditorLayoutInfo>;
791
/**
792
* An event emitted when the content width or content height in the editor has changed.
793
* @event
794
*/
795
readonly onDidContentSizeChange: Event<editorCommon.IContentSizeChangedEvent>;
796
/**
797
* An event emitted when the scroll in the editor has changed.
798
* @event
799
*/
800
readonly onDidScrollChange: Event<editorCommon.IScrollEvent>;
801
802
/**
803
* An event emitted when hidden areas change in the editor (e.g. due to folding).
804
* @event
805
*/
806
readonly onDidChangeHiddenAreas: Event<void>;
807
808
/**
809
* An event emitted before an editor
810
* @internal
811
*/
812
readonly onWillTriggerEditorOperationEvent: Event<editorCommon.ITriggerEditorOperationEvent>;
813
814
/**
815
* Some editor operations fire multiple events at once.
816
* To allow users to react to multiple events fired by a single operation,
817
* the editor fires a begin update before the operation and an end update after the operation.
818
* Whenever the editor fires `onBeginUpdate`, it will also fire `onEndUpdate` once the operation finishes.
819
* Note that not all operations are bracketed by `onBeginUpdate` and `onEndUpdate`.
820
*/
821
readonly onBeginUpdate: Event<void>;
822
823
/**
824
* Fires after the editor completes the operation it fired `onBeginUpdate` for.
825
*/
826
readonly onEndUpdate: Event<void>;
827
828
/**
829
* Saves current view state of the editor in a serializable object.
830
*/
831
saveViewState(): editorCommon.ICodeEditorViewState | null;
832
833
/**
834
* Restores the view state of the editor from a serializable object generated by `saveViewState`.
835
*/
836
restoreViewState(state: editorCommon.ICodeEditorViewState | null): void;
837
838
/**
839
* Returns true if the text inside this editor or an editor widget has focus.
840
*/
841
hasWidgetFocus(): boolean;
842
843
/**
844
* Get a contribution of this editor.
845
* @id Unique identifier of the contribution.
846
* @return The contribution or null if contribution not found.
847
*/
848
getContribution<T extends editorCommon.IEditorContribution>(id: string): T | null;
849
850
/**
851
* Execute `fn` with the editor's services.
852
* @internal
853
*/
854
invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T;
855
856
/**
857
* Type the getModel() of IEditor.
858
*/
859
getModel(): ITextModel | null;
860
861
/**
862
* Sets the current model attached to this editor.
863
* If the previous model was created by the editor via the value key in the options
864
* literal object, it will be destroyed. Otherwise, if the previous model was set
865
* via setModel, or the model key in the options literal object, the previous model
866
* will not be destroyed.
867
* It is safe to call setModel(null) to simply detach the current model from the editor.
868
*/
869
setModel(model: ITextModel | null): void;
870
871
/**
872
* Gets all the editor computed options.
873
*/
874
getOptions(): IComputedEditorOptions;
875
876
/**
877
* Gets a specific editor option.
878
*/
879
getOption<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;
880
881
/**
882
* Returns the editor's configuration (without any validation or defaults).
883
*/
884
getRawOptions(): IEditorOptions;
885
886
/**
887
* @internal
888
*/
889
getOverflowWidgetsDomNode(): HTMLElement | undefined;
890
891
/**
892
* @internal
893
*/
894
getConfiguredWordAtPosition(position: Position): IWordAtPosition | null;
895
896
/**
897
* An event emitted when line heights from decorations change
898
* @internal
899
* @event
900
*/
901
onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;
902
903
/**
904
* An event emitted when the font of the editor has changed.
905
* @internal
906
* @event
907
*/
908
onDidChangeFont: Event<ModelFontChangedEvent>;
909
910
/**
911
* Get value of the current model attached to this editor.
912
* @see {@link ITextModel.getValue}
913
*/
914
getValue(options?: { preserveBOM: boolean; lineEnding: string }): string;
915
916
/**
917
* Set the value of the current model attached to this editor.
918
* @see {@link ITextModel.setValue}
919
*/
920
setValue(newValue: string): void;
921
922
/**
923
* Get the width of the editor's content.
924
* This is information that is "erased" when computing `scrollWidth = Math.max(contentWidth, width)`
925
*/
926
getContentWidth(): number;
927
/**
928
* Get the scrollWidth of the editor's viewport.
929
*/
930
getScrollWidth(): number;
931
/**
932
* Get the scrollLeft of the editor's viewport.
933
*/
934
getScrollLeft(): number;
935
936
/**
937
* Get the height of the editor's content.
938
* This is information that is "erased" when computing `scrollHeight = Math.max(contentHeight, height)`
939
*/
940
getContentHeight(): number;
941
/**
942
* Get the scrollHeight of the editor's viewport.
943
*/
944
getScrollHeight(): number;
945
/**
946
* Get the scrollTop of the editor's viewport.
947
*/
948
getScrollTop(): number;
949
950
/**
951
* Change the scrollLeft of the editor's viewport.
952
*/
953
setScrollLeft(newScrollLeft: number, scrollType?: editorCommon.ScrollType): void;
954
/**
955
* Change the scrollTop of the editor's viewport.
956
*/
957
setScrollTop(newScrollTop: number, scrollType?: editorCommon.ScrollType): void;
958
/**
959
* Change the scroll position of the editor's viewport.
960
*/
961
setScrollPosition(position: editorCommon.INewScrollPosition, scrollType?: editorCommon.ScrollType): void;
962
/**
963
* Check if the editor is currently scrolling towards a different scroll position.
964
*/
965
hasPendingScrollAnimation(): boolean;
966
967
/**
968
* Get an action that is a contribution to this editor.
969
* @id Unique identifier of the contribution.
970
* @return The action or null if action not found.
971
*/
972
getAction(id: string): editorCommon.IEditorAction | null;
973
974
/**
975
* Execute a command on the editor.
976
* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.
977
* @param source The source of the call.
978
* @param command The command to execute
979
*/
980
executeCommand(source: string | null | undefined, command: editorCommon.ICommand): void;
981
982
/**
983
* Create an "undo stop" in the undo-redo stack.
984
*/
985
pushUndoStop(): boolean;
986
987
/**
988
* Remove the "undo stop" in the undo-redo stack.
989
*/
990
popUndoStop(): boolean;
991
992
/**
993
* Execute edits on the editor.
994
* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.
995
* @param source The source of the call.
996
* @param edits The edits to execute.
997
* @param endCursorState Cursor state after the edits were applied.
998
*/
999
executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;
1000
/** @internal */
1001
executeEdits(source: TextModelEditSource | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;
1002
1003
/**
1004
* @internal
1005
*/
1006
edit(edit: TextEdit, reason: TextModelEditSource): void;
1007
1008
/**
1009
* Execute multiple (concomitant) commands on the editor.
1010
* @param source The source of the call.
1011
* @param command The commands to execute
1012
*/
1013
executeCommands(source: string | null | undefined, commands: (editorCommon.ICommand | null)[]): void;
1014
1015
/**
1016
* @internal
1017
*/
1018
_getViewModel(): IViewModel | null;
1019
1020
/**
1021
* Get all the decorations on a line (filtering out decorations from other editors).
1022
*/
1023
getLineDecorations(lineNumber: number): IModelDecoration[] | null;
1024
1025
/**
1026
* Get all the decorations for a range (filtering out decorations from other editors).
1027
*/
1028
getDecorationsInRange(range: Range): IModelDecoration[] | null;
1029
1030
/**
1031
* Get the font size at a given position
1032
* @param position the position for which to fetch the font size
1033
*/
1034
getFontSizeAtPosition(position: IPosition): string | null;
1035
1036
/**
1037
* All decorations added through this call will get the ownerId of this editor.
1038
* @deprecated Use `createDecorationsCollection`
1039
* @see createDecorationsCollection
1040
*/
1041
deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];
1042
1043
/**
1044
* Remove previously added decorations.
1045
*/
1046
removeDecorations(decorationIds: string[]): void;
1047
1048
/**
1049
* @internal
1050
*/
1051
setDecorationsByType(description: string, decorationTypeKey: string, ranges: editorCommon.IDecorationOptions[]): readonly string[];
1052
1053
/**
1054
* @internal
1055
*/
1056
setDecorationsByTypeFast(decorationTypeKey: string, ranges: IRange[]): void;
1057
1058
/**
1059
* @internal
1060
*/
1061
removeDecorationsByType(decorationTypeKey: string): void;
1062
1063
/**
1064
* Get the layout info for the editor.
1065
*/
1066
getLayoutInfo(): EditorLayoutInfo;
1067
1068
/**
1069
* Returns the ranges that are currently visible.
1070
* Does not account for horizontal scrolling.
1071
*/
1072
getVisibleRanges(): Range[];
1073
1074
/**
1075
* @internal
1076
*/
1077
getVisibleRangesPlusViewportAboveBelow(): Range[];
1078
1079
/**
1080
* Get the view zones.
1081
* @internal
1082
*/
1083
getWhitespaces(): IEditorWhitespace[];
1084
1085
/**
1086
* Get the vertical position (top offset) for the line's top w.r.t. to the first line.
1087
*/
1088
getTopForLineNumber(lineNumber: number, includeViewZones?: boolean): number;
1089
1090
/**
1091
* Get the vertical position (top offset) for the line's bottom w.r.t. to the first line.
1092
*/
1093
getBottomForLineNumber(lineNumber: number): number;
1094
1095
/**
1096
* Get the vertical position (top offset) for the position w.r.t. to the first line.
1097
*/
1098
getTopForPosition(lineNumber: number, column: number): number;
1099
1100
/**
1101
* Get the line height for a model position.
1102
*/
1103
getLineHeightForPosition(position: IPosition): number;
1104
1105
/**
1106
* Set the model ranges that will be hidden in the view.
1107
* Hidden areas are stored per source.
1108
* @internal
1109
*/
1110
setHiddenAreas(ranges: IRange[], source?: unknown): void;
1111
1112
/**
1113
* Sets the editor aria options, primarily the active descendent.
1114
* @internal
1115
*/
1116
setAriaOptions(options: IEditorAriaOptions): void;
1117
1118
/**
1119
* Write the screen reader content to be the current selection
1120
*/
1121
writeScreenReaderContent(reason: string): void;
1122
1123
/**
1124
* @internal
1125
*/
1126
getTelemetryData(): { [key: string]: any } | undefined;
1127
1128
/**
1129
* Returns the editor's container dom node
1130
*/
1131
getContainerDomNode(): HTMLElement;
1132
1133
/**
1134
* Returns the editor's dom node
1135
*/
1136
getDomNode(): HTMLElement | null;
1137
1138
/**
1139
* Add a content widget. Widgets must have unique ids, otherwise they will be overwritten.
1140
*/
1141
addContentWidget(widget: IContentWidget): void;
1142
/**
1143
* Layout/Reposition a content widget. This is a ping to the editor to call widget.getPosition()
1144
* and update appropriately.
1145
*/
1146
layoutContentWidget(widget: IContentWidget): void;
1147
/**
1148
* Remove a content widget.
1149
*/
1150
removeContentWidget(widget: IContentWidget): void;
1151
1152
/**
1153
* Add an overlay widget. Widgets must have unique ids, otherwise they will be overwritten.
1154
*/
1155
addOverlayWidget(widget: IOverlayWidget): void;
1156
/**
1157
* Layout/Reposition an overlay widget. This is a ping to the editor to call widget.getPosition()
1158
* and update appropriately.
1159
*/
1160
layoutOverlayWidget(widget: IOverlayWidget): void;
1161
/**
1162
* Remove an overlay widget.
1163
*/
1164
removeOverlayWidget(widget: IOverlayWidget): void;
1165
1166
/**
1167
* Add a glyph margin widget. Widgets must have unique ids, otherwise they will be overwritten.
1168
*/
1169
addGlyphMarginWidget(widget: IGlyphMarginWidget): void;
1170
/**
1171
* Layout/Reposition a glyph margin widget. This is a ping to the editor to call widget.getPosition()
1172
* and update appropriately.
1173
*/
1174
layoutGlyphMarginWidget(widget: IGlyphMarginWidget): void;
1175
/**
1176
* Remove a glyph margin widget.
1177
*/
1178
removeGlyphMarginWidget(widget: IGlyphMarginWidget): void;
1179
1180
/**
1181
* Change the view zones. View zones are lost when a new model is attached to the editor.
1182
*/
1183
changeViewZones(callback: (accessor: IViewZoneChangeAccessor) => void): void;
1184
1185
/**
1186
* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.
1187
* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).
1188
* Use this method with caution.
1189
*/
1190
getOffsetForColumn(lineNumber: number, column: number): number;
1191
1192
/**
1193
* Force an editor render now.
1194
*/
1195
render(forceRedraw?: boolean): void;
1196
1197
/**
1198
* Get the hit test target at coordinates `clientX` and `clientY`.
1199
* The coordinates are relative to the top-left of the viewport.
1200
*
1201
* @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model.
1202
*/
1203
getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget | null;
1204
1205
/**
1206
* Get the visible position for `position`.
1207
* The result position takes scrolling into account and is relative to the top left corner of the editor.
1208
* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.
1209
* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.
1210
* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.
1211
*/
1212
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number } | null;
1213
1214
/**
1215
* Apply the same font settings as the editor to `target`.
1216
*/
1217
applyFontInfo(target: HTMLElement): void;
1218
1219
/**
1220
* Check if the current instance has a model attached.
1221
* @internal
1222
*/
1223
hasModel(): this is IActiveCodeEditor;
1224
1225
setBanner(bannerDomNode: HTMLElement | null, height: number): void;
1226
1227
/**
1228
* Is called when the model has been set, view state was restored and options are updated.
1229
* This is the best place to compute data for the viewport (such as tokens).
1230
*/
1231
handleInitialized?(): void;
1232
}
1233
1234
/**
1235
* @internal
1236
*/
1237
export interface IActiveCodeEditor extends ICodeEditor {
1238
/**
1239
* Returns the primary position of the cursor.
1240
*/
1241
getPosition(): Position;
1242
1243
/**
1244
* Returns the primary selection of the editor.
1245
*/
1246
getSelection(): Selection;
1247
1248
/**
1249
* Returns all the selections of the editor.
1250
*/
1251
getSelections(): Selection[];
1252
1253
/**
1254
* Saves current view state of the editor in a serializable object.
1255
*/
1256
saveViewState(): editorCommon.ICodeEditorViewState;
1257
1258
/**
1259
* Type the getModel() of IEditor.
1260
*/
1261
getModel(): ITextModel;
1262
1263
/**
1264
* @internal
1265
*/
1266
_getViewModel(): IViewModel;
1267
1268
/**
1269
* Get all the decorations on a line (filtering out decorations from other editors).
1270
*/
1271
getLineDecorations(lineNumber: number): IModelDecoration[];
1272
1273
/**
1274
* Returns the editor's dom node
1275
*/
1276
getDomNode(): HTMLElement;
1277
1278
/**
1279
* Get the visible position for `position`.
1280
* The result position takes scrolling into account and is relative to the top left corner of the editor.
1281
* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.
1282
* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.
1283
* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.
1284
*/
1285
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number };
1286
}
1287
1288
/**
1289
* @internal
1290
*/
1291
export const enum DiffEditorState {
1292
Idle,
1293
ComputingDiff,
1294
DiffComputed
1295
}
1296
1297
/**
1298
* A rich diff editor.
1299
*/
1300
export interface IDiffEditor extends editorCommon.IEditor {
1301
1302
/**
1303
* Returns whether the diff editor is ignoring trim whitespace or not.
1304
* @internal
1305
*/
1306
readonly ignoreTrimWhitespace: boolean;
1307
/**
1308
* Returns whether the diff editor is rendering side by side or inline.
1309
* @internal
1310
*/
1311
readonly renderSideBySide: boolean;
1312
/**
1313
* Timeout in milliseconds after which diff computation is cancelled.
1314
* @internal
1315
*/
1316
readonly maxComputationTime: number;
1317
1318
/**
1319
* @see {@link ICodeEditor.getContainerDomNode}
1320
*/
1321
getContainerDomNode(): HTMLElement;
1322
1323
/**
1324
* An event emitted when the diff information computed by this diff editor has been updated.
1325
* @event
1326
*/
1327
readonly onDidUpdateDiff: Event<void>;
1328
1329
/**
1330
* An event emitted when the diff model is changed (i.e. the diff editor shows new content).
1331
* @event
1332
*/
1333
readonly onDidChangeModel: Event<void>;
1334
1335
/**
1336
* Saves current view state of the editor in a serializable object.
1337
*/
1338
saveViewState(): editorCommon.IDiffEditorViewState | null;
1339
1340
/**
1341
* Restores the view state of the editor from a serializable object generated by `saveViewState`.
1342
*/
1343
restoreViewState(state: editorCommon.IDiffEditorViewState | null): void;
1344
1345
/**
1346
* Type the getModel() of IEditor.
1347
*/
1348
getModel(): editorCommon.IDiffEditorModel | null;
1349
1350
createViewModel(model: editorCommon.IDiffEditorModel): editorCommon.IDiffEditorViewModel;
1351
1352
/**
1353
* Sets the current model attached to this editor.
1354
* If the previous model was created by the editor via the value key in the options
1355
* literal object, it will be destroyed. Otherwise, if the previous model was set
1356
* via setModel, or the model key in the options literal object, the previous model
1357
* will not be destroyed.
1358
* It is safe to call setModel(null) to simply detach the current model from the editor.
1359
*/
1360
setModel(model: editorCommon.IDiffEditorModel | editorCommon.IDiffEditorViewModel | null): void;
1361
1362
/**
1363
* Get the `original` editor.
1364
*/
1365
getOriginalEditor(): ICodeEditor;
1366
1367
/**
1368
* Get the `modified` editor.
1369
*/
1370
getModifiedEditor(): ICodeEditor;
1371
1372
/**
1373
* Get the computed diff information.
1374
*/
1375
getLineChanges(): ILineChange[] | null;
1376
1377
/**
1378
* Get the computed diff information.
1379
* @internal
1380
*/
1381
getDiffComputationResult(): IDiffComputationResult | null;
1382
1383
/**
1384
* Update the editor's options after the editor has been created.
1385
*/
1386
updateOptions(newOptions: IDiffEditorOptions): void;
1387
1388
/**
1389
* @internal
1390
*/
1391
setBoundarySashes(sashes: IBoundarySashes): void;
1392
1393
/**
1394
* Jumps to the next or previous diff.
1395
*/
1396
goToDiff(target: 'next' | 'previous'): void;
1397
1398
/**
1399
* Scrolls to the first diff.
1400
* (Waits until the diff computation finished.)
1401
*/
1402
revealFirstDiff(): unknown;
1403
1404
accessibleDiffViewerNext(): void;
1405
1406
accessibleDiffViewerPrev(): void;
1407
1408
handleInitialized(): void;
1409
}
1410
1411
/**
1412
*@internal
1413
*/
1414
export function isCodeEditor(thing: unknown): thing is ICodeEditor {
1415
if (thing && typeof (<ICodeEditor>thing).getEditorType === 'function') {
1416
return (<ICodeEditor>thing).getEditorType() === editorCommon.EditorType.ICodeEditor;
1417
} else {
1418
return false;
1419
}
1420
}
1421
1422
/**
1423
*@internal
1424
*/
1425
export function isDiffEditor(thing: unknown): thing is IDiffEditor {
1426
if (thing && typeof (<IDiffEditor>thing).getEditorType === 'function') {
1427
return (<IDiffEditor>thing).getEditorType() === editorCommon.EditorType.IDiffEditor;
1428
} else {
1429
return false;
1430
}
1431
}
1432
1433
/**
1434
*@internal
1435
*/
1436
export function isCompositeEditor(thing: unknown): thing is editorCommon.ICompositeCodeEditor {
1437
return !!thing
1438
&& typeof thing === 'object'
1439
&& typeof (<editorCommon.ICompositeCodeEditor>thing).onDidChangeActiveEditor === 'function';
1440
1441
}
1442
1443
/**
1444
*@internal
1445
*/
1446
export function getCodeEditor(thing: unknown): ICodeEditor | null {
1447
if (isCodeEditor(thing)) {
1448
return thing;
1449
}
1450
1451
if (isDiffEditor(thing)) {
1452
return thing.getModifiedEditor();
1453
}
1454
1455
if (isCompositeEditor(thing) && isCodeEditor(thing.activeCodeEditor)) {
1456
return thing.activeCodeEditor;
1457
}
1458
1459
return null;
1460
}
1461
1462
/**
1463
*@internal
1464
*/
1465
export function getIEditor(thing: any): editorCommon.IEditor | null {
1466
if (isCodeEditor(thing) || isDiffEditor(thing)) {
1467
return thing;
1468
}
1469
1470
return null;
1471
}
1472
1473