UNPKG

7.93 kBTypeScriptView Raw
1import { Disposable } from '../../../index';
2import {
3 CopyMarkerOptions,
4 FindDisplayMarkerOptions,
5 Point,
6 PointCompatible,
7 Range,
8 RangeCompatible,
9} from './text-buffer';
10
11/**
12 * Represents a buffer annotation that remains logically stationary even as the
13 * buffer changes. This is used to represent cursors, folds, snippet targets,
14 * misspelled words, and anything else that needs to track a logical location
15 * in the buffer over time.
16 */
17export interface DisplayMarker {
18 // Construction and Destruction
19 /**
20 * Destroys the marker, causing it to emit the 'destroyed' event. Once destroyed,
21 * a marker cannot be restored by undo/redo operations.
22 */
23 destroy(): void;
24
25 /** Creates and returns a new DisplayMarker with the same properties as this marker. */
26 copy(options?: CopyMarkerOptions): DisplayMarker;
27
28 // Event Subscription
29 /** Invoke the given callback when the state of the marker changes. */
30 onDidChange(callback: (event: DisplayMarkerChangedEvent) => void): Disposable;
31
32 /** Invoke the given callback when the marker is destroyed. */
33 onDidDestroy(callback: () => void): Disposable;
34
35 // TextEditorMarker Details
36 /**
37 * Returns a boolean indicating whether the marker is valid. Markers can be
38 * invalidated when a region surrounding them in the buffer is changed.
39 */
40 isValid(): boolean;
41
42 /**
43 * Returns a boolean indicating whether the marker has been destroyed. A marker
44 * can be invalid without being destroyed, in which case undoing the invalidating
45 * operation would restore the marker.
46 */
47 isDestroyed(): boolean;
48
49 /** Returns a boolean indicating whether the head precedes the tail. */
50 isReversed(): boolean;
51
52 /**
53 * Returns a boolean indicating whether changes that occur exactly at the marker's
54 * head or tail cause it to move.
55 */
56 isExclusive(): boolean;
57
58 /**
59 * Get the invalidation strategy for this marker.
60 * Valid values include: never, surround, overlap, inside, and touch.
61 */
62 getInvalidationStrategy(): string;
63
64 /** Returns an Object containing any custom properties associated with the marker. */
65 getProperties(): object;
66
67 /** Merges an Object containing new properties into the marker's existing properties. */
68 setProperties(properties: object): void;
69
70 /** Returns whether this marker matches the given parameters. */
71 matchesProperties(attributes: FindDisplayMarkerOptions): boolean;
72
73 // Comparing to other markers
74 /** Compares this marker to another based on their ranges. */
75 compare(other: DisplayMarker): number;
76
77 /**
78 * Returns a boolean indicating whether this marker is equivalent to another
79 * marker, meaning they have the same range and options.
80 */
81 isEqual(other: DisplayMarker): boolean;
82
83 // Managing the marker's range
84 /** Gets the buffer range of this marker. */
85 getBufferRange(): Range;
86
87 /** Gets the screen range of this marker. */
88 getScreenRange(): Range;
89
90 /** Modifies the buffer range of this marker. */
91 setBufferRange(bufferRange: RangeCompatible, properties?: { reversed: boolean }): void;
92
93 /** Modifies the screen range of this marker. */
94 setScreenRange(
95 screenRange: RangeCompatible,
96 options?: { reversed?: boolean | undefined; clipDirection?: 'backward' | 'forward' | 'closest' | undefined },
97 ): void;
98
99 /**
100 * Retrieves the screen position of the marker's start. This will always be
101 * less than or equal to the result of DisplayMarker::getEndScreenPosition.
102 */
103 getStartScreenPosition(options?: { clipDirection: 'backward' | 'forward' | 'closest' }): Point;
104
105 /**
106 * Retrieves the screen position of the marker's end. This will always be
107 * greater than or equal to the result of DisplayMarker::getStartScreenPosition.
108 */
109 getEndScreenPosition(options?: { clipDirection: 'backward' | 'forward' | 'closest' }): Point;
110
111 /** Retrieves the buffer position of the marker's head. */
112 getHeadBufferPosition(): Point;
113
114 /** Sets the buffer position of the marker's head. */
115 setHeadBufferPosition(bufferPosition: PointCompatible): void;
116
117 /** Retrieves the screen position of the marker's head. */
118 getHeadScreenPosition(options?: { clipDirection: 'backward' | 'forward' | 'closest' }): Point;
119
120 /** Sets the screen position of the marker's head. */
121 setHeadScreenPosition(
122 screenPosition: PointCompatible,
123 options?: { clipDirection: 'backward' | 'forward' | 'closest' },
124 ): void;
125
126 /** Retrieves the buffer position of the marker's tail. */
127 getTailBufferPosition(): Point;
128
129 /** Sets the buffer position of the marker's tail. */
130 setTailBufferPosition(bufferPosition: PointCompatible): void;
131
132 /** Retrieves the screen position of the marker's tail. */
133 getTailScreenPosition(options?: { clipDirection: 'backward' | 'forward' | 'closest' }): Point;
134
135 /** Sets the screen position of the marker's tail. */
136 setTailScreenPosition(
137 screenPosition: PointCompatible,
138 options?: { clipDirection: 'backward' | 'forward' | 'closest' },
139 ): void;
140
141 /**
142 * Retrieves the buffer position of the marker's start. This will always be less
143 * than or equal to the result of DisplayMarker::getEndBufferPosition.
144 */
145 getStartBufferPosition(): Point;
146
147 /**
148 * Retrieves the buffer position of the marker's end. This will always be greater
149 * than or equal to the result of DisplayMarker::getStartBufferPosition.
150 */
151 getEndBufferPosition(): Point;
152
153 /** Returns a boolean indicating whether the marker has a tail. */
154 hasTail(): boolean;
155
156 /**
157 * Plants the marker's tail at the current head position. After calling the
158 * marker's tail position will be its head position at the time of the call,
159 * regardless of where the marker's head is moved.
160 */
161 plantTail(): void;
162
163 /**
164 * Removes the marker's tail. After calling the marker's head position will be
165 * reported as its current tail position until the tail is planted again.
166 */
167 clearTail(): void;
168}
169
170export interface DisplayMarkerChangedEvent {
171 /** Point representing the former head buffer position. */
172 oldHeadBufferPosition: Point;
173
174 /** Point representing the new head buffer position. */
175 newHeadBufferPosition: Point;
176
177 // Point representing the former tail buffer position. */
178 oldTailBufferPosition: Point;
179
180 /** Point representing the new tail buffer position. */
181 newTailBufferPosition: Point;
182
183 /** Point representing the former head screen position. */
184 oldHeadScreenPosition: Point;
185
186 /** Point representing the new head screen position. */
187 newHeadScreenPosition: Point;
188
189 /** Point representing the former tail screen position. */
190 oldTailScreenPosition: Point;
191
192 /** Point representing the new tail screen position. */
193 newTailScreenPosition: Point;
194
195 /** Boolean indicating whether the marker was valid before the change. */
196 wasValid: boolean;
197
198 /** Boolean indicating whether the marker is now valid. */
199 isValid: boolean;
200
201 /** Boolean indicating whether the marker had a tail before the change. */
202 hadTail: boolean;
203
204 /** Boolean indicating whether the marker now has a tail */
205 hasTail: boolean;
206
207 /**
208 * -DEPRECATED- Object containing the marker's custom properties before the change.
209 * @deprecated
210 */
211 oldProperties: object;
212
213 /**
214 * -DEPRECATED- Object containing the marker's custom properties after the change.
215 * @deprecated
216 */
217 newProperties: object;
218
219 /**
220 * Boolean indicating whether this change was caused by a textual change to the
221 * buffer or whether the marker was manipulated directly via its public API.
222 */
223 textChanged: boolean;
224}