-
Notifications
You must be signed in to change notification settings - Fork 30.2k
/
Copy patheditorCommon.ts
781 lines (681 loc) · 20.9 KB
/
editorCommon.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from '../../base/common/event.js';
import { IMarkdownString } from '../../base/common/htmlContent.js';
import { IDisposable } from '../../base/common/lifecycle.js';
import { ThemeColor } from '../../base/common/themables.js';
import { URI, UriComponents } from '../../base/common/uri.js';
import { IEditorOptions } from './config/editorOptions.js';
import { IDimension } from './core/dimension.js';
import { IPosition, Position } from './core/position.js';
import { IRange, Range } from './core/range.js';
import { ISelection, Selection } from './core/selection.js';
import { IModelDecoration, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel, IValidEditOperation, OverviewRulerLane, TrackedRangeStickiness } from './model.js';
import { IModelDecorationsChangedEvent } from './textModelEvents.js';
import { ICommandMetadata } from '../../platform/commands/common/commands.js';
/**
* A builder and helper for edit operations for a command.
*/
export interface IEditOperationBuilder {
/**
* Add a new edit operation (a replace operation).
* @param range The range to replace (delete). May be empty to represent a simple insert.
* @param text The text to replace with. May be null to represent a simple delete.
*/
addEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;
/**
* Add a new edit operation (a replace operation).
* The inverse edits will be accessible in `ICursorStateComputerData.getInverseEditOperations()`
* @param range The range to replace (delete). May be empty to represent a simple insert.
* @param text The text to replace with. May be null to represent a simple delete.
*/
addTrackedEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;
/**
* Track `selection` when applying edit operations.
* A best effort will be made to not grow/expand the selection.
* An empty selection will clamp to a nearby character.
* @param selection The selection to track.
* @param trackPreviousOnEmpty If set, and the selection is empty, indicates whether the selection
* should clamp to the previous or the next character.
* @return A unique identifier.
*/
trackSelection(selection: Selection, trackPreviousOnEmpty?: boolean): string;
}
/**
* A helper for computing cursor state after a command.
*/
export interface ICursorStateComputerData {
/**
* Get the inverse edit operations of the added edit operations.
*/
getInverseEditOperations(): IValidEditOperation[];
/**
* Get a previously tracked selection.
* @param id The unique identifier returned by `trackSelection`.
* @return The selection.
*/
getTrackedSelection(id: string): Selection;
}
/**
* A command that modifies text / cursor state on a model.
*/
export interface ICommand {
/**
* Signal that this command is inserting automatic whitespace that should be trimmed if possible.
* @internal
*/
readonly insertsAutoWhitespace?: boolean;
/**
* Get the edit operations needed to execute this command.
* @param model The model the command will execute on.
* @param builder A helper to collect the needed edit operations and to track selections.
*/
getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void;
/**
* Compute the cursor state after the edit operations were applied.
* @param model The model the command has executed on.
* @param helper A helper to get inverse edit operations and to get previously tracked selections.
* @return The cursor state after the command executed.
*/
computeCursorState(model: ITextModel, helper: ICursorStateComputerData): Selection;
}
/**
* A model for the diff editor.
*/
export interface IDiffEditorModel {
/**
* Original model.
*/
original: ITextModel;
/**
* Modified model.
*/
modified: ITextModel;
}
export interface IDiffEditorViewModel extends IDisposable {
readonly model: IDiffEditorModel;
waitForDiff(): Promise<void>;
}
/**
* An event describing that an editor has had its model reset (i.e. `editor.setModel()`).
*/
export interface IModelChangedEvent {
/**
* The `uri` of the previous model or null.
*/
readonly oldModelUrl: URI | null;
/**
* The `uri` of the new model or null.
*/
readonly newModelUrl: URI | null;
}
// --- view
export interface IScrollEvent {
readonly scrollTop: number;
readonly scrollLeft: number;
readonly scrollWidth: number;
readonly scrollHeight: number;
readonly scrollTopChanged: boolean;
readonly scrollLeftChanged: boolean;
readonly scrollWidthChanged: boolean;
readonly scrollHeightChanged: boolean;
}
export interface IContentSizeChangedEvent {
readonly contentWidth: number;
readonly contentHeight: number;
readonly contentWidthChanged: boolean;
readonly contentHeightChanged: boolean;
}
/**
* @internal
*/
export interface ITriggerEditorOperationEvent {
source: string | null | undefined;
handlerId: string;
payload: any;
}
export interface INewScrollPosition {
scrollLeft?: number;
scrollTop?: number;
}
export interface IEditorAction {
readonly id: string;
readonly label: string;
readonly alias: string;
readonly metadata: ICommandMetadata | undefined;
isSupported(): boolean;
run(args?: unknown): Promise<void>;
}
export type IEditorModel = ITextModel | IDiffEditorModel | IDiffEditorViewModel;
/**
* A (serializable) state of the cursors.
*/
export interface ICursorState {
inSelectionMode: boolean;
selectionStart: IPosition;
position: IPosition;
}
/**
* A (serializable) state of the view.
*/
export interface IViewState {
/** written by previous versions */
scrollTop?: number;
/** written by previous versions */
scrollTopWithoutViewZones?: number;
scrollLeft: number;
firstPosition: IPosition;
firstPositionDeltaTop: number;
}
/**
* A (serializable) state of the code editor.
*/
export interface ICodeEditorViewState {
cursorState: ICursorState[];
viewState: IViewState;
contributionsState: { [id: string]: any };
}
/**
* (Serializable) View state for the diff editor.
*/
export interface IDiffEditorViewState {
original: ICodeEditorViewState | null;
modified: ICodeEditorViewState | null;
modelState?: unknown;
}
/**
* An editor view state.
*/
export type IEditorViewState = ICodeEditorViewState | IDiffEditorViewState;
export const enum ScrollType {
Smooth = 0,
Immediate = 1,
}
/**
* An editor.
*/
export interface IEditor {
/**
* An event emitted when the editor has been disposed.
* @event
*/
onDidDispose(listener: () => void): IDisposable;
/**
* Dispose the editor.
*/
dispose(): void;
/**
* Get a unique id for this editor instance.
*/
getId(): string;
/**
* Get the editor type. Please see `EditorType`.
* This is to avoid an instanceof check
*/
getEditorType(): string;
/**
* Update the editor's options after the editor has been created.
*/
updateOptions(newOptions: IEditorOptions): void;
/**
* Indicates that the editor becomes visible.
* @internal
*/
onVisible(): void;
/**
* Indicates that the editor becomes hidden.
* @internal
*/
onHide(): void;
/**
* Instructs the editor to remeasure its container. This method should
* be called when the container of the editor gets resized.
*
* If a dimension is passed in, the passed in value will be used.
*
* By default, this will also render the editor immediately.
* If you prefer to delay rendering to the next animation frame, use postponeRendering == true.
*/
layout(dimension?: IDimension, postponeRendering?: boolean): void;
/**
* Brings browser focus to the editor text
*/
focus(): void;
/**
* Returns true if the text inside this editor is focused (i.e. cursor is blinking).
*/
hasTextFocus(): boolean;
/**
* Returns all actions associated with this editor.
*/
getSupportedActions(): IEditorAction[];
/**
* Saves current view state of the editor in a serializable object.
*/
saveViewState(): IEditorViewState | null;
/**
* Restores the view state of the editor from a serializable object generated by `saveViewState`.
*/
restoreViewState(state: IEditorViewState | null): void;
/**
* Given a position, returns a column number that takes tab-widths into account.
*/
getVisibleColumnFromPosition(position: IPosition): number;
/**
* Given a position, returns a column number that takes tab-widths into account.
* @internal
*/
getStatusbarColumn(position: IPosition): number;
/**
* Returns the primary position of the cursor.
*/
getPosition(): Position | null;
/**
* Set the primary position of the cursor. This will remove any secondary cursors.
* @param position New primary cursor's position
* @param source Source of the call that caused the position
*/
setPosition(position: IPosition, source?: string): void;
/**
* Scroll vertically as necessary and reveal a line.
*/
revealLine(lineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal a line centered vertically.
*/
revealLineInCenter(lineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport.
*/
revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal a line close to the top of the viewport,
* optimized for viewing a code definition.
*/
revealLineNearTop(lineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a position.
*/
revealPosition(position: IPosition, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a position centered vertically.
*/
revealPositionInCenter(position: IPosition, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a position centered vertically only if it lies outside the viewport.
*/
revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a position close to the top of the viewport,
* optimized for viewing a code definition.
*/
revealPositionNearTop(position: IPosition, scrollType?: ScrollType): void;
/**
* Returns the primary selection of the editor.
*/
getSelection(): Selection | null;
/**
* Returns all the selections of the editor.
*/
getSelections(): Selection[] | null;
/**
* Set the primary selection of the editor. This will remove any secondary cursors.
* @param selection The new selection
* @param source Source of the call that caused the selection
*/
setSelection(selection: IRange, source?: string): void;
/**
* Set the primary selection of the editor. This will remove any secondary cursors.
* @param selection The new selection
* @param source Source of the call that caused the selection
*/
setSelection(selection: Range, source?: string): void;
/**
* Set the primary selection of the editor. This will remove any secondary cursors.
* @param selection The new selection
* @param source Source of the call that caused the selection
*/
setSelection(selection: ISelection, source?: string): void;
/**
* Set the primary selection of the editor. This will remove any secondary cursors.
* @param selection The new selection
* @param source Source of the call that caused the selection
*/
setSelection(selection: Selection, source?: string): void;
/**
* Set the selections for all the cursors of the editor.
* Cursors will be removed or added, as necessary.
* @param selections The new selection
* @param source Source of the call that caused the selection
*/
setSelections(selections: readonly ISelection[], source?: string): void;
/**
* Scroll vertically as necessary and reveal lines.
*/
revealLines(startLineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal lines centered vertically.
*/
revealLinesInCenter(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal lines centered vertically only if it lies outside the viewport.
*/
revealLinesInCenterIfOutsideViewport(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically as necessary and reveal lines close to the top of the viewport,
* optimized for viewing a code definition.
*/
revealLinesNearTop(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range.
*/
revealRange(range: IRange, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range centered vertically.
*/
revealRangeInCenter(range: IRange, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range at the top of the viewport.
*/
revealRangeAtTop(range: IRange, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
*/
revealRangeInCenterIfOutsideViewport(range: IRange, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,
* optimized for viewing a code definition.
*/
revealRangeNearTop(range: IRange, scrollType?: ScrollType): void;
/**
* Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,
* optimized for viewing a code definition. Only if it lies outside the viewport.
*/
revealRangeNearTopIfOutsideViewport(range: IRange, scrollType?: ScrollType): void;
/**
* Directly trigger a handler or an editor action.
* @param source The source of the call.
* @param handlerId The id of the handler or the id of a contribution.
* @param payload Extra data to be sent to the handler.
*/
trigger(source: string | null | undefined, handlerId: string, payload: any): void;
/**
* Gets the current model attached to this editor.
*/
getModel(): IEditorModel | null;
/**
* Sets the current model attached to this editor.
* If the previous model was created by the editor via the value key in the options
* literal object, it will be destroyed. Otherwise, if the previous model was set
* via setModel, or the model key in the options literal object, the previous model
* will not be destroyed.
* It is safe to call setModel(null) to simply detach the current model from the editor.
*/
setModel(model: IEditorModel | null): void;
/**
* Create a collection of decorations. All decorations added through this collection
* will get the ownerId of the editor (meaning they will not show up in other editors).
* These decorations will be automatically cleared when the editor's model changes.
*/
createDecorationsCollection(decorations?: IModelDeltaDecoration[]): IEditorDecorationsCollection;
/**
* Change the decorations. All decorations added through this changeAccessor
* will get the ownerId of the editor (meaning they will not show up in other
* editors).
* @see {@link ITextModel.changeDecorations}
* @internal
*/
changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
}
/**
* A diff editor.
*
* @internal
*/
export interface IDiffEditor extends IEditor {
/**
* Type the getModel() of IEditor.
*/
getModel(): IDiffEditorModel | null;
/**
* Get the `original` editor.
*/
getOriginalEditor(): IEditor;
/**
* Get the `modified` editor.
*/
getModifiedEditor(): IEditor;
}
/**
* @internal
*/
export interface ICompositeCodeEditor {
/**
* An event that signals that the active editor has changed
*/
readonly onDidChangeActiveEditor: Event<ICompositeCodeEditor>;
/**
* The active code editor iff any
*/
readonly activeCodeEditor: IEditor | undefined;
// readonly editors: readonly ICodeEditor[] maybe supported with uris
}
/**
* A collection of decorations
*/
export interface IEditorDecorationsCollection {
/**
* An event emitted when decorations change in the editor,
* but the change is not caused by us setting or clearing the collection.
*/
onDidChange: Event<IModelDecorationsChangedEvent>;
/**
* Get the decorations count.
*/
length: number;
/**
* Get the range for a decoration.
*/
getRange(index: number): Range | null;
/**
* Get all ranges for decorations.
*/
getRanges(): Range[];
/**
* Determine if a decoration is in this collection.
*/
has(decoration: IModelDecoration): boolean;
/**
* Replace all previous decorations with `newDecorations`.
*/
set(newDecorations: readonly IModelDeltaDecoration[]): string[];
/**
* Append `newDecorations` to this collection.
*/
append(newDecorations: readonly IModelDeltaDecoration[]): string[];
/**
* Remove all previous decorations.
*/
clear(): void;
}
/**
* An editor contribution that gets created every time a new editor gets created and gets disposed when the editor gets disposed.
*/
export interface IEditorContribution {
/**
* Dispose this contribution.
*/
dispose(): void;
/**
* Store view state.
*/
saveViewState?(): any;
/**
* Restore view state.
*/
restoreViewState?(state: any): void;
}
/**
* A diff editor contribution that gets created every time a new diffeditor gets created and gets disposed when the diff editor gets disposed.
* @internal
*/
export interface IDiffEditorContribution {
/**
* Dispose this contribution.
*/
dispose(): void;
}
/**
* @internal
*/
export function isThemeColor(o: any): o is ThemeColor {
return o && typeof o.id === 'string';
}
/**
* @internal
*/
export interface IThemeDecorationRenderOptions {
backgroundColor?: string | ThemeColor;
outline?: string;
outlineColor?: string | ThemeColor;
outlineStyle?: string;
outlineWidth?: string;
border?: string;
borderColor?: string | ThemeColor;
borderRadius?: string;
borderSpacing?: string;
borderStyle?: string;
borderWidth?: string;
fontStyle?: string;
fontWeight?: string;
fontSize?: string;
textDecoration?: string;
cursor?: string;
color?: string | ThemeColor;
opacity?: string;
letterSpacing?: string;
gutterIconPath?: UriComponents;
gutterIconSize?: string;
overviewRulerColor?: string | ThemeColor;
/**
* @deprecated
*/
before?: IContentDecorationRenderOptions;
/**
* @deprecated
*/
after?: IContentDecorationRenderOptions;
/**
* @deprecated
*/
beforeInjectedText?: IContentDecorationRenderOptions & { affectsLetterSpacing?: boolean };
/**
* @deprecated
*/
afterInjectedText?: IContentDecorationRenderOptions & { affectsLetterSpacing?: boolean };
}
/**
* @internal
*/
export interface IContentDecorationRenderOptions {
contentText?: string;
contentIconPath?: UriComponents;
border?: string;
borderColor?: string | ThemeColor;
borderRadius?: string;
fontStyle?: string;
fontWeight?: string;
fontSize?: string;
fontFamily?: string;
textDecoration?: string;
color?: string | ThemeColor;
backgroundColor?: string | ThemeColor;
opacity?: string;
verticalAlign?: string;
margin?: string;
padding?: string;
width?: string;
height?: string;
}
/**
* @internal
*/
export interface IDecorationRenderOptions extends IThemeDecorationRenderOptions {
isWholeLine?: boolean;
rangeBehavior?: TrackedRangeStickiness;
overviewRulerLane?: OverviewRulerLane;
light?: IThemeDecorationRenderOptions;
dark?: IThemeDecorationRenderOptions;
}
/**
* @internal
*/
export interface IThemeDecorationInstanceRenderOptions {
/**
* @deprecated
*/
before?: IContentDecorationRenderOptions;
/**
* @deprecated
*/
after?: IContentDecorationRenderOptions;
}
/**
* @internal
*/
export interface IDecorationInstanceRenderOptions extends IThemeDecorationInstanceRenderOptions {
light?: IThemeDecorationInstanceRenderOptions;
dark?: IThemeDecorationInstanceRenderOptions;
}
/**
* @internal
*/
export interface IDecorationOptions {
range: IRange;
hoverMessage?: IMarkdownString | IMarkdownString[];
renderOptions?: IDecorationInstanceRenderOptions;
}
/**
* The type of the `IEditor`.
*/
export const EditorType = {
ICodeEditor: 'vs.editor.ICodeEditor',
IDiffEditor: 'vs.editor.IDiffEditor'
};
/**
* Built-in commands.
* @internal
*/
export const enum Handler {
CompositionStart = 'compositionStart',
CompositionEnd = 'compositionEnd',
Type = 'type',
ReplacePreviousChar = 'replacePreviousChar',
CompositionType = 'compositionType',
Paste = 'paste',
Cut = 'cut',
}
/**
* @internal
*/
export interface TypePayload {
text: string;
}
/**
* @internal
*/
export interface ReplacePreviousCharPayload {
text: string;
replaceCharCnt: number;
}
/**
* @internal
*/
export interface CompositionTypePayload {
text: string;
replacePrevCharCnt: number;
replaceNextCharCnt: number;
positionDelta: number;
}