1 | import { DisplayMarker, Disposable, Point, PointCompatible, Range, ScopeDescriptor } from '../index';
|
2 |
|
3 | /**
|
4 | * The Cursor class represents the little blinking line identifying where text
|
5 | * can be inserted.
|
6 | */
|
7 | export interface Cursor {
|
8 | // Event Subscription
|
9 | /** Calls your callback when the cursor has been moved. */
|
10 | onDidChangePosition(callback: (event: CursorPositionChangedEvent) => void): Disposable;
|
11 |
|
12 | /** Calls your callback when the cursor is destroyed. */
|
13 | onDidDestroy(callback: () => void): Disposable;
|
14 |
|
15 | /** Calls your callback when the cursor's visibility has changed. */
|
16 | onDidChangeVisibility(callback: (visibility: boolean) => void): Disposable;
|
17 |
|
18 | // Managing Cursor Position
|
19 | /** Moves a cursor to a given screen position. */
|
20 | setScreenPosition(screenPosition: PointCompatible, options?: { autoscroll?: boolean | undefined }): void;
|
21 |
|
22 | /** Returns the screen position of the cursor as a Point. */
|
23 | getScreenPosition(): Point;
|
24 |
|
25 | /** Moves a cursor to a given buffer position. */
|
26 | setBufferPosition(bufferPosition: PointCompatible, options?: { autoscroll?: boolean | undefined }): void;
|
27 |
|
28 | /** Returns the current buffer position as an Array. */
|
29 | getBufferPosition(): Point;
|
30 |
|
31 | /** Returns the cursor's current screen row. */
|
32 | getScreenRow(): number;
|
33 |
|
34 | /** Returns the cursor's current screen column. */
|
35 | getScreenColumn(): number;
|
36 |
|
37 | /** Retrieves the cursor's current buffer row. */
|
38 | getBufferRow(): number;
|
39 |
|
40 | /** Returns the cursor's current buffer column. */
|
41 | getBufferColumn(): number;
|
42 |
|
43 | /** Returns the cursor's current buffer row of text excluding its line ending. */
|
44 | getCurrentBufferLine(): string;
|
45 |
|
46 | /** Returns whether the cursor is at the start of a line. */
|
47 | isAtBeginningOfLine(): boolean;
|
48 |
|
49 | /** Returns whether the cursor is on the line return character. */
|
50 | isAtEndOfLine(): boolean;
|
51 |
|
52 | // Cursor Position Details
|
53 | /**
|
54 | * Returns the underlying DisplayMarker for the cursor. Useful with overlay
|
55 | * Decorations.
|
56 | */
|
57 | getMarker(): DisplayMarker;
|
58 |
|
59 | /**
|
60 | * Identifies if the cursor is surrounded by whitespace.
|
61 | * "Surrounded" here means that the character directly before and after the cursor
|
62 | * are both whitespace.
|
63 | */
|
64 | isSurroundedByWhitespace(): boolean;
|
65 |
|
66 | /** This method returns false if the character before or after the cursor is whitespace. */
|
67 | isBetweenWordAndNonWord(): boolean;
|
68 |
|
69 | /** Returns whether this cursor is between a word's start and end. */
|
70 | isInsideWord(options?: { wordRegex?: RegExp | undefined }): boolean;
|
71 |
|
72 | /** Returns the indentation level of the current line. */
|
73 | getIndentLevel(): number;
|
74 |
|
75 | /** Retrieves the scope descriptor for the cursor's current position. */
|
76 | getScopeDescriptor(): ScopeDescriptor;
|
77 |
|
78 | /** Retrieves the syntax tree scope descriptor for the cursor's current position. */
|
79 | getSyntaxTreeScopeDescriptor(): ScopeDescriptor;
|
80 |
|
81 | /**
|
82 | * Returns true if this cursor has no non-whitespace characters before its
|
83 | * current position.
|
84 | */
|
85 | hasPrecedingCharactersOnLine(): boolean;
|
86 |
|
87 | /**
|
88 | * Identifies if this cursor is the last in the TextEditor.
|
89 | * "Last" is defined as the most recently added cursor.
|
90 | */
|
91 | isLastCursor(): boolean;
|
92 |
|
93 | // Moving the Cursor
|
94 | /** Moves the cursor up one screen row. */
|
95 | moveUp(rowCount?: number, options?: { moveToEndOfSelection?: boolean | undefined }): void;
|
96 |
|
97 | /** Moves the cursor down one screen row. */
|
98 | moveDown(rowCount?: number, options?: { moveToEndOfSelection?: boolean | undefined }): void;
|
99 |
|
100 | /** Moves the cursor left one screen column. */
|
101 | moveLeft(columnCount?: number, options?: { moveToEndOfSelection?: boolean | undefined }): void;
|
102 |
|
103 | /** Moves the cursor right one screen column. */
|
104 | moveRight(columnCount?: number, options?: { moveToEndOfSelection?: boolean | undefined }): void;
|
105 |
|
106 | /** Moves the cursor to the top of the buffer. */
|
107 | moveToTop(): void;
|
108 |
|
109 | /** Moves the cursor to the bottom of the buffer. */
|
110 | moveToBottom(): void;
|
111 |
|
112 | /** Moves the cursor to the beginning of the line. */
|
113 | moveToBeginningOfScreenLine(): void;
|
114 |
|
115 | /** Moves the cursor to the beginning of the buffer line. */
|
116 | moveToBeginningOfLine(): void;
|
117 |
|
118 | /** Moves the cursor to the beginning of the first character in the line. */
|
119 | moveToFirstCharacterOfLine(): void;
|
120 |
|
121 | /** Moves the cursor to the end of the line. */
|
122 | moveToEndOfScreenLine(): void;
|
123 |
|
124 | /** Moves the cursor to the end of the buffer line. */
|
125 | moveToEndOfLine(): void;
|
126 |
|
127 | /** Moves the cursor to the beginning of the word. */
|
128 | moveToBeginningOfWord(): void;
|
129 |
|
130 | /** Moves the cursor to the end of the word. */
|
131 | moveToEndOfWord(): void;
|
132 |
|
133 | /** Moves the cursor to the beginning of the next word. */
|
134 | moveToBeginningOfNextWord(): void;
|
135 |
|
136 | /** Moves the cursor to the previous word boundary. */
|
137 | moveToPreviousWordBoundary(): void;
|
138 |
|
139 | /** Moves the cursor to the next word boundary. */
|
140 | moveToNextWordBoundary(): void;
|
141 |
|
142 | /** Moves the cursor to the previous subword boundary. */
|
143 | moveToPreviousSubwordBoundary(): void;
|
144 |
|
145 | /** Moves the cursor to the next subword boundary. */
|
146 | moveToNextSubwordBoundary(): void;
|
147 |
|
148 | /** Moves the cursor to the beginning of the buffer line, skipping all whitespace. */
|
149 | skipLeadingWhitespace(): void;
|
150 |
|
151 | /** Moves the cursor to the beginning of the next paragraph. */
|
152 | moveToBeginningOfNextParagraph(): void;
|
153 |
|
154 | /** Moves the cursor to the beginning of the previous paragraph. */
|
155 | moveToBeginningOfPreviousParagraph(): void;
|
156 |
|
157 | // Local Positions and Ranges
|
158 | /**
|
159 | * Returns buffer position of previous word boundary. It might be on the current
|
160 | * word, or the previous word.
|
161 | */
|
162 | getPreviousWordBoundaryBufferPosition(options?: { wordRegex?: RegExp | undefined }): Point;
|
163 |
|
164 | /**
|
165 | * Returns buffer position of the next word boundary. It might be on the current
|
166 | * word, or the previous word.
|
167 | */
|
168 | getNextWordBoundaryBufferPosition(options?: { wordRegex?: RegExp | undefined }): Point;
|
169 |
|
170 | /** Retrieves the buffer position of where the current word starts. */
|
171 | getBeginningOfCurrentWordBufferPosition(options?: {
|
172 | wordRegex?: RegExp | undefined;
|
173 | includeNonWordCharacters?: boolean | undefined;
|
174 | allowPrevious?: boolean | undefined;
|
175 | }): Point;
|
176 |
|
177 | /** Retrieves the buffer position of where the current word ends. */
|
178 | getEndOfCurrentWordBufferPosition(options?: { wordRegex?: RegExp | undefined; includeNonWordCharacters?: boolean | undefined }): Point;
|
179 |
|
180 | /** Retrieves the buffer position of where the next word starts. */
|
181 | getBeginningOfNextWordBufferPosition(options?: { wordRegex?: RegExp | undefined }): Point;
|
182 |
|
183 | /** Returns the buffer Range occupied by the word located under the cursor. */
|
184 | getCurrentWordBufferRange(options?: { wordRegex?: RegExp | undefined }): Range;
|
185 |
|
186 | /** Returns the buffer Range for the current line. */
|
187 | getCurrentLineBufferRange(options?: { includeNewline?: boolean | undefined }): Range;
|
188 |
|
189 | /**
|
190 | * Retrieves the range for the current paragraph.
|
191 | * A paragraph is defined as a block of text surrounded by empty lines or comments.
|
192 | */
|
193 | getCurrentParagraphBufferRange(): Range;
|
194 |
|
195 | /** Returns the characters preceding the cursor in the current word. */
|
196 | getCurrentWordPrefix(): string;
|
197 |
|
198 | // Visibility
|
199 | /** Sets whether the cursor is visible. */
|
200 | setVisible(visible: boolean): void;
|
201 |
|
202 | /** Returns the visibility of the cursor. */
|
203 | isVisible(): boolean;
|
204 |
|
205 | // Comparing to another cursor
|
206 | /**
|
207 | * Compare this cursor's buffer position to another cursor's buffer position.
|
208 | * See Point::compare for more details.
|
209 | */
|
210 | compare(otherCursor: Cursor): number;
|
211 |
|
212 | // Utilities
|
213 | /** Prevents this cursor from causing scrolling. */
|
214 | clearAutoscroll(): void;
|
215 |
|
216 | /** Deselects the current selection. */
|
217 | clearSelection(): void;
|
218 |
|
219 | /** Get the RegExp used by the cursor to determine what a "word" is. */
|
220 | wordRegExp(options?: { includeNonWordCharacters?: boolean | undefined }): RegExp;
|
221 |
|
222 | /** Get the RegExp used by the cursor to determine what a "subword" is. */
|
223 | subwordRegExp(options?: { backwards?: boolean | undefined }): RegExp;
|
224 | }
|
225 |
|
226 | export interface CursorPositionChangedEvent {
|
227 | oldBufferPosition: Point;
|
228 | oldScreenPosition: Point;
|
229 | newBufferPosition: Point;
|
230 | newScreenPosition: Point;
|
231 | textChanged: boolean;
|
232 | cursor: Cursor;
|
233 | }
|