UNPKG

46.6 kBTypeScriptView Raw
1import {
2 BufferScanResult,
3 BufferStoppedChangingEvent,
4 ContextualBufferScanResult,
5 Cursor,
6 CursorPositionChangedEvent,
7 Decoration,
8 DecorationLayerOptions,
9 DecorationOptions,
10 DisplayMarker,
11 DisplayMarkerLayer,
12 Disposable,
13 EditorChangedEvent,
14 FindDisplayMarkerOptions,
15 Grammar,
16 Gutter,
17 GutterOptions,
18 LayerDecoration,
19 MarkerLayer,
20 Point,
21 PointCompatible,
22 Range,
23 RangeCompatible,
24 RangeLike,
25 ReadonlyEditOptions,
26 ScanContextOptions,
27 ScopeDescriptor,
28 Selection,
29 SelectionChangedEvent,
30 TextBuffer,
31 TextEditOptions,
32 TextInsertionOptions,
33} from "../index";
34
35/**
36 * This class represents all essential editing state for a single TextBuffer,
37 * including cursor and selection positions, folds, and soft wraps.
38 */
39export class TextEditor {
40 readonly id: number;
41
42 // NOTE: undocumented within the public API. Don't go down the rabbit hole.
43 constructor(options?: object);
44
45 // Event Subscription
46 /** Calls your callback when the buffer's title has changed. */
47 onDidChangeTitle(callback: (title: string) => void): Disposable;
48
49 /** Calls your callback when the buffer's path, and therefore title, has changed. */
50 onDidChangePath(callback: (path: string) => void): Disposable;
51
52 /**
53 * Invoke the given callback synchronously when the content of the buffer
54 * changes.
55 */
56 onDidChange(callback: (event: EditorChangedEvent[]) => void): Disposable;
57
58 /**
59 * Invoke callback when the buffer's contents change. It is emit
60 * asynchronously 300ms after the last buffer change. This is a good place
61 * to handle changes to the buffer without compromising typing performance.
62 */
63 onDidStopChanging(callback: (event: BufferStoppedChangingEvent) => void): Disposable;
64
65 /**
66 * Calls your callback when a Cursor is moved. If there are multiple cursors,
67 * your callback will be called for each cursor.
68 */
69 onDidChangeCursorPosition(callback: (event: CursorPositionChangedEvent) => void): Disposable;
70
71 /** Calls your callback when a selection's screen range changes. */
72 onDidChangeSelectionRange(callback: (event: SelectionChangedEvent) => void): Disposable;
73
74 /** Invoke the given callback after the buffer is saved to disk. */
75 onDidSave(callback: (event: { path: string }) => void): Disposable;
76
77 /** Invoke the given callback when the editor is destroyed. */
78 onDidDestroy(callback: () => void): Disposable;
79
80 /** Retrieves the current TextBuffer. */
81 getBuffer(): TextBuffer;
82
83 /** Sets the read-only state for the editor. */
84 setReadOnly(readonly: boolean): void;
85
86 /** Whether or not this editor is in read-only mode. */
87 isReadOnly(): boolean;
88
89 /**
90 * Calls your callback when a Gutter is added to the editor. Immediately calls
91 * your callback for each existing gutter.
92 */
93 observeGutters(callback: (gutter: Gutter) => void): Disposable;
94
95 /** Calls your callback when a Gutter is added to the editor. */
96 onDidAddGutter(callback: (gutter: Gutter) => void): Disposable;
97
98 /** Calls your callback when a Gutter is removed from the editor. */
99 onDidRemoveGutter(callback: (name: string) => void): Disposable;
100
101 /** Calls your callback when soft wrap was enabled or disabled. */
102 onDidChangeSoftWrapped(callback: (softWrapped: boolean) => void): Disposable;
103
104 /** Calls your callback when the buffer's encoding has changed. */
105 onDidChangeEncoding(callback: (encoding: string) => void): Disposable;
106
107 /**
108 * Calls your callback when the grammar that interprets and colorizes the text
109 * has been changed. Immediately calls your callback with the current grammar.
110 */
111 observeGrammar(callback: (grammar: Grammar) => void): Disposable;
112
113 /**
114 * Calls your callback when the grammar that interprets and colorizes the text
115 * has been changed.
116 */
117 onDidChangeGrammar(callback: (grammar: Grammar) => void): Disposable;
118
119 /** Calls your callback when the result of ::isModified changes. */
120 onDidChangeModified(callback: (modified: boolean) => void): Disposable;
121
122 /**
123 * Calls your callback when the buffer's underlying file changes on disk at a
124 * moment when the result of ::isModified is true.
125 */
126 onDidConflict(callback: () => void): Disposable;
127
128 /** Calls your callback before text has been inserted. */
129 onWillInsertText(callback: (event: { text: string; cancel(): void }) => void): Disposable;
130
131 /** Calls your callback after text has been inserted. */
132 onDidInsertText(callback: (event: { text: string }) => void): Disposable;
133
134 /**
135 * Calls your callback when a Cursor is added to the editor. Immediately calls
136 * your callback for each existing cursor.
137 */
138 observeCursors(callback: (cursor: Cursor) => void): Disposable;
139
140 /** Calls your callback when a Cursor is added to the editor. */
141 onDidAddCursor(callback: (cursor: Cursor) => void): Disposable;
142
143 /** Calls your callback when a Cursor is removed from the editor. */
144 onDidRemoveCursor(callback: (cursor: Cursor) => void): Disposable;
145
146 /**
147 * Calls your callback when a Selection is added to the editor. Immediately
148 * calls your callback for each existing selection.
149 */
150 observeSelections(callback: (selection: Selection) => void): Disposable;
151
152 /** Calls your callback when a Selection is added to the editor. */
153 onDidAddSelection(callback: (selection: Selection) => void): Disposable;
154
155 /** Calls your callback when a Selection is removed from the editor. */
156 onDidRemoveSelection(callback: (selection: Selection) => void): Disposable;
157
158 /**
159 * Calls your callback with each Decoration added to the editor. Calls your
160 * callback immediately for any existing decorations.
161 */
162 observeDecorations(callback: (decoration: Decoration) => void): Disposable;
163
164 /** Calls your callback when a Decoration is added to the editor. */
165 onDidAddDecoration(callback: (decoration: Decoration) => void): Disposable;
166
167 /** Calls your callback when a Decoration is removed from the editor. */
168 onDidRemoveDecoration(callback: (decoration: Decoration) => void): Disposable;
169
170 /** Calls your callback when the placeholder text is changed. */
171 onDidChangePlaceholderText(callback: (placeholderText: string) => void): Disposable;
172
173 // File Details
174 /**
175 * Get the editor's title for display in other parts of the UI such as the tabs.
176 * If the editor's buffer is saved, its title is the file name. If it is unsaved,
177 * its title is "untitled".
178 */
179 getTitle(): string;
180
181 /**
182 * Get unique title for display in other parts of the UI, such as the window title.
183 * If the editor's buffer is unsaved, its title is "untitled" If the editor's
184 * buffer is saved, its unique title is formatted as one of the following,
185 *
186 * "" when it is the only editing buffer with this file name.
187 * " — " when other buffers have this file name.
188 */
189 getLongTitle(): string;
190
191 /** Returns the string path of this editor's text buffer. */
192 getPath(): string | undefined;
193
194 /** Returns boolean true if this editor has been modified. */
195 isModified(): boolean;
196
197 /** Returns boolean true if this editor has no content. */
198 isEmpty(): boolean;
199
200 /** Returns the string character set encoding of this editor's text buffer. */
201 getEncoding(): string;
202
203 /** Set the character set encoding to use in this editor's text buffer. */
204 setEncoding(encoding: string): void;
205
206 // File Operations
207 /**
208 * Saves the editor's text buffer.
209 * See TextBuffer::save for more details.
210 */
211 save(): Promise<void>;
212
213 /**
214 * Saves the editor's text buffer as the given path.
215 * See TextBuffer::saveAs for more details.
216 */
217 saveAs(filePath: string): Promise<void>;
218
219 // Reading Text
220 /** Returns a string representing the entire contents of the editor. */
221 getText(): string;
222
223 /** Get the text in the given range in buffer coordinates. */
224 getTextInBufferRange(range: RangeCompatible): string;
225
226 /** Returns a number representing the number of lines in the buffer. */
227 getLineCount(): number;
228
229 /**
230 * Returns a number representing the number of screen lines in the editor.
231 * This accounts for folds.
232 */
233 getScreenLineCount(): number;
234
235 /**
236 * Returns a number representing the last zero-indexed buffer row number of
237 * the editor.
238 */
239 getLastBufferRow(): number;
240
241 /**
242 * Returns a number representing the last zero-indexed screen row number of
243 * the editor.
244 */
245 getLastScreenRow(): number;
246
247 /**
248 * Returns a string representing the contents of the line at the given
249 * buffer row.
250 */
251 lineTextForBufferRow(bufferRow: number): string;
252
253 /**
254 * Returns a string representing the contents of the line at the given
255 * screen row.
256 */
257 lineTextForScreenRow(screenRow: number): string;
258
259 /** Get the range of the paragraph surrounding the most recently added cursor. */
260 getCurrentParagraphBufferRange(): Range;
261
262 // Mutating Text
263 /** Replaces the entire contents of the buffer with the given string. */
264 setText(text: string, options?: ReadonlyEditOptions): void;
265
266 /** Set the text in the given Range in buffer coordinates. */
267 setTextInBufferRange(range: RangeCompatible, text: string, options?: TextEditOptions & ReadonlyEditOptions): Range;
268
269 /* For each selection, replace the selected text with the given text. */
270 insertText(text: string, options?: TextInsertionOptions & ReadonlyEditOptions): Range | false;
271
272 /** For each selection, replace the selected text with a newline. */
273 insertNewline(options?: ReadonlyEditOptions): void;
274
275 /**
276 * For each selection, if the selection is empty, delete the character following
277 * the cursor. Otherwise delete the selected text.
278 */
279 delete(options?: ReadonlyEditOptions): void;
280
281 /**
282 * For each selection, if the selection is empty, delete the character preceding
283 * the cursor. Otherwise delete the selected text.
284 */
285 backspace(options?: ReadonlyEditOptions): void;
286
287 /**
288 * Mutate the text of all the selections in a single transaction.
289 * All the changes made inside the given function can be reverted with a single
290 * call to ::undo.
291 */
292 mutateSelectedText(fn: (selection: Selection, index: number) => void): void;
293
294 /**
295 * For each selection, transpose the selected text.
296 * If the selection is empty, the characters preceding and following the cursor
297 * are swapped. Otherwise, the selected characters are reversed.
298 */
299 transpose(options?: ReadonlyEditOptions): void;
300
301 /**
302 * Convert the selected text to upper case.
303 * For each selection, if the selection is empty, converts the containing word
304 * to upper case. Otherwise convert the selected text to upper case.
305 */
306 upperCase(options?: ReadonlyEditOptions): void;
307
308 /**
309 * Convert the selected text to lower case.
310 * For each selection, if the selection is empty, converts the containing word
311 * to upper case. Otherwise convert the selected text to upper case.
312 */
313 lowerCase(options?: ReadonlyEditOptions): void;
314
315 /**
316 * Toggle line comments for rows intersecting selections.
317 * If the current grammar doesn't support comments, does nothing.
318 */
319 toggleLineCommentsInSelection(options?: ReadonlyEditOptions): void;
320
321 /** For each cursor, insert a newline at beginning the following line. */
322 insertNewlineBelow(options?: ReadonlyEditOptions): void;
323
324 /** For each cursor, insert a newline at the end of the preceding line. */
325 insertNewlineAbove(options?: ReadonlyEditOptions): void;
326
327 /**
328 * For each selection, if the selection is empty, delete all characters of the
329 * containing word that precede the cursor. Otherwise delete the selected text.
330 */
331 deleteToBeginningOfWord(options?: ReadonlyEditOptions): void;
332
333 /**
334 * Similar to ::deleteToBeginningOfWord, but deletes only back to the previous
335 * word boundary.
336 */
337 deleteToPreviousWordBoundary(options?: ReadonlyEditOptions): void;
338
339 /** Similar to ::deleteToEndOfWord, but deletes only up to the next word boundary. */
340 deleteToNextWordBoundary(options?: ReadonlyEditOptions): void;
341
342 /**
343 * For each selection, if the selection is empty, delete all characters of the
344 * containing subword following the cursor. Otherwise delete the selected text.
345 */
346 deleteToBeginningOfSubword(options?: ReadonlyEditOptions): void;
347
348 /**
349 * For each selection, if the selection is empty, delete all characters of the
350 * containing subword following the cursor. Otherwise delete the selected text.
351 */
352 deleteToEndOfSubword(options?: ReadonlyEditOptions): void;
353
354 /**
355 * For each selection, if the selection is empty, delete all characters of the
356 * containing line that precede the cursor. Otherwise delete the selected text.
357 */
358 deleteToBeginningOfLine(options?: ReadonlyEditOptions): void;
359
360 /**
361 * For each selection, if the selection is not empty, deletes the selection
362 * otherwise, deletes all characters of the containing line following the cursor.
363 * If the cursor is already at the end of the line, deletes the following newline.
364 */
365 deleteToEndOfLine(options?: ReadonlyEditOptions): void;
366
367 /**
368 * For each selection, if the selection is empty, delete all characters of the
369 * containing word following the cursor. Otherwise delete the selected text.
370 */
371 deleteToEndOfWord(options?: ReadonlyEditOptions): void;
372
373 /** Delete all lines intersecting selections. */
374 deleteLine(options?: ReadonlyEditOptions): void;
375
376 // History
377 /** Undo the last change. */
378 undo(options?: ReadonlyEditOptions): void;
379
380 /** Redo the last change. */
381 redo(options?: ReadonlyEditOptions): void;
382
383 /**
384 * Batch multiple operations as a single undo/redo step.
385 * Any group of operations that are logically grouped from the perspective of undoing
386 * and redoing should be performed in a transaction. If you want to abort the transaction,
387 * call ::abortTransaction to terminate the function's execution and revert any changes
388 * performed up to the abortion.
389 */
390 transact(fn: () => void): void;
391 /**
392 * Batch multiple operations as a single undo/redo step.
393 * Any group of operations that are logically grouped from the perspective of undoing
394 * and redoing should be performed in a transaction. If you want to abort the transaction,
395 * call ::abortTransaction to terminate the function's execution and revert any changes
396 * performed up to the abortion.
397 */
398 transact(groupingInterval: number, fn: () => void): void;
399
400 /**
401 * Abort an open transaction, undoing any operations performed so far within the
402 * transaction.
403 */
404 abortTransaction(): void;
405
406 /**
407 * Create a pointer to the current state of the buffer for use with ::revertToCheckpoint
408 * and ::groupChangesSinceCheckpoint.
409 */
410 createCheckpoint(): number;
411
412 /**
413 * Revert the buffer to the state it was in when the given checkpoint was created.
414 * The redo stack will be empty following this operation, so changes since the checkpoint
415 * will be lost. If the given checkpoint is no longer present in the undo history, no
416 * changes will be made to the buffer and this method will return false.
417 */
418 revertToCheckpoint(checkpoint: number): boolean;
419
420 /**
421 * Group all changes since the given checkpoint into a single transaction for purposes
422 * of undo/redo.
423 * If the given checkpoint is no longer present in the undo history, no grouping will be
424 * performed and this method will return false.
425 */
426 groupChangesSinceCheckpoint(checkpoint: number): boolean;
427
428 // TextEditor Coordinates
429 /** Convert a position in buffer-coordinates to screen-coordinates. */
430 screenPositionForBufferPosition(
431 bufferPosition: PointCompatible,
432 options?: { clipDirection?: "backward" | "forward" | "closest" | undefined },
433 ): Point;
434
435 /** Convert a position in screen-coordinates to buffer-coordinates. */
436 bufferPositionForScreenPosition(
437 bufferPosition: PointCompatible,
438 options?: { clipDirection?: "backward" | "forward" | "closest" | undefined },
439 ): Point;
440
441 /** Convert a range in buffer-coordinates to screen-coordinates. */
442 screenRangeForBufferRange(bufferRange: RangeCompatible): Range;
443
444 /** Convert a range in screen-coordinates to buffer-coordinates. */
445 bufferRangeForScreenRange(screenRange: RangeCompatible): Range;
446
447 /** Clip the given Point to a valid position in the buffer. */
448 clipBufferPosition(bufferPosition: PointCompatible): Point;
449
450 /**
451 * Clip the start and end of the given range to valid positions in the buffer.
452 * See ::clipBufferPosition for more information.
453 */
454 clipBufferRange(range: RangeCompatible): Range;
455
456 /** Clip the given Point to a valid position on screen. */
457 clipScreenPosition(
458 screenPosition: PointCompatible,
459 options?: { clipDirection?: "backward" | "forward" | "closest" | undefined },
460 ): Point;
461
462 /**
463 * Clip the start and end of the given range to valid positions on screen.
464 * See ::clipScreenPosition for more information.
465 */
466 clipScreenRange(
467 range: RangeCompatible,
468 options?: { clipDirection?: "backward" | "forward" | "closest" | undefined },
469 ): Range;
470
471 // Decorations
472 /**
473 * Add a decoration that tracks a DisplayMarker. When the marker moves, is
474 * invalidated, or is destroyed, the decoration will be updated to reflect
475 * the marker's state.
476 */
477 decorateMarker(marker: DisplayMarker, decorationParams: DecorationOptions): Decoration;
478
479 /**
480 * Add a decoration to every marker in the given marker layer. Can be used to
481 * decorate a large number of markers without having to create and manage many
482 * individual decorations.
483 */
484 decorateMarkerLayer(
485 markerLayer: MarkerLayer | DisplayMarkerLayer,
486 decorationParams: DecorationLayerOptions,
487 ): LayerDecoration;
488
489 /** Get all decorations. */
490 getDecorations(propertyFilter?: DecorationOptions): Decoration[];
491
492 /** Get all decorations of type 'line'. */
493 getLineDecorations(propertyFilter?: DecorationOptions): Decoration[];
494
495 /** Get all decorations of type 'line-number'. */
496 getLineNumberDecorations(propertyFilter?: DecorationOptions): Decoration[];
497
498 /** Get all decorations of type 'highlight'. */
499 getHighlightDecorations(propertyFilter?: DecorationOptions): Decoration[];
500
501 /** Get all decorations of type 'overlay'. */
502 getOverlayDecorations(propertyFilter?: DecorationOptions): Decoration[];
503
504 // Markers
505 /**
506 * Create a marker on the default marker layer with the given range in buffer coordinates.
507 * This marker will maintain its logical location as the buffer is changed, so if you mark
508 * a particular word, the marker will remain over that word even if the word's location
509 * in the buffer changes.
510 */
511 markBufferRange(
512 range: RangeCompatible,
513 properties?: {
514 maintainHistory?: boolean | undefined;
515 reversed?: boolean | undefined;
516 invalidate?: "never" | "surround" | "overlap" | "inside" | "touch" | undefined;
517 },
518 ): DisplayMarker;
519
520 /**
521 * Create a marker on the default marker layer with the given range in screen coordinates.
522 * This marker will maintain its logical location as the buffer is changed, so if you mark
523 * a particular word, the marker will remain over that word even if the word's location in
524 * the buffer changes.
525 */
526 markScreenRange(
527 range: RangeCompatible,
528 properties?: {
529 maintainHistory?: boolean | undefined;
530 reversed?: boolean | undefined;
531 invalidate?: "never" | "surround" | "overlap" | "inside" | "touch" | undefined;
532 },
533 ): DisplayMarker;
534
535 /**
536 * Create a marker on the default marker layer with the given buffer position and no tail.
537 * To group multiple markers together in their own private layer, see ::addMarkerLayer.
538 */
539 markBufferPosition(
540 bufferPosition: PointCompatible,
541 options?: {
542 invalidate?: "never" | "surround" | "overlap" | "inside" | "touch" | undefined;
543 },
544 ): DisplayMarker;
545
546 /**
547 * Create a marker on the default marker layer with the given screen position and no tail.
548 * To group multiple markers together in their own private layer, see ::addMarkerLayer.
549 */
550 markScreenPosition(
551 screenPosition: PointCompatible,
552 options?: {
553 invalidate?: "never" | "surround" | "overlap" | "inside" | "touch" | undefined;
554 clipDirection?: "backward" | "forward" | "closest" | undefined;
555 },
556 ): DisplayMarker;
557
558 /**
559 * Find all DisplayMarkers on the default marker layer that match the given properties.
560 *
561 * This method finds markers based on the given properties. Markers can be associated
562 * with custom properties that will be compared with basic equality. In addition, there
563 * are several special properties that will be compared with the range of the markers
564 * rather than their properties.
565 */
566 findMarkers(properties: FindDisplayMarkerOptions): DisplayMarker[];
567
568 /** Create a marker layer to group related markers. */
569 addMarkerLayer(
570 options?: { maintainHistory?: boolean | undefined; persistent?: boolean | undefined },
571 ): DisplayMarkerLayer;
572
573 /** Get a DisplayMarkerLayer by id. */
574 getMarkerLayer(id: number): DisplayMarkerLayer | undefined;
575
576 /**
577 * Get the default DisplayMarkerLayer.
578 * All marker APIs not tied to an explicit layer interact with this default layer.
579 */
580 getDefaultMarkerLayer(): DisplayMarkerLayer;
581
582 /** Get the DisplayMarker on the default layer for the given marker id. */
583 getMarker(id: number): DisplayMarker;
584
585 /** Get all DisplayMarkers on the default marker layer. Consider using ::findMarkers. */
586 getMarkers(): DisplayMarker[];
587
588 /** Get the number of markers in the default marker layer. */
589 getMarkerCount(): number;
590
591 // Cursors
592 /** Get the position of the most recently added cursor in buffer coordinates. */
593 getCursorBufferPosition(): Point;
594
595 /** Get the position of all the cursor positions in buffer coordinates. */
596 getCursorBufferPositions(): Point[];
597
598 /**
599 * Move the cursor to the given position in buffer coordinates.
600 * If there are multiple cursors, they will be consolidated to a single cursor.
601 */
602 setCursorBufferPosition(position: PointCompatible, options?: { autoscroll?: boolean | undefined }): void;
603
604 /** Get a Cursor at given screen coordinates Point. */
605 getCursorAtScreenPosition(position: PointCompatible): Cursor | undefined;
606
607 /** Get the position of the most recently added cursor in screen coordinates. */
608 getCursorScreenPosition(): Point;
609
610 /** Get the position of all the cursor positions in screen coordinates. */
611 getCursorScreenPositions(): Point[];
612
613 /**
614 * Move the cursor to the given position in screen coordinates.
615 * If there are multiple cursors, they will be consolidated to a single cursor.
616 */
617 setCursorScreenPosition(position: PointCompatible, options?: { autoscroll?: boolean | undefined }): void;
618
619 /** Add a cursor at the given position in buffer coordinates. */
620 addCursorAtBufferPosition(bufferPosition: PointCompatible, options?: { autoscroll?: boolean | undefined }): Cursor;
621
622 /** Add a cursor at the position in screen coordinates. */
623 addCursorAtScreenPosition(screenPosition: PointCompatible): Cursor;
624
625 /** Returns a boolean indicating whether or not there are multiple cursors. */
626 hasMultipleCursors(): boolean;
627
628 /** Move every cursor up one row in screen coordinates. */
629 moveUp(lineCount?: number): void;
630
631 /** Move every cursor down one row in screen coordinates. */
632 moveDown(lineCount?: number): void;
633
634 /** Move every cursor left one column. */
635 moveLeft(columnCount?: number): void;
636
637 /** Move every cursor right one column. */
638 moveRight(columnCount?: number): void;
639
640 /** Move every cursor to the beginning of its line in buffer coordinates. */
641 moveToBeginningOfLine(): void;
642
643 /** Move every cursor to the beginning of its line in screen coordinates. */
644 moveToBeginningOfScreenLine(): void;
645
646 /** Move every cursor to the first non-whitespace character of its line. */
647 moveToFirstCharacterOfLine(): void;
648
649 /** Move every cursor to the end of its line in buffer coordinates. */
650 moveToEndOfLine(): void;
651
652 /** Move every cursor to the end of its line in screen coordinates. */
653 moveToEndOfScreenLine(): void;
654
655 /** Move every cursor to the beginning of its surrounding word. */
656 moveToBeginningOfWord(): void;
657
658 /** Move every cursor to the end of its surrounding word. */
659 moveToEndOfWord(): void;
660
661 /**
662 * Move every cursor to the top of the buffer.
663 * If there are multiple cursors, they will be merged into a single cursor.
664 */
665 moveToTop(): void;
666
667 /**
668 * Move every cursor to the bottom of the buffer.
669 * If there are multiple cursors, they will be merged into a single cursor.
670 */
671 moveToBottom(): void;
672
673 /** Move every cursor to the beginning of the next word. */
674 moveToBeginningOfNextWord(): void;
675
676 /** Move every cursor to the previous word boundary. */
677 moveToPreviousWordBoundary(): void;
678
679 /** Move every cursor to the next word boundary. */
680 moveToNextWordBoundary(): void;
681
682 /** Move every cursor to the previous subword boundary. */
683 moveToPreviousSubwordBoundary(): void;
684
685 /** Move every cursor to the next subword boundary. */
686 moveToNextSubwordBoundary(): void;
687
688 /** Move every cursor to the beginning of the next paragraph. */
689 moveToBeginningOfNextParagraph(): void;
690
691 /** Move every cursor to the beginning of the previous paragraph. */
692 moveToBeginningOfPreviousParagraph(): void;
693
694 /** Returns the most recently added Cursor. */
695 getLastCursor(): Cursor;
696
697 /** Returns the word surrounding the most recently added cursor. */
698 getWordUnderCursor(options?: {
699 wordRegex?: RegExp | undefined;
700 includeNonWordCharacters?: boolean | undefined;
701 allowPrevious?: boolean | undefined;
702 }): string;
703
704 /** Get an Array of all Cursors. */
705 getCursors(): Cursor[];
706
707 /**
708 * Get all Cursors, ordered by their position in the buffer instead of the
709 * order in which they were added.
710 */
711 getCursorsOrderedByBufferPosition(): Cursor[];
712
713 // Selections
714 /** Get the selected text of the most recently added selection. */
715 getSelectedText(): string;
716
717 /** Get the Range of the most recently added selection in buffer coordinates. */
718 getSelectedBufferRange(): Range;
719
720 /**
721 * Get the Ranges of all selections in buffer coordinates.
722 * The ranges are sorted by when the selections were added. Most recent at the end.
723 */
724 getSelectedBufferRanges(): Range[];
725
726 /**
727 * Set the selected range in buffer coordinates. If there are multiple selections,
728 * they are reduced to a single selection with the given range.
729 */
730 setSelectedBufferRange(
731 bufferRange: RangeCompatible,
732 options?: { reversed?: boolean | undefined; preserveFolds?: boolean | undefined },
733 ): void;
734
735 /**
736 * Set the selected ranges in buffer coordinates. If there are multiple selections,
737 * they are replaced by new selections with the given ranges.
738 */
739 setSelectedBufferRanges(
740 bufferRanges: readonly RangeCompatible[],
741 options?: { reversed?: boolean | undefined; preserveFolds?: boolean | undefined },
742 ): void;
743
744 /** Get the Range of the most recently added selection in screen coordinates. */
745 getSelectedScreenRange(): Range;
746
747 /**
748 * Get the Ranges of all selections in screen coordinates.
749 * The ranges are sorted by when the selections were added. Most recent at the end.
750 */
751 getSelectedScreenRanges(): Range[];
752
753 /**
754 * Set the selected range in screen coordinates. If there are multiple selections,
755 * they are reduced to a single selection with the given range.
756 */
757 setSelectedScreenRange(screenRange: RangeCompatible, options?: { reversed?: boolean | undefined }): void;
758
759 /**
760 * Set the selected ranges in screen coordinates. If there are multiple selections,
761 * they are replaced by new selections with the given ranges.
762 */
763 setSelectedScreenRanges(
764 screenRanges: readonly RangeCompatible[],
765 options?: { reversed?: boolean | undefined },
766 ): void;
767
768 /** Add a selection for the given range in buffer coordinates. */
769 addSelectionForBufferRange(
770 bufferRange: RangeCompatible,
771 options?: { reversed?: boolean | undefined; preserveFolds?: boolean | undefined },
772 ): Selection;
773
774 /** Add a selection for the given range in screen coordinates. */
775 addSelectionForScreenRange(
776 screenRange: RangeCompatible,
777 options?: { reversed?: boolean | undefined; preserveFolds?: boolean | undefined },
778 ): Selection;
779
780 /**
781 * Select from the current cursor position to the given position in buffer coordinates.
782 * This method may merge selections that end up intersecting.
783 */
784 selectToBufferPosition(position: PointCompatible): void;
785
786 /**
787 * Select from the current cursor position to the given position in screen coordinates.
788 * This method may merge selections that end up intersecting.
789 */
790 selectToScreenPosition(position: PointCompatible): void;
791
792 /**
793 * Move the cursor of each selection one character upward while preserving the
794 * selection's tail position.
795 * This method may merge selections that end up intersecting.
796 */
797 selectUp(rowCount?: number): void;
798
799 /**
800 * Move the cursor of each selection one character downward while preserving
801 * the selection's tail position.
802 * This method may merge selections that end up intersecting.
803 */
804 selectDown(rowCount?: number): void;
805
806 /**
807 * Move the cursor of each selection one character leftward while preserving
808 * the selection's tail position.
809 * This method may merge selections that end up intersecting.
810 */
811 selectLeft(columnCount?: number): void;
812
813 /**
814 * Move the cursor of each selection one character rightward while preserving
815 * the selection's tail position.
816 * This method may merge selections that end up intersecting.
817 */
818 selectRight(columnCount?: number): void;
819
820 /**
821 * Select from the top of the buffer to the end of the last selection in the buffer.
822 * This method merges multiple selections into a single selection.
823 */
824 selectToTop(): void;
825
826 /**
827 * Selects from the top of the first selection in the buffer to the end of the buffer.
828 * This method merges multiple selections into a single selection.
829 */
830 selectToBottom(): void;
831
832 /**
833 * Select all text in the buffer.
834 * This method merges multiple selections into a single selection.
835 */
836 selectAll(): void;
837
838 /**
839 * Move the cursor of each selection to the beginning of its line while preserving
840 * the selection's tail position.
841 * This method may merge selections that end up intersecting.
842 */
843 selectToBeginningOfLine(): void;
844
845 /**
846 * Move the cursor of each selection to the first non-whitespace character of its
847 * line while preserving the selection's tail position. If the cursor is already
848 * on the first character of the line, move it to the beginning of the line.
849 * This method may merge selections that end up intersecting.
850 */
851 selectToFirstCharacterOfLine(): void;
852
853 /**
854 * Move the cursor of each selection to the end of its line while preserving the
855 * selection's tail position.
856 * This method may merge selections that end up intersecting.
857 */
858 selectToEndOfLine(): void;
859
860 /**
861 * Expand selections to the beginning of their containing word.
862 * Operates on all selections. Moves the cursor to the beginning of the containing
863 * word while preserving the selection's tail position.
864 */
865 selectToBeginningOfWord(): void;
866
867 /**
868 * Expand selections to the end of their containing word.
869 * Operates on all selections. Moves the cursor to the end of the containing word
870 * while preserving the selection's tail position.
871 */
872 selectToEndOfWord(): void;
873
874 /**
875 * For each cursor, select the containing line.
876 * This method merges selections on successive lines.
877 */
878 selectLinesContainingCursors(): void;
879
880 /** Select the word surrounding each cursor. */
881 selectWordsContainingCursors(): void;
882
883 /**
884 * For each selection, move its cursor to the preceding subword boundary while
885 * maintaining the selection's tail position.
886 * This method may merge selections that end up intersecting.
887 */
888 selectToPreviousSubwordBoundary(): void;
889
890 /**
891 * For each selection, move its cursor to the next subword boundary while maintaining
892 * the selection's tail position.
893 * This method may merge selections that end up intersecting.
894 */
895 selectToNextSubwordBoundary(): void;
896
897 /**
898 * For each selection, move its cursor to the preceding word boundary while
899 * maintaining the selection's tail position.
900 * This method may merge selections that end up intersecting.
901 */
902 selectToPreviousWordBoundary(): void;
903
904 /**
905 * For each selection, move its cursor to the next word boundary while maintaining
906 * the selection's tail position.
907 * This method may merge selections that end up intersecting.
908 */
909 selectToNextWordBoundary(): void;
910
911 /**
912 * Expand selections to the beginning of the next word.
913 * Operates on all selections. Moves the cursor to the beginning of the next word
914 * while preserving the selection's tail position.
915 */
916 selectToBeginningOfNextWord(): void;
917
918 /**
919 * Expand selections to the beginning of the next paragraph.
920 * Operates on all selections. Moves the cursor to the beginning of the next
921 * paragraph while preserving the selection's tail position.
922 */
923 selectToBeginningOfNextParagraph(): void;
924
925 /**
926 * Expand selections to the beginning of the next paragraph.
927 * Operates on all selections. Moves the cursor to the beginning of the next
928 * paragraph while preserving the selection's tail position.
929 */
930 selectToBeginningOfPreviousParagraph(): void;
931
932 /** For each selection, select the syntax node that contains that selection. */
933 selectLargerSyntaxNode(): void;
934
935 /** Undo the effect a preceding call to `::selectLargerSyntaxNode`. */
936 selectSmallerSyntaxNode(): void;
937
938 /** Select the range of the given marker if it is valid. */
939 selectMarker(marker: DisplayMarker): Range | undefined;
940
941 /** Get the most recently added Selection. */
942 getLastSelection(): Selection;
943
944 /** Get current Selections. */
945 getSelections(): Selection[];
946
947 /**
948 * Get all Selections, ordered by their position in the buffer instead of the
949 * order in which they were added.
950 */
951 getSelectionsOrderedByBufferPosition(): Selection[];
952
953 // NOTE: this calls into Selection::intersectsBufferRange, which itself calls
954 // into Range::intersectsWith. Range::intersectsWith is one of the few functions
955 // which does NOT take a range-compatible array.
956 /** Determine if a given range in buffer coordinates intersects a selection. */
957 selectionIntersectsBufferRange(bufferRange: RangeLike): boolean;
958
959 // Searching and Replacing
960 /**
961 * Scan regular expression matches in the entire buffer, calling the given
962 * iterator function on each match.
963 *
964 * ::scan functions as the replace method as well via the replace.
965 */
966 scan(regex: RegExp, options: ScanContextOptions, iterator: (params: ContextualBufferScanResult) => void): void;
967 /**
968 * Scan regular expression matches in the entire buffer, calling the given
969 * iterator function on each match.
970 *
971 * ::scan functions as the replace method as well via the replace.
972 */
973 scan(regex: RegExp, iterator: (params: BufferScanResult) => void): void;
974
975 /**
976 * Scan regular expression matches in a given range, calling the given iterator.
977 * function on each match.
978 */
979 scanInBufferRange(regex: RegExp, range: RangeCompatible, iterator: (params: BufferScanResult) => void): void;
980
981 /**
982 * Scan regular expression matches in a given range in reverse order, calling the
983 * given iterator function on each match.
984 */
985 backwardsScanInBufferRange(
986 regex: RegExp,
987 range: RangeCompatible,
988 iterator: (params: BufferScanResult) => void,
989 ): void;
990
991 // Tab Behavior
992 /** Returns a boolean indicating whether softTabs are enabled for this editor. */
993 getSoftTabs(): boolean;
994
995 /** Enable or disable soft tabs for this editor. */
996 setSoftTabs(softTabs: boolean): void;
997
998 /** Toggle soft tabs for this editor. */
999 toggleSoftTabs(): boolean;
1000
1001 /** Get the on-screen length of tab characters. */
1002 getTabLength(): number;
1003
1004 /**
1005 * Set the on-screen length of tab characters. Setting this to a number will
1006 * override the editor.tabLength setting.
1007 */
1008 setTabLength(tabLength: number): void;
1009
1010 /** Determine if the buffer uses hard or soft tabs. */
1011 usesSoftTabs(): boolean | undefined;
1012
1013 /**
1014 * Get the text representing a single level of indent.
1015 * If soft tabs are enabled, the text is composed of N spaces, where N is the
1016 * tab length. Otherwise the text is a tab character (\t).
1017 */
1018 getTabText(): string;
1019
1020 // Soft Wrap Behavior
1021 /** Determine whether lines in this editor are soft-wrapped. */
1022 isSoftWrapped(): boolean;
1023
1024 /** Enable or disable soft wrapping for this editor. */
1025 setSoftWrapped(softWrapped: boolean): boolean;
1026
1027 /** Toggle soft wrapping for this editor. */
1028 toggleSoftWrapped(): boolean;
1029
1030 /** Gets the column at which column will soft wrap. */
1031 getSoftWrapColumn(): number;
1032
1033 // Indentation
1034 /**
1035 * Get the indentation level of the given buffer row.
1036 * Determines how deeply the given row is indented based on the soft tabs and tab
1037 * length settings of this editor. Note that if soft tabs are enabled and the tab
1038 * length is 2, a row with 4 leading spaces would have an indentation level of 2.
1039 */
1040 indentationForBufferRow(bufferRow: number): number;
1041
1042 /**
1043 * Set the indentation level for the given buffer row.
1044 * Inserts or removes hard tabs or spaces based on the soft tabs and tab length settings
1045 * of this editor in order to bring it to the given indentation level. Note that if soft
1046 * tabs are enabled and the tab length is 2, a row with 4 leading spaces would have an
1047 * indentation level of 2.
1048 */
1049 setIndentationForBufferRow(
1050 bufferRow: number,
1051 newLevel: number,
1052 options?: { preserveLeadingWhitespace?: boolean | undefined },
1053 ): void;
1054
1055 /** Indent rows intersecting selections by one level. */
1056 indentSelectedRows(options?: ReadonlyEditOptions): void;
1057
1058 /** Outdent rows intersecting selections by one level. */
1059 outdentSelectedRows(options?: ReadonlyEditOptions): void;
1060
1061 /**
1062 * Get the indentation level of the given line of text.
1063 * Determines how deeply the given line is indented based on the soft tabs and tab length
1064 * settings of this editor. Note that if soft tabs are enabled and the tab length is 2,
1065 * a row with 4 leading spaces would have an indentation level of 2.
1066 */
1067 indentLevelForLine(line: string): number;
1068
1069 /** Indent rows intersecting selections based on the grammar's suggested indent level. */
1070 autoIndentSelectedRows(options?: ReadonlyEditOptions): void;
1071
1072 // Grammars
1073 /** Get the current Grammar of this editor. */
1074 getGrammar(): Grammar;
1075
1076 // Managing Syntax Scopes
1077 /**
1078 * Returns a ScopeDescriptor that includes this editor's language.
1079 * e.g. [".source.ruby"], or [".source.coffee"].
1080 */
1081 getRootScopeDescriptor(): ScopeDescriptor;
1082
1083 /** Get the syntactic scopeDescriptor for the given position in buffer coordinates. */
1084 scopeDescriptorForBufferPosition(bufferPosition: PointCompatible): ScopeDescriptor;
1085
1086 /**
1087 * Get the syntactic tree {ScopeDescriptor} for the given position in buffer
1088 * coordinates or the syntactic {ScopeDescriptor} for TextMate language mode
1089 */
1090 syntaxTreeScopeDescriptorForBufferPosition(bufferPosition: PointCompatible): ScopeDescriptor;
1091
1092 /**
1093 * Get the range in buffer coordinates of all tokens surrounding the cursor
1094 * that match the given scope selector.
1095 */
1096 bufferRangeForScopeAtCursor(scopeSelector: string): Range;
1097
1098 /** Determine if the given row is entirely a comment. */
1099 isBufferRowCommented(bufferRow: number): boolean;
1100
1101 // Clipboard Operations
1102 /** For each selection, copy the selected text. */
1103 copySelectedText(): void;
1104
1105 /** For each selection, cut the selected text. */
1106 cutSelectedText(options?: ReadonlyEditOptions): void;
1107
1108 /**
1109 * For each selection, replace the selected text with the contents of the clipboard.
1110 * If the clipboard contains the same number of selections as the current editor,
1111 * each selection will be replaced with the content of the corresponding clipboard
1112 * selection text.
1113 */
1114 pasteText(options?: TextInsertionOptions & ReadonlyEditOptions): void;
1115
1116 /**
1117 * For each selection, if the selection is empty, cut all characters of the
1118 * containing screen line following the cursor. Otherwise cut the selected text.
1119 */
1120 cutToEndOfLine(options?: ReadonlyEditOptions): void;
1121
1122 /**
1123 * For each selection, if the selection is empty, cut all characters of the
1124 * containing buffer line following the cursor. Otherwise cut the selected text.
1125 */
1126 cutToEndOfBufferLine(options?: ReadonlyEditOptions): void;
1127
1128 // Folds
1129 /**
1130 * Fold the most recent cursor's row based on its indentation level.
1131 * The fold will extend from the nearest preceding line with a lower indentation
1132 * level up to the nearest following row with a lower indentation level.
1133 */
1134 foldCurrentRow(): void;
1135
1136 /** Unfold the most recent cursor's row by one level. */
1137 unfoldCurrentRow(): void;
1138
1139 /**
1140 * Fold the given row in buffer coordinates based on its indentation level.
1141 * If the given row is foldable, the fold will begin there. Otherwise, it will
1142 * begin at the first foldable row preceding the given row.
1143 */
1144 foldBufferRow(bufferRow: number): void;
1145
1146 /** Unfold all folds containing the given row in buffer coordinates. */
1147 unfoldBufferRow(bufferRow: number): void;
1148
1149 /** For each selection, fold the rows it intersects. */
1150 foldSelectedLines(): void;
1151
1152 /** Fold all foldable lines. */
1153 foldAll(): void;
1154
1155 /** Unfold all existing folds. */
1156 unfoldAll(): void;
1157
1158 /**
1159 * Fold all foldable lines at the given indent level.
1160 * @param level A zero-indexed number.
1161 */
1162 foldAllAtIndentLevel(level: number): void;
1163
1164 /**
1165 * Determine whether the given row in buffer coordinates is foldable.
1166 * A foldable row is a row that starts a row range that can be folded.
1167 */
1168 isFoldableAtBufferRow(bufferRow: number): boolean;
1169
1170 /**
1171 * Determine whether the given row in screen coordinates is foldable.
1172 * A foldable row is a row that starts a row range that can be folded.
1173 */
1174 isFoldableAtScreenRow(bufferRow: number): boolean;
1175
1176 /** Fold the given buffer row if it isn't currently folded, and unfold it otherwise. */
1177 toggleFoldAtBufferRow(bufferRow: number): void;
1178
1179 /** Determine whether the most recently added cursor's row is folded. */
1180 isFoldedAtCursorRow(): boolean;
1181
1182 /** Determine whether the given row in buffer coordinates is folded. */
1183 isFoldedAtBufferRow(bufferRow: number): boolean;
1184
1185 /** Determine whether the given row in screen coordinates is folded. */
1186 isFoldedAtScreenRow(screenRow: number): boolean;
1187
1188 // Gutters
1189 /** Add a custom Gutter. */
1190 addGutter(options: GutterOptions): Gutter;
1191
1192 /** Get this editor's gutters. */
1193 getGutters(): Gutter[];
1194
1195 /** Get the gutter with the given name. */
1196 gutterWithName(name: string): Gutter | null;
1197
1198 // Scrolling the TextEditor
1199 /** Scroll the editor to reveal the most recently added cursor if it is off-screen. */
1200 scrollToCursorPosition(options?: { center?: boolean | undefined }): void;
1201
1202 /** Scrolls the editor to the given buffer position. */
1203 scrollToBufferPosition(bufferPosition: PointCompatible, options?: { center?: boolean | undefined }): void;
1204
1205 /** Scrolls the editor to the given screen position. */
1206 scrollToScreenPosition(screenPosition: PointCompatible, options?: { center?: boolean | undefined }): void;
1207
1208 // TextEditor Rendering
1209 /** Retrieves the rendered line height in pixels. */
1210 getLineHeightInPixels(): number;
1211
1212 /** Retrieves the greyed out placeholder of a mini editor. */
1213 getPlaceholderText(): string;
1214
1215 /**
1216 * Set the greyed out placeholder of a mini editor. Placeholder text will be
1217 * displayed when the editor has no content.
1218 */
1219 setPlaceholderText(placeholderText: string): void;
1220
1221 /** Undocumented: Buffer range for syntax scope at position */
1222 bufferRangeForScopeAtPosition(scope: string, point: PointCompatible): Range;
1223
1224 /** Undocumented: Get syntax token at buffer position */
1225 tokenForBufferPosition(pos: PointCompatible): { value: string; scopes: string[] };
1226}