Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/viewEvents.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 { ScrollEvent } from '../../base/common/scrollable.js';
7
import { ConfigurationChangedEvent, EditorOption } from './config/editorOptions.js';
8
import { Range } from './core/range.js';
9
import { Selection } from './core/selection.js';
10
import { CursorChangeReason } from './cursorEvents.js';
11
import { ScrollType } from './editorCommon.js';
12
import { IModelDecorationsChangedEvent } from './textModelEvents.js';
13
import { IColorTheme } from '../../platform/theme/common/themeService.js';
14
15
export const enum ViewEventType {
16
ViewCompositionStart,
17
ViewCompositionEnd,
18
ViewConfigurationChanged,
19
ViewCursorStateChanged,
20
ViewDecorationsChanged,
21
ViewFlushed,
22
ViewFocusChanged,
23
ViewLanguageConfigurationChanged,
24
ViewLineMappingChanged,
25
ViewLinesChanged,
26
ViewLinesDeleted,
27
ViewLinesInserted,
28
ViewRevealRangeRequest,
29
ViewScrollChanged,
30
ViewThemeChanged,
31
ViewTokensChanged,
32
ViewTokensColorsChanged,
33
ViewZonesChanged,
34
}
35
36
export class ViewCompositionStartEvent {
37
public readonly type = ViewEventType.ViewCompositionStart;
38
constructor() { }
39
}
40
41
export class ViewCompositionEndEvent {
42
public readonly type = ViewEventType.ViewCompositionEnd;
43
constructor() { }
44
}
45
46
export class ViewConfigurationChangedEvent {
47
48
public readonly type = ViewEventType.ViewConfigurationChanged;
49
50
public readonly _source: ConfigurationChangedEvent;
51
52
constructor(source: ConfigurationChangedEvent) {
53
this._source = source;
54
}
55
56
public hasChanged(id: EditorOption): boolean {
57
return this._source.hasChanged(id);
58
}
59
}
60
61
export class ViewCursorStateChangedEvent {
62
63
public readonly type = ViewEventType.ViewCursorStateChanged;
64
65
constructor(
66
public readonly selections: Selection[],
67
public readonly modelSelections: Selection[],
68
public readonly reason: CursorChangeReason
69
) { }
70
}
71
72
export class ViewDecorationsChangedEvent {
73
74
public readonly type = ViewEventType.ViewDecorationsChanged;
75
76
readonly affectsMinimap: boolean;
77
readonly affectsOverviewRuler: boolean;
78
readonly affectsGlyphMargin: boolean;
79
readonly affectsLineNumber: boolean;
80
81
constructor(source: IModelDecorationsChangedEvent | null) {
82
if (source) {
83
this.affectsMinimap = source.affectsMinimap;
84
this.affectsOverviewRuler = source.affectsOverviewRuler;
85
this.affectsGlyphMargin = source.affectsGlyphMargin;
86
this.affectsLineNumber = source.affectsLineNumber;
87
} else {
88
this.affectsMinimap = true;
89
this.affectsOverviewRuler = true;
90
this.affectsGlyphMargin = true;
91
this.affectsLineNumber = true;
92
}
93
}
94
}
95
96
export class ViewFlushedEvent {
97
98
public readonly type = ViewEventType.ViewFlushed;
99
100
constructor() {
101
// Nothing to do
102
}
103
}
104
105
export class ViewFocusChangedEvent {
106
107
public readonly type = ViewEventType.ViewFocusChanged;
108
109
public readonly isFocused: boolean;
110
111
constructor(isFocused: boolean) {
112
this.isFocused = isFocused;
113
}
114
}
115
116
export class ViewLanguageConfigurationEvent {
117
118
public readonly type = ViewEventType.ViewLanguageConfigurationChanged;
119
}
120
121
export class ViewLineMappingChangedEvent {
122
123
public readonly type = ViewEventType.ViewLineMappingChanged;
124
125
constructor() {
126
// Nothing to do
127
}
128
}
129
130
export class ViewLinesChangedEvent {
131
132
public readonly type = ViewEventType.ViewLinesChanged;
133
134
constructor(
135
/**
136
* The first line that has changed.
137
*/
138
public readonly fromLineNumber: number,
139
/**
140
* The number of lines that have changed.
141
*/
142
public readonly count: number,
143
) { }
144
}
145
146
export class ViewLinesDeletedEvent {
147
148
public readonly type = ViewEventType.ViewLinesDeleted;
149
150
/**
151
* At what line the deletion began (inclusive).
152
*/
153
public readonly fromLineNumber: number;
154
/**
155
* At what line the deletion stopped (inclusive).
156
*/
157
public readonly toLineNumber: number;
158
159
constructor(fromLineNumber: number, toLineNumber: number) {
160
this.fromLineNumber = fromLineNumber;
161
this.toLineNumber = toLineNumber;
162
}
163
}
164
165
export class ViewLinesInsertedEvent {
166
167
public readonly type = ViewEventType.ViewLinesInserted;
168
169
/**
170
* Before what line did the insertion begin
171
*/
172
public readonly fromLineNumber: number;
173
/**
174
* `toLineNumber` - `fromLineNumber` + 1 denotes the number of lines that were inserted
175
*/
176
public readonly toLineNumber: number;
177
178
constructor(fromLineNumber: number, toLineNumber: number) {
179
this.fromLineNumber = fromLineNumber;
180
this.toLineNumber = toLineNumber;
181
}
182
}
183
184
export const enum VerticalRevealType {
185
Simple = 0,
186
Center = 1,
187
CenterIfOutsideViewport = 2,
188
Top = 3,
189
Bottom = 4,
190
NearTop = 5,
191
NearTopIfOutsideViewport = 6,
192
}
193
194
export class ViewRevealRangeRequestEvent {
195
196
public readonly type = ViewEventType.ViewRevealRangeRequest;
197
198
199
constructor(
200
/**
201
* Source of the call that caused the event.
202
*/
203
public readonly source: string | null | undefined,
204
/**
205
* Reduce the revealing to a minimum (e.g. avoid scrolling if the bounding box is visible and near the viewport edge).
206
*/
207
public readonly minimalReveal: boolean,
208
/**
209
* Range to be reavealed.
210
*/
211
public readonly range: Range | null,
212
/**
213
* Selections to be revealed.
214
*/
215
public readonly selections: Selection[] | null,
216
/**
217
* The vertical reveal strategy.
218
*/
219
public readonly verticalType: VerticalRevealType,
220
/**
221
* If true: there should be a horizontal & vertical revealing.
222
* If false: there should be just a vertical revealing.
223
*/
224
public readonly revealHorizontal: boolean,
225
/**
226
* The scroll type.
227
*/
228
public readonly scrollType: ScrollType
229
) { }
230
}
231
232
export class ViewScrollChangedEvent {
233
234
public readonly type = ViewEventType.ViewScrollChanged;
235
236
public readonly scrollWidth: number;
237
public readonly scrollLeft: number;
238
public readonly scrollHeight: number;
239
public readonly scrollTop: number;
240
241
public readonly scrollWidthChanged: boolean;
242
public readonly scrollLeftChanged: boolean;
243
public readonly scrollHeightChanged: boolean;
244
public readonly scrollTopChanged: boolean;
245
246
constructor(source: ScrollEvent) {
247
this.scrollWidth = source.scrollWidth;
248
this.scrollLeft = source.scrollLeft;
249
this.scrollHeight = source.scrollHeight;
250
this.scrollTop = source.scrollTop;
251
252
this.scrollWidthChanged = source.scrollWidthChanged;
253
this.scrollLeftChanged = source.scrollLeftChanged;
254
this.scrollHeightChanged = source.scrollHeightChanged;
255
this.scrollTopChanged = source.scrollTopChanged;
256
}
257
}
258
259
export class ViewThemeChangedEvent {
260
261
public readonly type = ViewEventType.ViewThemeChanged;
262
263
constructor(
264
public readonly theme: IColorTheme
265
) { }
266
}
267
268
export class ViewTokensChangedEvent {
269
270
public readonly type = ViewEventType.ViewTokensChanged;
271
272
public readonly ranges: {
273
/**
274
* Start line number of range
275
*/
276
readonly fromLineNumber: number;
277
/**
278
* End line number of range
279
*/
280
readonly toLineNumber: number;
281
}[];
282
283
constructor(ranges: { fromLineNumber: number; toLineNumber: number }[]) {
284
this.ranges = ranges;
285
}
286
}
287
288
export class ViewTokensColorsChangedEvent {
289
290
public readonly type = ViewEventType.ViewTokensColorsChanged;
291
292
constructor() {
293
// Nothing to do
294
}
295
}
296
297
export class ViewZonesChangedEvent {
298
299
public readonly type = ViewEventType.ViewZonesChanged;
300
301
constructor() {
302
// Nothing to do
303
}
304
}
305
306
export type ViewEvent = (
307
ViewCompositionStartEvent
308
| ViewCompositionEndEvent
309
| ViewConfigurationChangedEvent
310
| ViewCursorStateChangedEvent
311
| ViewDecorationsChangedEvent
312
| ViewFlushedEvent
313
| ViewFocusChangedEvent
314
| ViewLanguageConfigurationEvent
315
| ViewLineMappingChangedEvent
316
| ViewLinesChangedEvent
317
| ViewLinesDeletedEvent
318
| ViewLinesInsertedEvent
319
| ViewRevealRangeRequestEvent
320
| ViewScrollChangedEvent
321
| ViewThemeChangedEvent
322
| ViewTokensChangedEvent
323
| ViewTokensColorsChangedEvent
324
| ViewZonesChangedEvent
325
);
326
327