Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/model.ts
5240 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 { Event } from '../../base/common/event.js';
7
import { IMarkdownString } from '../../base/common/htmlContent.js';
8
import { IDisposable } from '../../base/common/lifecycle.js';
9
import { equals } from '../../base/common/objects.js';
10
import { ThemeColor } from '../../base/common/themables.js';
11
import { URI } from '../../base/common/uri.js';
12
import { ISingleEditOperation } from './core/editOperation.js';
13
import { IPosition, Position } from './core/position.js';
14
import { IRange, Range } from './core/range.js';
15
import { Selection } from './core/selection.js';
16
import { TextChange } from './core/textChange.js';
17
import { WordCharacterClassifier } from './core/wordCharacterClassifier.js';
18
import { IWordAtPosition } from './core/wordHelper.js';
19
import { FormattingOptions } from './languages.js';
20
import { ILanguageSelection } from './languages/language.js';
21
import { IBracketPairsTextModelPart } from './textModelBracketPairs.js';
22
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelFontChangedEvent, ModelLineHeightChangedEvent } from './textModelEvents.js';
23
import { IModelContentChange } from './model/mirrorTextModel.js';
24
import { IGuidesTextModelPart } from './textModelGuides.js';
25
import { ITokenizationTextModelPart } from './tokenizationTextModelPart.js';
26
import { UndoRedoGroup } from '../../platform/undoRedo/common/undoRedo.js';
27
import { TokenArray } from './tokens/lineTokens.js';
28
import { IEditorModel } from './editorCommon.js';
29
import { TextModelEditSource } from './textModelEditSource.js';
30
import { TextEdit } from './core/edits/textEdit.js';
31
import { IViewModel } from './viewModel.js';
32
33
/**
34
* Vertical Lane in the overview ruler of the editor.
35
*/
36
export enum OverviewRulerLane {
37
Left = 1,
38
Center = 2,
39
Right = 4,
40
Full = 7
41
}
42
43
/**
44
* Vertical Lane in the glyph margin of the editor.
45
*/
46
export enum GlyphMarginLane {
47
Left = 1,
48
Center = 2,
49
Right = 3,
50
}
51
52
export interface IGlyphMarginLanesModel {
53
/**
54
* The number of lanes that should be rendered in the editor.
55
*/
56
readonly requiredLanes: number;
57
58
/**
59
* Gets the lanes that should be rendered starting at a given line number.
60
*/
61
getLanesAtLine(lineNumber: number): GlyphMarginLane[];
62
63
/**
64
* Resets the model and ensures it can contain at least `maxLine` lines.
65
*/
66
reset(maxLine: number): void;
67
68
/**
69
* Registers that a lane should be visible at the Range in the model.
70
* @param persist - if true, notes that the lane should always be visible,
71
* even on lines where there's no specific request for that lane.
72
*/
73
push(lane: GlyphMarginLane, range: Range, persist?: boolean): void;
74
}
75
76
/**
77
* Position in the minimap to render the decoration.
78
*/
79
export const enum MinimapPosition {
80
Inline = 1,
81
Gutter = 2
82
}
83
84
/**
85
* Section header style.
86
*/
87
export const enum MinimapSectionHeaderStyle {
88
Normal = 1,
89
Underlined = 2
90
}
91
92
export interface IDecorationOptions {
93
/**
94
* CSS color to render.
95
* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
96
*/
97
color: string | ThemeColor | undefined;
98
/**
99
* CSS color to render.
100
* e.g.: rgba(100, 100, 100, 0.5) or a color from the color registry
101
*/
102
darkColor?: string | ThemeColor;
103
}
104
105
export interface IModelDecorationGlyphMarginOptions {
106
/**
107
* The position in the glyph margin.
108
*/
109
position: GlyphMarginLane;
110
111
/**
112
* Whether the glyph margin lane in {@link position} should be rendered even
113
* outside of this decoration's range.
114
*/
115
persistLane?: boolean;
116
}
117
118
/**
119
* Options for rendering a model decoration in the overview ruler.
120
*/
121
export interface IModelDecorationOverviewRulerOptions extends IDecorationOptions {
122
/**
123
* The position in the overview ruler.
124
*/
125
position: OverviewRulerLane;
126
}
127
128
/**
129
* Options for rendering a model decoration in the minimap.
130
*/
131
export interface IModelDecorationMinimapOptions extends IDecorationOptions {
132
/**
133
* The position in the minimap.
134
*/
135
position: MinimapPosition;
136
/**
137
* If the decoration is for a section header, which header style.
138
*/
139
sectionHeaderStyle?: MinimapSectionHeaderStyle | null;
140
/**
141
* If the decoration is for a section header, the header text.
142
*/
143
sectionHeaderText?: string | null;
144
}
145
146
/**
147
* Options for a model decoration.
148
*/
149
export interface IModelDecorationOptions {
150
/**
151
* A debug description that can be used for inspecting model decorations.
152
* @internal
153
*/
154
description: string;
155
/**
156
* Customize the growing behavior of the decoration when typing at the edges of the decoration.
157
* Defaults to TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
158
*/
159
stickiness?: TrackedRangeStickiness;
160
/**
161
* CSS class name describing the decoration.
162
*/
163
className?: string | null;
164
/**
165
* Indicates whether the decoration should span across the entire line when it continues onto the next line.
166
*/
167
shouldFillLineOnLineBreak?: boolean | null;
168
blockClassName?: string | null;
169
/**
170
* Indicates if this block should be rendered after the last line.
171
* In this case, the range must be empty and set to the last line.
172
*/
173
blockIsAfterEnd?: boolean | null;
174
blockDoesNotCollapse?: boolean | null;
175
blockPadding?: [top: number, right: number, bottom: number, left: number] | null;
176
177
/**
178
* Message to be rendered when hovering over the glyph margin decoration.
179
*/
180
glyphMarginHoverMessage?: IMarkdownString | IMarkdownString[] | null;
181
/**
182
* Array of MarkdownString to render as the decoration message.
183
*/
184
hoverMessage?: IMarkdownString | IMarkdownString[] | null;
185
/**
186
* Array of MarkdownString to render as the line number message.
187
*/
188
lineNumberHoverMessage?: IMarkdownString | IMarkdownString[] | null;
189
/**
190
* Should the decoration expand to encompass a whole line.
191
*/
192
isWholeLine?: boolean;
193
/**
194
* Always render the decoration (even when the range it encompasses is collapsed).
195
*/
196
showIfCollapsed?: boolean;
197
/**
198
* Collapse the decoration if its entire range is being replaced via an edit.
199
* @internal
200
*/
201
collapseOnReplaceEdit?: boolean;
202
/**
203
* Specifies the stack order of a decoration.
204
* A decoration with greater stack order is always in front of a decoration with
205
* a lower stack order when the decorations are on the same line.
206
*/
207
zIndex?: number;
208
/**
209
* If set, render this decoration in the overview ruler.
210
*/
211
overviewRuler?: IModelDecorationOverviewRulerOptions | null;
212
/**
213
* If set, render this decoration in the minimap.
214
*/
215
minimap?: IModelDecorationMinimapOptions | null;
216
/**
217
* If set, the decoration will be rendered in the glyph margin with this CSS class name.
218
*/
219
glyphMarginClassName?: string | null;
220
/**
221
* If set and the decoration has {@link glyphMarginClassName} set, render this decoration
222
* with the specified {@link IModelDecorationGlyphMarginOptions} in the glyph margin.
223
*/
224
glyphMargin?: IModelDecorationGlyphMarginOptions | null;
225
/**
226
* If set, the decoration will override the line height of the lines it spans. This value is a multiplier to the default line height.
227
*/
228
lineHeight?: number | null;
229
/**
230
* Font family
231
*/
232
fontFamily?: string | null;
233
/**
234
* Font size
235
*/
236
fontSize?: string | null;
237
/**
238
* Font weight
239
*/
240
fontWeight?: string | null;
241
/**
242
* Font style
243
*/
244
fontStyle?: string | null;
245
/**
246
* If set, the decoration will be rendered in the lines decorations with this CSS class name.
247
*/
248
linesDecorationsClassName?: string | null;
249
/**
250
* Controls the tooltip text of the line decoration.
251
*/
252
linesDecorationsTooltip?: string | null;
253
/**
254
* If set, the decoration will be rendered on the line number.
255
*/
256
lineNumberClassName?: string | null;
257
/**
258
* If set, the decoration will be rendered in the lines decorations with this CSS class name, but only for the first line in case of line wrapping.
259
*/
260
firstLineDecorationClassName?: string | null;
261
/**
262
* If set, the decoration will be rendered in the margin (covering its full width) with this CSS class name.
263
*/
264
marginClassName?: string | null;
265
/**
266
* If set, the decoration will be rendered inline with the text with this CSS class name.
267
* Please use this only for CSS rules that must impact the text. For example, use `className`
268
* to have a background color decoration.
269
*/
270
inlineClassName?: string | null;
271
/**
272
* If there is an `inlineClassName` which affects letter spacing.
273
*/
274
inlineClassNameAffectsLetterSpacing?: boolean;
275
/**
276
* If set, the decoration will be rendered before the text with this CSS class name.
277
*/
278
beforeContentClassName?: string | null;
279
/**
280
* If set, the decoration will be rendered after the text with this CSS class name.
281
*/
282
afterContentClassName?: string | null;
283
/**
284
* If set, text will be injected in the view after the range.
285
*/
286
after?: InjectedTextOptions | null;
287
288
/**
289
* If set, text will be injected in the view before the range.
290
*/
291
before?: InjectedTextOptions | null;
292
293
/**
294
* If set, this decoration will not be rendered for comment tokens.
295
* @internal
296
*/
297
hideInCommentTokens?: boolean | null;
298
299
/**
300
* If set, this decoration will not be rendered for string tokens.
301
* @internal
302
*/
303
hideInStringTokens?: boolean | null;
304
305
/**
306
* Whether the decoration affects the font.
307
* @internal
308
*/
309
affectsFont?: boolean | null;
310
311
/**
312
* The text direction of the decoration.
313
*/
314
textDirection?: TextDirection | null;
315
}
316
317
/**
318
* Text Direction for a decoration.
319
*/
320
export enum TextDirection {
321
LTR = 0,
322
323
RTL = 1,
324
}
325
326
/**
327
* Configures text that is injected into the view without changing the underlying document.
328
*/
329
export interface InjectedTextOptions {
330
/**
331
* Sets the text to inject. Must be a single line.
332
*/
333
readonly content: string;
334
335
/**
336
* @internal
337
*/
338
readonly tokens?: TokenArray | null;
339
340
/**
341
* If set, the decoration will be rendered inline with the text with this CSS class name.
342
*/
343
readonly inlineClassName?: string | null;
344
345
/**
346
* If there is an `inlineClassName` which affects letter spacing.
347
*/
348
readonly inlineClassNameAffectsLetterSpacing?: boolean;
349
350
/**
351
* This field allows to attach data to this injected text.
352
* The data can be read when injected texts at a given position are queried.
353
*/
354
readonly attachedData?: unknown;
355
356
/**
357
* Configures cursor stops around injected text.
358
* Defaults to {@link InjectedTextCursorStops.Both}.
359
*/
360
readonly cursorStops?: InjectedTextCursorStops | null;
361
}
362
363
export enum InjectedTextCursorStops {
364
Both,
365
Right,
366
Left,
367
None
368
}
369
370
/**
371
* New model decorations.
372
*/
373
export interface IModelDeltaDecoration {
374
/**
375
* Range that this decoration covers.
376
*/
377
range: IRange;
378
/**
379
* Options associated with this decoration.
380
*/
381
options: IModelDecorationOptions;
382
}
383
384
/**
385
* A decoration in the model.
386
*/
387
export interface IModelDecoration {
388
/**
389
* Identifier for a decoration.
390
*/
391
readonly id: string;
392
/**
393
* Identifier for a decoration's owner.
394
*/
395
readonly ownerId: number;
396
/**
397
* Range that this decoration covers.
398
*/
399
readonly range: Range;
400
/**
401
* Options associated with this decoration.
402
*/
403
readonly options: IModelDecorationOptions;
404
}
405
406
/**
407
* An accessor that can add, change or remove model decorations.
408
* @internal
409
*/
410
export interface IModelDecorationsChangeAccessor {
411
/**
412
* Add a new decoration.
413
* @param range Range that this decoration covers.
414
* @param options Options associated with this decoration.
415
* @return An unique identifier associated with this decoration.
416
*/
417
addDecoration(range: IRange, options: IModelDecorationOptions): string;
418
/**
419
* Change the range that an existing decoration covers.
420
* @param id The unique identifier associated with the decoration.
421
* @param newRange The new range that this decoration covers.
422
*/
423
changeDecoration(id: string, newRange: IRange): void;
424
/**
425
* Change the options associated with an existing decoration.
426
* @param id The unique identifier associated with the decoration.
427
* @param newOptions The new options associated with this decoration.
428
*/
429
changeDecorationOptions(id: string, newOptions: IModelDecorationOptions): void;
430
/**
431
* Remove an existing decoration.
432
* @param id The unique identifier associated with the decoration.
433
*/
434
removeDecoration(id: string): void;
435
/**
436
* Perform a minimum amount of operations, in order to transform the decorations
437
* identified by `oldDecorations` to the decorations described by `newDecorations`
438
* and returns the new identifiers associated with the resulting decorations.
439
*
440
* @param oldDecorations Array containing previous decorations identifiers.
441
* @param newDecorations Array describing what decorations should result after the call.
442
* @return An array containing the new decorations identifiers.
443
*/
444
deltaDecorations(oldDecorations: readonly string[], newDecorations: readonly IModelDeltaDecoration[]): string[];
445
}
446
447
/**
448
* End of line character preference.
449
*/
450
export const enum EndOfLinePreference {
451
/**
452
* Use the end of line character identified in the text buffer.
453
*/
454
TextDefined = 0,
455
/**
456
* Use line feed (\n) as the end of line character.
457
*/
458
LF = 1,
459
/**
460
* Use carriage return and line feed (\r\n) as the end of line character.
461
*/
462
CRLF = 2
463
}
464
465
/**
466
* The default end of line to use when instantiating models.
467
*/
468
export const enum DefaultEndOfLine {
469
/**
470
* Use line feed (\n) as the end of line character.
471
*/
472
LF = 1,
473
/**
474
* Use carriage return and line feed (\r\n) as the end of line character.
475
*/
476
CRLF = 2
477
}
478
479
/**
480
* End of line character preference.
481
*/
482
export const enum EndOfLineSequence {
483
/**
484
* Use line feed (\n) as the end of line character.
485
*/
486
LF = 0,
487
/**
488
* Use carriage return and line feed (\r\n) as the end of line character.
489
*/
490
CRLF = 1
491
}
492
493
/**
494
* An identifier for a single edit operation.
495
* @internal
496
*/
497
export interface ISingleEditOperationIdentifier {
498
/**
499
* Identifier major
500
*/
501
major: number;
502
/**
503
* Identifier minor
504
*/
505
minor: number;
506
}
507
508
/**
509
* A single edit operation, that has an identifier.
510
*/
511
export interface IIdentifiedSingleEditOperation extends ISingleEditOperation {
512
/**
513
* An identifier associated with this single edit operation.
514
* @internal
515
*/
516
identifier?: ISingleEditOperationIdentifier | null;
517
/**
518
* This indicates that this operation is inserting automatic whitespace
519
* that can be removed on next model edit operation if `config.trimAutoWhitespace` is true.
520
* @internal
521
*/
522
isAutoWhitespaceEdit?: boolean;
523
/**
524
* This indicates that this operation is in a set of operations that are tracked and should not be "simplified".
525
* @internal
526
*/
527
_isTracked?: boolean;
528
}
529
530
export interface IValidEditOperation {
531
/**
532
* An identifier associated with this single edit operation.
533
* @internal
534
*/
535
identifier: ISingleEditOperationIdentifier | null;
536
/**
537
* The range to replace. This can be empty to emulate a simple insert.
538
*/
539
range: Range;
540
/**
541
* The text to replace with. This can be empty to emulate a simple delete.
542
*/
543
text: string;
544
/**
545
* @internal
546
*/
547
textChange: TextChange;
548
}
549
550
/**
551
* A callback that can compute the cursor state after applying a series of edit operations.
552
*/
553
export interface ICursorStateComputer {
554
/**
555
* A callback that can compute the resulting cursors state after some edit operations have been executed.
556
*/
557
(inverseEditOperations: IValidEditOperation[]): Selection[] | null;
558
}
559
560
export class TextModelResolvedOptions {
561
_textModelResolvedOptionsBrand: void = undefined;
562
563
readonly tabSize: number;
564
readonly indentSize: number;
565
private readonly _indentSizeIsTabSize: boolean;
566
readonly insertSpaces: boolean;
567
readonly defaultEOL: DefaultEndOfLine;
568
readonly trimAutoWhitespace: boolean;
569
readonly bracketPairColorizationOptions: BracketPairColorizationOptions;
570
571
public get originalIndentSize(): number | 'tabSize' {
572
return this._indentSizeIsTabSize ? 'tabSize' : this.indentSize;
573
}
574
575
/**
576
* @internal
577
*/
578
constructor(src: {
579
tabSize: number;
580
indentSize: number | 'tabSize';
581
insertSpaces: boolean;
582
defaultEOL: DefaultEndOfLine;
583
trimAutoWhitespace: boolean;
584
bracketPairColorizationOptions: BracketPairColorizationOptions;
585
}) {
586
this.tabSize = Math.max(1, src.tabSize | 0);
587
if (src.indentSize === 'tabSize') {
588
this.indentSize = this.tabSize;
589
this._indentSizeIsTabSize = true;
590
} else {
591
this.indentSize = Math.max(1, src.indentSize | 0);
592
this._indentSizeIsTabSize = false;
593
}
594
this.insertSpaces = Boolean(src.insertSpaces);
595
this.defaultEOL = src.defaultEOL | 0;
596
this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace);
597
this.bracketPairColorizationOptions = src.bracketPairColorizationOptions;
598
}
599
600
/**
601
* @internal
602
*/
603
public equals(other: TextModelResolvedOptions): boolean {
604
return (
605
this.tabSize === other.tabSize
606
&& this._indentSizeIsTabSize === other._indentSizeIsTabSize
607
&& this.indentSize === other.indentSize
608
&& this.insertSpaces === other.insertSpaces
609
&& this.defaultEOL === other.defaultEOL
610
&& this.trimAutoWhitespace === other.trimAutoWhitespace
611
&& equals(this.bracketPairColorizationOptions, other.bracketPairColorizationOptions)
612
);
613
}
614
615
/**
616
* @internal
617
*/
618
public createChangeEvent(newOpts: TextModelResolvedOptions): IModelOptionsChangedEvent {
619
return {
620
tabSize: this.tabSize !== newOpts.tabSize,
621
indentSize: this.indentSize !== newOpts.indentSize,
622
insertSpaces: this.insertSpaces !== newOpts.insertSpaces,
623
trimAutoWhitespace: this.trimAutoWhitespace !== newOpts.trimAutoWhitespace,
624
};
625
}
626
}
627
628
/**
629
* @internal
630
*/
631
export interface ITextModelCreationOptions {
632
tabSize: number;
633
indentSize: number | 'tabSize';
634
insertSpaces: boolean;
635
detectIndentation: boolean;
636
trimAutoWhitespace: boolean;
637
defaultEOL: DefaultEndOfLine;
638
isForSimpleWidget: boolean;
639
largeFileOptimizations: boolean;
640
bracketPairColorizationOptions: BracketPairColorizationOptions;
641
}
642
643
export interface BracketPairColorizationOptions {
644
enabled: boolean;
645
independentColorPoolPerBracketType: boolean;
646
}
647
648
export interface ITextModelUpdateOptions {
649
tabSize?: number;
650
indentSize?: number | 'tabSize';
651
insertSpaces?: boolean;
652
trimAutoWhitespace?: boolean;
653
bracketColorizationOptions?: BracketPairColorizationOptions;
654
}
655
656
export class FindMatch {
657
_findMatchBrand: void = undefined;
658
659
public readonly range: Range;
660
public readonly matches: string[] | null;
661
662
/**
663
* @internal
664
*/
665
constructor(range: Range, matches: string[] | null) {
666
this.range = range;
667
this.matches = matches;
668
}
669
}
670
671
/**
672
* Describes the behavior of decorations when typing/editing near their edges.
673
* Note: Please do not edit the values, as they very carefully match `DecorationRangeBehavior`
674
*/
675
export const enum TrackedRangeStickiness {
676
AlwaysGrowsWhenTypingAtEdges = 0,
677
NeverGrowsWhenTypingAtEdges = 1,
678
GrowsOnlyWhenTypingBefore = 2,
679
GrowsOnlyWhenTypingAfter = 3,
680
}
681
682
/**
683
* Text snapshot that works like an iterator.
684
* Will try to return chunks of roughly ~64KB size.
685
* Will return null when finished.
686
*/
687
export interface ITextSnapshot {
688
read(): string | null;
689
}
690
691
/**
692
* @internal
693
*/
694
export function isITextSnapshot(obj: unknown): obj is ITextSnapshot {
695
return (!!obj && typeof (obj as ITextSnapshot).read === 'function');
696
}
697
698
/**
699
* A model.
700
*/
701
export interface ITextModel {
702
703
/**
704
* Gets the resource associated with this editor model.
705
*/
706
readonly uri: URI;
707
708
/**
709
* A unique identifier associated with this model.
710
*/
711
readonly id: string;
712
713
/**
714
* This model is constructed for a simple widget code editor.
715
* @internal
716
*/
717
readonly isForSimpleWidget: boolean;
718
719
/**
720
* Method to register a view model on a model
721
* @internal
722
*/
723
registerViewModel(viewModel: IViewModel): void;
724
725
/**
726
* Method which unregister a view model on a model
727
* @internal
728
*/
729
unregisterViewModel(viewModel: IViewModel): void;
730
731
/**
732
* If true, the text model might contain RTL.
733
* If false, the text model **contains only** contain LTR.
734
* @internal
735
*/
736
mightContainRTL(): boolean;
737
738
/**
739
* If true, the text model might contain LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).
740
* If false, the text model definitely does not contain these.
741
* @internal
742
*/
743
mightContainUnusualLineTerminators(): boolean;
744
745
/**
746
* @internal
747
*/
748
removeUnusualLineTerminators(selections?: Selection[]): void;
749
750
/**
751
* If true, the text model might contain non basic ASCII.
752
* If false, the text model **contains only** basic ASCII.
753
* @internal
754
*/
755
mightContainNonBasicASCII(): boolean;
756
757
/**
758
* Get the resolved options for this model.
759
*/
760
getOptions(): TextModelResolvedOptions;
761
762
/**
763
* Get the formatting options for this model.
764
* @internal
765
*/
766
getFormattingOptions(): FormattingOptions;
767
768
/**
769
* Get the current version id of the model.
770
* Anytime a change happens to the model (even undo/redo),
771
* the version id is incremented.
772
*/
773
getVersionId(): number;
774
775
/**
776
* Get the alternative version id of the model.
777
* This alternative version id is not always incremented,
778
* it will return the same values in the case of undo-redo.
779
*/
780
getAlternativeVersionId(): number;
781
782
/**
783
* Replace the entire text buffer value contained in this model.
784
*/
785
setValue(newValue: string | ITextSnapshot): void;
786
787
/**
788
* Get the text stored in this model.
789
* @param eol The end of line character preference. Defaults to `EndOfLinePreference.TextDefined`.
790
* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.
791
* @return The text.
792
*/
793
getValue(eol?: EndOfLinePreference, preserveBOM?: boolean): string;
794
795
/**
796
* Get the text stored in this model.
797
* @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.
798
* @return The text snapshot (it is safe to consume it asynchronously).
799
*/
800
createSnapshot(preserveBOM?: boolean): ITextSnapshot;
801
802
/**
803
* Get the length of the text stored in this model.
804
*/
805
getValueLength(eol?: EndOfLinePreference, preserveBOM?: boolean): number;
806
807
/**
808
* Check if the raw text stored in this model equals another raw text.
809
* @internal
810
*/
811
equalsTextBuffer(other: ITextBuffer): boolean;
812
813
/**
814
* Get the underling text buffer.
815
* @internal
816
*/
817
getTextBuffer(): ITextBuffer;
818
819
/**
820
* Get the text in a certain range.
821
* @param range The range describing what text to get.
822
* @param eol The end of line character preference. This will only be used for multiline ranges. Defaults to `EndOfLinePreference.TextDefined`.
823
* @return The text.
824
*/
825
getValueInRange(range: IRange, eol?: EndOfLinePreference): string;
826
827
/**
828
* Get the length of text in a certain range.
829
* @param range The range describing what text length to get.
830
* @return The text length.
831
*/
832
getValueLengthInRange(range: IRange, eol?: EndOfLinePreference): number;
833
834
/**
835
* Get the character count of text in a certain range.
836
* @param range The range describing what text length to get.
837
*/
838
getCharacterCountInRange(range: IRange, eol?: EndOfLinePreference): number;
839
840
/**
841
* Splits characters in two buckets. First bucket (A) is of characters that
842
* sit in lines with length < `LONG_LINE_BOUNDARY`. Second bucket (B) is of
843
* characters that sit in lines with length >= `LONG_LINE_BOUNDARY`.
844
* If count(B) > count(A) return true. Returns false otherwise.
845
* @internal
846
*/
847
isDominatedByLongLines(): boolean;
848
849
/**
850
* Get the number of lines in the model.
851
*/
852
getLineCount(): number;
853
854
/**
855
* Get the text for a certain line.
856
*/
857
getLineContent(lineNumber: number): string;
858
859
/**
860
* Get the text length for a certain line.
861
*/
862
getLineLength(lineNumber: number): number;
863
864
/**
865
* Get the text for all lines.
866
*/
867
getLinesContent(): string[];
868
869
/**
870
* Get the end of line sequence predominantly used in the text buffer.
871
* @return EOL char sequence (e.g.: '\n' or '\r\n').
872
*/
873
getEOL(): string;
874
875
/**
876
* Get the end of line sequence predominantly used in the text buffer.
877
*/
878
getEndOfLineSequence(): EndOfLineSequence;
879
880
/**
881
* Get the minimum legal column for line at `lineNumber`
882
*/
883
getLineMinColumn(lineNumber: number): number;
884
885
/**
886
* Get the maximum legal column for line at `lineNumber`
887
*/
888
getLineMaxColumn(lineNumber: number): number;
889
890
/**
891
* Returns the column before the first non whitespace character for line at `lineNumber`.
892
* Returns 0 if line is empty or contains only whitespace.
893
*/
894
getLineFirstNonWhitespaceColumn(lineNumber: number): number;
895
896
/**
897
* Returns the column after the last non whitespace character for line at `lineNumber`.
898
* Returns 0 if line is empty or contains only whitespace.
899
*/
900
getLineLastNonWhitespaceColumn(lineNumber: number): number;
901
902
/**
903
* Create a valid position.
904
*/
905
validatePosition(position: IPosition): Position;
906
907
/**
908
* Advances the given position by the given offset (negative offsets are also accepted)
909
* and returns it as a new valid position.
910
*
911
* If the offset and position are such that their combination goes beyond the beginning or
912
* end of the model, throws an exception.
913
*
914
* If the offset is such that the new position would be in the middle of a multi-byte
915
* line terminator, throws an exception.
916
*/
917
modifyPosition(position: IPosition, offset: number): Position;
918
919
/**
920
* Create a valid range.
921
*/
922
validateRange(range: IRange): Range;
923
924
/**
925
* Verifies the range is valid.
926
*/
927
isValidRange(range: IRange): boolean;
928
929
/**
930
* Converts the position to a zero-based offset.
931
*
932
* The position will be [adjusted](#TextDocument.validatePosition).
933
*
934
* @param position A position.
935
* @return A valid zero-based offset.
936
*/
937
getOffsetAt(position: IPosition): number;
938
939
/**
940
* Converts a zero-based offset to a position.
941
*
942
* @param offset A zero-based offset.
943
* @return A valid [position](#Position).
944
*/
945
getPositionAt(offset: number): Position;
946
947
/**
948
* Get a range covering the entire model.
949
*/
950
getFullModelRange(): Range;
951
952
/**
953
* Returns if the model was disposed or not.
954
*/
955
isDisposed(): boolean;
956
957
/**
958
* This model is so large that it would not be a good idea to sync it over
959
* to web workers or other places.
960
* @internal
961
*/
962
isTooLargeForSyncing(): boolean;
963
964
/**
965
* The file is so large, that even tokenization is disabled.
966
* @internal
967
*/
968
isTooLargeForTokenization(): boolean;
969
970
/**
971
* The file is so large, that operations on it might be too large for heap
972
* and can lead to OOM crashes so they should be disabled.
973
* @internal
974
*/
975
isTooLargeForHeapOperation(): boolean;
976
977
/**
978
* Search the model.
979
* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
980
* @param searchOnlyEditableRange Limit the searching to only search inside the editable range of the model.
981
* @param isRegex Used to indicate that `searchString` is a regular expression.
982
* @param matchCase Force the matching to match lower/upper case exactly.
983
* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
984
* @param captureMatches The result will contain the captured groups.
985
* @param limitResultCount Limit the number of results
986
* @return The ranges where the matches are. It is empty if not matches have been found.
987
*/
988
findMatches(searchString: string, searchOnlyEditableRange: boolean, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];
989
/**
990
* Search the model.
991
* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
992
* @param searchScope Limit the searching to only search inside these ranges.
993
* @param isRegex Used to indicate that `searchString` is a regular expression.
994
* @param matchCase Force the matching to match lower/upper case exactly.
995
* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
996
* @param captureMatches The result will contain the captured groups.
997
* @param limitResultCount Limit the number of results
998
* @return The ranges where the matches are. It is empty if no matches have been found.
999
*/
1000
findMatches(searchString: string, searchScope: IRange | IRange[], isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];
1001
/**
1002
* Search the model for the next match. Loops to the beginning of the model if needed.
1003
* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
1004
* @param searchStart Start the searching at the specified position.
1005
* @param isRegex Used to indicate that `searchString` is a regular expression.
1006
* @param matchCase Force the matching to match lower/upper case exactly.
1007
* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
1008
* @param captureMatches The result will contain the captured groups.
1009
* @return The range where the next match is. It is null if no next match has been found.
1010
*/
1011
findNextMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;
1012
/**
1013
* Search the model for the previous match. Loops to the end of the model if needed.
1014
* @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
1015
* @param searchStart Start the searching at the specified position.
1016
* @param isRegex Used to indicate that `searchString` is a regular expression.
1017
* @param matchCase Force the matching to match lower/upper case exactly.
1018
* @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
1019
* @param captureMatches The result will contain the captured groups.
1020
* @return The range where the previous match is. It is null if no previous match has been found.
1021
*/
1022
findPreviousMatch(searchString: string, searchStart: IPosition, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean): FindMatch | null;
1023
1024
1025
/**
1026
* Get the language associated with this model.
1027
*/
1028
getLanguageId(): string;
1029
1030
/**
1031
* Set the current language mode associated with the model.
1032
* @param languageId The new language.
1033
* @param source The source of the call that set the language.
1034
* @internal
1035
*/
1036
setLanguage(languageId: string, source?: string): void;
1037
1038
/**
1039
* Set the current language mode associated with the model.
1040
* @param languageSelection The new language selection.
1041
* @param source The source of the call that set the language.
1042
* @internal
1043
*/
1044
setLanguage(languageSelection: ILanguageSelection, source?: string): void;
1045
1046
/**
1047
* Returns the real (inner-most) language mode at a given position.
1048
* The result might be inaccurate. Use `forceTokenization` to ensure accurate tokens.
1049
* @internal
1050
*/
1051
getLanguageIdAtPosition(lineNumber: number, column: number): string;
1052
1053
/**
1054
* Get the word under or besides `position`.
1055
* @param position The position to look for a word.
1056
* @return The word under or besides `position`. Might be null.
1057
*/
1058
getWordAtPosition(position: IPosition): IWordAtPosition | null;
1059
1060
/**
1061
* Get the word under or besides `position` trimmed to `position`.column
1062
* @param position The position to look for a word.
1063
* @return The word under or besides `position`. Will never be null.
1064
*/
1065
getWordUntilPosition(position: IPosition): IWordAtPosition;
1066
1067
/**
1068
* Change the decorations. The callback will be called with a change accessor
1069
* that becomes invalid as soon as the callback finishes executing.
1070
* This allows for all events to be queued up until the change
1071
* is completed. Returns whatever the callback returns.
1072
* @param ownerId Identifies the editor id in which these decorations should appear. If no `ownerId` is provided, the decorations will appear in all editors that attach this model.
1073
* @internal
1074
*/
1075
changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T, ownerId?: number): T | null;
1076
1077
/**
1078
* Perform a minimum amount of operations, in order to transform the decorations
1079
* identified by `oldDecorations` to the decorations described by `newDecorations`
1080
* and returns the new identifiers associated with the resulting decorations.
1081
*
1082
* @param oldDecorations Array containing previous decorations identifiers.
1083
* @param newDecorations Array describing what decorations should result after the call.
1084
* @param ownerId Identifies the editor id in which these decorations should appear. If no `ownerId` is provided, the decorations will appear in all editors that attach this model.
1085
* @return An array containing the new decorations identifiers.
1086
*/
1087
deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[], ownerId?: number): string[];
1088
1089
/**
1090
* Remove all decorations that have been added with this specific ownerId.
1091
* @param ownerId The owner id to search for.
1092
* @internal
1093
*/
1094
removeAllDecorationsWithOwnerId(ownerId: number): void;
1095
1096
/**
1097
* Get the options associated with a decoration.
1098
* @param id The decoration id.
1099
* @return The decoration options or null if the decoration was not found.
1100
*/
1101
getDecorationOptions(id: string): IModelDecorationOptions | null;
1102
1103
/**
1104
* Get the range associated with a decoration.
1105
* @param id The decoration id.
1106
* @return The decoration range or null if the decoration was not found.
1107
*/
1108
getDecorationRange(id: string): Range | null;
1109
1110
/**
1111
* Gets all the decorations for the line `lineNumber` as an array.
1112
* @param lineNumber The line number
1113
* @param ownerId If set, it will ignore decorations belonging to other owners.
1114
* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
1115
* @param filterFontDecorations If set, it will ignore font decorations.
1116
* @return An array with the decorations
1117
*/
1118
getLineDecorations(lineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];
1119
1120
/**
1121
* Gets all the font decorations for the line `lineNumber` as an array.
1122
* @param ownerId If set, it will ignore decorations belonging to other owners.
1123
* @internal
1124
*/
1125
getFontDecorationsInRange(range: IRange, ownerId?: number): IModelDecoration[];
1126
1127
/**
1128
* Gets all the decorations for the lines between `startLineNumber` and `endLineNumber` as an array.
1129
* @param startLineNumber The start line number
1130
* @param endLineNumber The end line number
1131
* @param ownerId If set, it will ignore decorations belonging to other owners.
1132
* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
1133
* @param filterFontDecorations If set, it will ignore font decorations.
1134
* @return An array with the decorations
1135
*/
1136
getLinesDecorations(startLineNumber: number, endLineNumber: number, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];
1137
1138
/**
1139
* Gets all the decorations in a range as an array. Only `startLineNumber` and `endLineNumber` from `range` are used for filtering.
1140
* So for now it returns all the decorations on the same line as `range`.
1141
* @param range The range to search in
1142
* @param ownerId If set, it will ignore decorations belonging to other owners.
1143
* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
1144
* @param filterFontDecorations If set, it will ignore font decorations.
1145
* @param onlyMinimapDecorations If set, it will return only decorations that render in the minimap.
1146
* @param onlyMarginDecorations If set, it will return only decorations that render in the glyph margin.
1147
* @return An array with the decorations
1148
*/
1149
getDecorationsInRange(range: IRange, ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean, onlyMinimapDecorations?: boolean, onlyMarginDecorations?: boolean): IModelDecoration[];
1150
1151
/**
1152
* Gets all the decorations as an array.
1153
* @param ownerId If set, it will ignore decorations belonging to other owners.
1154
* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
1155
* @param filterFontDecorations If set, it will ignore font decorations.
1156
*/
1157
getAllDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];
1158
1159
/**
1160
* Gets all decorations that render in the glyph margin as an array.
1161
* @param ownerId If set, it will ignore decorations belonging to other owners.
1162
*/
1163
getAllMarginDecorations(ownerId?: number): IModelDecoration[];
1164
1165
/**
1166
* Gets all the decorations that should be rendered in the overview ruler as an array.
1167
* @param ownerId If set, it will ignore decorations belonging to other owners.
1168
* @param filterOutValidation If set, it will ignore decorations specific to validation (i.e. warnings, errors).
1169
* @param filterFontDecorations If set, it will ignore font decorations.
1170
*/
1171
getOverviewRulerDecorations(ownerId?: number, filterOutValidation?: boolean, filterFontDecorations?: boolean): IModelDecoration[];
1172
1173
/**
1174
* Gets all the decorations that contain injected text.
1175
* @param ownerId If set, it will ignore decorations belonging to other owners.
1176
*/
1177
getInjectedTextDecorations(ownerId?: number): IModelDecoration[];
1178
1179
/**
1180
* Gets all the decorations that contain custom line heights.
1181
* @param ownerId If set, it will ignore decorations belonging to other owners.
1182
*/
1183
getCustomLineHeightsDecorations(ownerId?: number): IModelDecoration[];
1184
1185
/**
1186
* @internal
1187
*/
1188
_getTrackedRange(id: string): Range | null;
1189
1190
/**
1191
* @internal
1192
*/
1193
_setTrackedRange(id: string | null, newRange: null, newStickiness: TrackedRangeStickiness): null;
1194
/**
1195
* @internal
1196
*/
1197
_setTrackedRange(id: string | null, newRange: Range, newStickiness: TrackedRangeStickiness): string;
1198
1199
/**
1200
* Normalize a string containing whitespace according to indentation rules (converts to spaces or to tabs).
1201
*/
1202
normalizeIndentation(str: string): string;
1203
1204
/**
1205
* Change the options of this model.
1206
*/
1207
updateOptions(newOpts: ITextModelUpdateOptions): void;
1208
1209
/**
1210
* Detect the indentation options for this model from its content.
1211
*/
1212
detectIndentation(defaultInsertSpaces: boolean, defaultTabSize: number): void;
1213
1214
/**
1215
* Close the current undo-redo element.
1216
* This offers a way to create an undo/redo stop point.
1217
*/
1218
pushStackElement(): void;
1219
1220
/**
1221
* Open the current undo-redo element.
1222
* This offers a way to remove the current undo/redo stop point.
1223
*/
1224
popStackElement(): void;
1225
1226
/**
1227
* @internal
1228
*/
1229
edit(edit: TextEdit, options?: { reason?: TextModelEditSource }): void;
1230
1231
/**
1232
* Push edit operations, basically editing the model. This is the preferred way
1233
* of editing the model. The edit operations will land on the undo stack.
1234
* @param beforeCursorState The cursor state before the edit operations. This cursor state will be returned when `undo` or `redo` are invoked.
1235
* @param editOperations The edit operations.
1236
* @param cursorStateComputer A callback that can compute the resulting cursors state after the edit operations have been executed.
1237
* @return The cursor state returned by the `cursorStateComputer`.
1238
*/
1239
pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer): Selection[] | null;
1240
/**
1241
* @internal
1242
*/
1243
pushEditOperations(beforeCursorState: Selection[] | null, editOperations: IIdentifiedSingleEditOperation[], cursorStateComputer: ICursorStateComputer, group?: UndoRedoGroup, reason?: TextModelEditSource): Selection[] | null;
1244
1245
/**
1246
* Change the end of line sequence. This is the preferred way of
1247
* changing the eol sequence. This will land on the undo stack.
1248
*/
1249
pushEOL(eol: EndOfLineSequence): void;
1250
1251
/**
1252
* Edit the model without adding the edits to the undo stack.
1253
* This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.
1254
* @param operations The edit operations.
1255
* @return If desired, the inverse edit operations, that, when applied, will bring the model back to the previous state.
1256
*/
1257
applyEdits(operations: readonly IIdentifiedSingleEditOperation[]): void;
1258
/** @internal */
1259
applyEdits(operations: readonly IIdentifiedSingleEditOperation[], reason: TextModelEditSource): void;
1260
applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: false): void;
1261
applyEdits(operations: readonly IIdentifiedSingleEditOperation[], computeUndoEdits: true): IValidEditOperation[];
1262
1263
/**
1264
* Change the end of line sequence without recording in the undo stack.
1265
* This can have dire consequences on the undo stack! See @pushEOL for the preferred way.
1266
*/
1267
setEOL(eol: EndOfLineSequence): void;
1268
1269
/**
1270
* @internal
1271
*/
1272
_applyUndo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;
1273
1274
/**
1275
* @internal
1276
*/
1277
_applyRedo(changes: TextChange[], eol: EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void;
1278
1279
/**
1280
* Undo edit operations until the previous undo/redo point.
1281
* The inverse edit operations will be pushed on the redo stack.
1282
*/
1283
undo(): void | Promise<void>;
1284
1285
/**
1286
* Is there anything in the undo stack?
1287
*/
1288
canUndo(): boolean;
1289
1290
/**
1291
* Redo edit operations until the next undo/redo point.
1292
* The inverse edit operations will be pushed on the undo stack.
1293
*/
1294
redo(): void | Promise<void>;
1295
1296
/**
1297
* Is there anything in the redo stack?
1298
*/
1299
canRedo(): boolean;
1300
1301
/**
1302
* An event emitted when the contents of the model have changed.
1303
* @event
1304
*/
1305
onDidChangeContent(listener: (e: IModelContentChangedEvent) => void): IDisposable;
1306
/**
1307
* An event emitted when decorations of the model have changed.
1308
* @event
1309
*/
1310
readonly onDidChangeDecorations: Event<IModelDecorationsChangedEvent>;
1311
/**
1312
* An event emitted when line heights from decorations changes.
1313
* This event is emitted only when adding, removing or changing a decoration
1314
* and not when doing edits in the model (i.e. when decoration ranges change)
1315
* @internal
1316
* @event
1317
*/
1318
readonly onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;
1319
/**
1320
* An event emitted when the font from decorations changes.
1321
* This event is emitted only when adding, removing or changing a decoration
1322
* and not when doing edits in the model (i.e. when decoration ranges change)
1323
* @internal
1324
* @event
1325
*/
1326
readonly onDidChangeFont: Event<ModelFontChangedEvent>;
1327
/**
1328
* An event emitted when the model options have changed.
1329
* @event
1330
*/
1331
readonly onDidChangeOptions: Event<IModelOptionsChangedEvent>;
1332
/**
1333
* An event emitted when the language associated with the model has changed.
1334
* @event
1335
*/
1336
readonly onDidChangeLanguage: Event<IModelLanguageChangedEvent>;
1337
/**
1338
* An event emitted when the language configuration associated with the model has changed.
1339
* @event
1340
*/
1341
readonly onDidChangeLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;
1342
/**
1343
* An event emitted when the tokens associated with the model have changed.
1344
* @event
1345
* @internal
1346
*/
1347
readonly onDidChangeTokens: Event<IModelTokensChangedEvent>;
1348
/**
1349
* An event emitted when the model has been attached to the first editor or detached from the last editor.
1350
* @event
1351
*/
1352
readonly onDidChangeAttached: Event<void>;
1353
/**
1354
* An event emitted right before disposing the model.
1355
* @event
1356
*/
1357
readonly onWillDispose: Event<void>;
1358
1359
/**
1360
* Destroy this model.
1361
*/
1362
dispose(): void;
1363
1364
/**
1365
* @internal
1366
*/
1367
onBeforeAttached(): IAttachedView;
1368
1369
/**
1370
* @internal
1371
*/
1372
onBeforeDetached(view: IAttachedView): void;
1373
1374
/**
1375
* Returns if this model is attached to an editor or not.
1376
*/
1377
isAttachedToEditor(): boolean;
1378
1379
/**
1380
* Returns the count of editors this model is attached to.
1381
* @internal
1382
*/
1383
getAttachedEditorCount(): number;
1384
1385
/**
1386
* Among all positions that are projected to the same position in the underlying text model as
1387
* the given position, select a unique position as indicated by the affinity.
1388
*
1389
* PositionAffinity.Left:
1390
* The normalized position must be equal or left to the requested position.
1391
*
1392
* PositionAffinity.Right:
1393
* The normalized position must be equal or right to the requested position.
1394
*
1395
* @internal
1396
*/
1397
normalizePosition(position: Position, affinity: PositionAffinity): Position;
1398
1399
/**
1400
* Gets the column at which indentation stops at a given line.
1401
* @internal
1402
*/
1403
getLineIndentColumn(lineNumber: number): number;
1404
1405
/**
1406
* Returns an object that can be used to query brackets.
1407
* @internal
1408
*/
1409
readonly bracketPairs: IBracketPairsTextModelPart;
1410
1411
/**
1412
* Returns an object that can be used to query indent guides.
1413
* @internal
1414
*/
1415
readonly guides: IGuidesTextModelPart;
1416
1417
/**
1418
* @internal
1419
*/
1420
readonly tokenization: ITokenizationTextModelPart;
1421
}
1422
1423
/**
1424
* @internal
1425
*/
1426
export function isITextModel(obj: IEditorModel): obj is ITextModel {
1427
return Boolean(obj && (obj as ITextModel).uri);
1428
}
1429
1430
/**
1431
* @internal
1432
*/
1433
export interface IAttachedView {
1434
/**
1435
* @param stabilized Indicates if the visible lines are probably going to change soon or can be considered stable.
1436
* Is true on reveal range and false on scroll.
1437
* Tokenizers should tokenize synchronously if stabilized is true.
1438
*/
1439
setVisibleLines(visibleLines: { startLineNumber: number; endLineNumber: number }[], stabilized: boolean): void;
1440
}
1441
1442
export const enum PositionAffinity {
1443
/**
1444
* Prefers the left most position.
1445
*/
1446
Left = 0,
1447
1448
/**
1449
* Prefers the right most position.
1450
*/
1451
Right = 1,
1452
1453
/**
1454
* No preference.
1455
*/
1456
None = 2,
1457
1458
/**
1459
* If the given position is on injected text, prefers the position left of it.
1460
*/
1461
LeftOfInjectedText = 3,
1462
1463
/**
1464
* If the given position is on injected text, prefers the position right of it.
1465
*/
1466
RightOfInjectedText = 4,
1467
}
1468
1469
/**
1470
* @internal
1471
*/
1472
export interface ITextBufferBuilder {
1473
acceptChunk(chunk: string): void;
1474
finish(): ITextBufferFactory;
1475
}
1476
1477
/**
1478
* @internal
1479
*/
1480
export interface ITextBufferFactory {
1481
create(defaultEOL: DefaultEndOfLine): { textBuffer: ITextBuffer; disposable: IDisposable };
1482
getFirstLineText(lengthLimit: number): string;
1483
}
1484
1485
/**
1486
* @internal
1487
*/
1488
export const enum ModelConstants {
1489
FIRST_LINE_DETECTION_LENGTH_LIMIT = 1000
1490
}
1491
1492
/**
1493
* @internal
1494
*/
1495
export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {
1496
constructor(
1497
public readonly identifier: ISingleEditOperationIdentifier | null,
1498
public readonly range: Range,
1499
public readonly text: string | null,
1500
public readonly forceMoveMarkers: boolean,
1501
public readonly isAutoWhitespaceEdit: boolean,
1502
public readonly _isTracked: boolean,
1503
) { }
1504
}
1505
1506
/**
1507
* @internal
1508
*
1509
* `lineNumber` is 1 based.
1510
*/
1511
export interface IReadonlyTextBuffer {
1512
readonly onDidChangeContent: Event<void>;
1513
equals(other: ITextBuffer): boolean;
1514
mightContainRTL(): boolean;
1515
mightContainUnusualLineTerminators(): boolean;
1516
resetMightContainUnusualLineTerminators(): void;
1517
mightContainNonBasicASCII(): boolean;
1518
getBOM(): string;
1519
getEOL(): string;
1520
1521
getOffsetAt(lineNumber: number, column: number): number;
1522
getPositionAt(offset: number): Position;
1523
getRangeAt(offset: number, length: number): Range;
1524
1525
getValueInRange(range: Range, eol: EndOfLinePreference): string;
1526
createSnapshot(preserveBOM: boolean): ITextSnapshot;
1527
getValueLengthInRange(range: Range, eol: EndOfLinePreference): number;
1528
getCharacterCountInRange(range: Range, eol: EndOfLinePreference): number;
1529
getLength(): number;
1530
getLineCount(): number;
1531
getLinesContent(): string[];
1532
getLineContent(lineNumber: number): string;
1533
getLineCharCode(lineNumber: number, index: number): number;
1534
getCharCode(offset: number): number;
1535
getLineLength(lineNumber: number): number;
1536
getLineMinColumn(lineNumber: number): number;
1537
getLineMaxColumn(lineNumber: number): number;
1538
getLineFirstNonWhitespaceColumn(lineNumber: number): number;
1539
getLineLastNonWhitespaceColumn(lineNumber: number): number;
1540
findMatchesLineByLine(searchRange: Range, searchData: SearchData, captureMatches: boolean, limitResultCount: number): FindMatch[];
1541
1542
/**
1543
* Get nearest chunk of text after `offset` in the text buffer.
1544
*/
1545
getNearestChunk(offset: number): string;
1546
}
1547
1548
/**
1549
* @internal
1550
*/
1551
export class SearchData {
1552
1553
/**
1554
* The regex to search for. Always defined.
1555
*/
1556
public readonly regex: RegExp;
1557
/**
1558
* The word separator classifier.
1559
*/
1560
public readonly wordSeparators: WordCharacterClassifier | null;
1561
/**
1562
* The simple string to search for (if possible).
1563
*/
1564
public readonly simpleSearch: string | null;
1565
1566
constructor(regex: RegExp, wordSeparators: WordCharacterClassifier | null, simpleSearch: string | null) {
1567
this.regex = regex;
1568
this.wordSeparators = wordSeparators;
1569
this.simpleSearch = simpleSearch;
1570
}
1571
}
1572
1573
/**
1574
* @internal
1575
*/
1576
export interface ITextBuffer extends IReadonlyTextBuffer, IDisposable {
1577
setEOL(newEOL: '\r\n' | '\n'): void;
1578
applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean, computeUndoEdits: boolean): ApplyEditsResult;
1579
}
1580
1581
/**
1582
* @internal
1583
*/
1584
export class ApplyEditsResult {
1585
1586
constructor(
1587
public readonly reverseEdits: IValidEditOperation[] | null,
1588
public readonly changes: IInternalModelContentChange[],
1589
public readonly trimAutoWhitespaceLineNumbers: number[] | null
1590
) { }
1591
1592
}
1593
1594
/**
1595
* @internal
1596
*/
1597
export interface IInternalModelContentChange extends IModelContentChange {
1598
range: Range;
1599
forceMoveMarkers: boolean;
1600
}
1601
1602
/**
1603
* @internal
1604
*/
1605
export function shouldSynchronizeModel(model: ITextModel): boolean {
1606
return (
1607
!model.isTooLargeForSyncing() && !model.isForSimpleWidget
1608
);
1609
}
1610
1611