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