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