viewEvents.ts 7.3 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

A
Alex Dima 已提交
6
import { ScrollEvent } from 'vs/base/common/scrollable';
7
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
A
Alex Dima 已提交
8 9
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
10
import { ScrollType } from 'vs/editor/common/editorCommon';
11
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';
12

A
Alex Dima 已提交
13
export const enum ViewEventType {
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
	ViewConfigurationChanged,
	ViewCursorStateChanged,
	ViewDecorationsChanged,
	ViewFlushed,
	ViewFocusChanged,
	ViewLanguageConfigurationChanged,
	ViewLineMappingChanged,
	ViewLinesChanged,
	ViewLinesDeleted,
	ViewLinesInserted,
	ViewRevealRangeRequest,
	ViewScrollChanged,
	ViewThemeChanged,
	ViewTokensChanged,
	ViewTokensColorsChanged,
	ViewZonesChanged,
A
Alex Dima 已提交
30 31
}

32
export class ViewConfigurationChangedEvent {
A
Alex Dima 已提交
33

34
	public readonly type = ViewEventType.ViewConfigurationChanged;
A
Alex Dima 已提交
35

36
	public readonly _source: ConfigurationChangedEvent;
37

38
	constructor(source: ConfigurationChangedEvent) {
A
Alex Dima 已提交
39 40 41
		this._source = source;
	}

A
renames  
Alex Dima 已提交
42
	public hasChanged(id: EditorOption): boolean {
A
Alex Dima 已提交
43
		return this._source.hasChanged(id);
A
Alex Dima 已提交
44
	}
45 46
}

47
export class ViewCursorStateChangedEvent {
48

49
	public readonly type = ViewEventType.ViewCursorStateChanged;
A
Alex Dima 已提交
50

51
	public readonly selections: Selection[];
52
	public readonly modelSelections: Selection[];
A
Alex Dima 已提交
53

54
	constructor(selections: Selection[], modelSelections: Selection[]) {
55
		this.selections = selections;
56
		this.modelSelections = modelSelections;
A
Alex Dima 已提交
57
	}
58 59
}

60
export class ViewDecorationsChangedEvent {
61

62
	public readonly type = ViewEventType.ViewDecorationsChanged;
A
Alex Dima 已提交
63

64 65 66 67 68 69 70 71 72 73 74
	readonly affectsMinimap: boolean;
	readonly affectsOverviewRuler: boolean;

	constructor(source: IModelDecorationsChangedEvent | null) {
		if (source) {
			this.affectsMinimap = source.affectsMinimap;
			this.affectsOverviewRuler = source.affectsOverviewRuler;
		} else {
			this.affectsMinimap = true;
			this.affectsOverviewRuler = true;
		}
75 76
	}
}
A
Alex Dima 已提交
77

78
export class ViewFlushedEvent {
79 80 81 82 83

	public readonly type = ViewEventType.ViewFlushed;

	constructor() {
		// Nothing to do
A
Alex Dima 已提交
84
	}
85 86
}

87
export class ViewFocusChangedEvent {
88

89
	public readonly type = ViewEventType.ViewFocusChanged;
A
Alex Dima 已提交
90

91
	public readonly isFocused: boolean;
A
Alex Dima 已提交
92

93 94
	constructor(isFocused: boolean) {
		this.isFocused = isFocused;
A
Alex Dima 已提交
95
	}
96 97
}

98 99 100 101 102
export class ViewLanguageConfigurationEvent {

	public readonly type = ViewEventType.ViewLanguageConfigurationChanged;
}

A
Alex Dima 已提交
103
export class ViewLineMappingChangedEvent {
A
Alex Dima 已提交
104

A
Alex Dima 已提交
105
	public readonly type = ViewEventType.ViewLineMappingChanged;
106

A
Alex Dima 已提交
107 108
	constructor() {
		// Nothing to do
109 110 111
	}
}

A
Alex Dima 已提交
112
export class ViewLinesChangedEvent {
113

A
Alex Dima 已提交
114
	public readonly type = ViewEventType.ViewLinesChanged;
115

A
Alex Dima 已提交
116 117 118 119 120 121 122 123 124 125 126 127
	/**
	 * The first line that has changed.
	 */
	public readonly fromLineNumber: number;
	/**
	 * The last line that has changed.
	 */
	public readonly toLineNumber: number;

	constructor(fromLineNumber: number, toLineNumber: number) {
		this.fromLineNumber = fromLineNumber;
		this.toLineNumber = toLineNumber;
128 129 130
	}
}

131
export class ViewLinesDeletedEvent {
132 133 134

	public readonly type = ViewEventType.ViewLinesDeleted;

135
	/**
136
	 * At what line the deletion began (inclusive).
137
	 */
138
	public readonly fromLineNumber: number;
139
	/**
140
	 * At what line the deletion stopped (inclusive).
141
	 */
142
	public readonly toLineNumber: number;
A
Alex Dima 已提交
143

144 145 146
	constructor(fromLineNumber: number, toLineNumber: number) {
		this.fromLineNumber = fromLineNumber;
		this.toLineNumber = toLineNumber;
A
Alex Dima 已提交
147
	}
148 149
}

150
export class ViewLinesInsertedEvent {
151

152
	public readonly type = ViewEventType.ViewLinesInserted;
A
Alex Dima 已提交
153

154
	/**
155
	 * Before what line did the insertion begin
156
	 */
157
	public readonly fromLineNumber: number;
158
	/**
159
	 * `toLineNumber` - `fromLineNumber` + 1 denotes the number of lines that were inserted
160
	 */
161
	public readonly toLineNumber: number;
A
Alex Dima 已提交
162

163 164 165
	constructor(fromLineNumber: number, toLineNumber: number) {
		this.fromLineNumber = fromLineNumber;
		this.toLineNumber = toLineNumber;
A
Alex Dima 已提交
166
	}
167 168
}

169 170 171 172 173
export const enum VerticalRevealType {
	Simple = 0,
	Center = 1,
	CenterIfOutsideViewport = 2,
	Top = 3,
174
	Bottom = 4,
175
	NearTop = 5,
176
	NearTopIfOutsideViewport = 6,
177 178
}

179
export class ViewRevealRangeRequestEvent {
180

A
Alex Dima 已提交
181
	public readonly type = ViewEventType.ViewRevealRangeRequest;
A
Alex Dima 已提交
182

183 184 185
	/**
	 * Range to be reavealed.
	 */
186 187 188 189 190 191
	public readonly range: Range | null;

	/**
	 * Selections to be revealed.
	 */
	public readonly selections: Selection[] | null;
192

A
Alex Dima 已提交
193
	public readonly verticalType: VerticalRevealType;
194 195 196 197
	/**
	 * If true: there should be a horizontal & vertical revealing
	 * If false: there should be just a vertical revealing
	 */
A
Alex Dima 已提交
198 199
	public readonly revealHorizontal: boolean;

200 201
	public readonly scrollType: ScrollType;

202 203 204
	/**
	 * Source of the call that caused the event.
	 */
A
Alex Dima 已提交
205
	readonly source: string | null | undefined;
206

A
Alex Dima 已提交
207
	constructor(source: string | null | undefined, range: Range | null, selections: Selection[] | null, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: ScrollType) {
208
		this.source = source;
A
Alex Dima 已提交
209
		this.range = range;
210
		this.selections = selections;
A
Alex Dima 已提交
211 212
		this.verticalType = verticalType;
		this.revealHorizontal = revealHorizontal;
213
		this.scrollType = scrollType;
A
Alex Dima 已提交
214
	}
215 216
}

217
export class ViewScrollChangedEvent {
A
Alex Dima 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

	public readonly type = ViewEventType.ViewScrollChanged;

	public readonly scrollWidth: number;
	public readonly scrollLeft: number;
	public readonly scrollHeight: number;
	public readonly scrollTop: number;

	public readonly scrollWidthChanged: boolean;
	public readonly scrollLeftChanged: boolean;
	public readonly scrollHeightChanged: boolean;
	public readonly scrollTopChanged: boolean;

	constructor(source: ScrollEvent) {
		this.scrollWidth = source.scrollWidth;
		this.scrollLeft = source.scrollLeft;
		this.scrollHeight = source.scrollHeight;
		this.scrollTop = source.scrollTop;

		this.scrollWidthChanged = source.scrollWidthChanged;
		this.scrollLeftChanged = source.scrollLeftChanged;
		this.scrollHeightChanged = source.scrollHeightChanged;
		this.scrollTopChanged = source.scrollTopChanged;
	}
}

244 245 246 247 248
export class ViewThemeChangedEvent {

	public readonly type = ViewEventType.ViewThemeChanged;
}

249
export class ViewTokensChangedEvent {
A
Alex Dima 已提交
250

251
	public readonly type = ViewEventType.ViewTokensChanged;
A
Alex Dima 已提交
252

253 254 255 256 257 258 259 260 261 262
	public readonly ranges: {
		/**
		 * Start line number of range
		 */
		readonly fromLineNumber: number;
		/**
		 * End line number of range
		 */
		readonly toLineNumber: number;
	}[];
A
Alex Dima 已提交
263

264 265 266 267 268
	constructor(ranges: { fromLineNumber: number; toLineNumber: number; }[]) {
		this.ranges = ranges;
	}
}

269 270 271 272 273 274 275 276 277
export class ViewTokensColorsChangedEvent {

	public readonly type = ViewEventType.ViewTokensColorsChanged;

	constructor() {
		// Nothing to do
	}
}

278
export class ViewZonesChangedEvent {
279 280 281 282 283

	public readonly type = ViewEventType.ViewZonesChanged;

	constructor() {
		// Nothing to do
A
Alex Dima 已提交
284
	}
285
}
286 287 288

export type ViewEvent = (
	ViewConfigurationChangedEvent
289
	| ViewCursorStateChangedEvent
290 291 292
	| ViewDecorationsChangedEvent
	| ViewFlushedEvent
	| ViewFocusChangedEvent
293
	| ViewLanguageConfigurationEvent
294
	| ViewLineMappingChangedEvent
295
	| ViewLinesChangedEvent
296 297 298 299
	| ViewLinesDeletedEvent
	| ViewLinesInsertedEvent
	| ViewRevealRangeRequestEvent
	| ViewScrollChangedEvent
300
	| ViewThemeChangedEvent
301
	| ViewTokensChangedEvent
302
	| ViewTokensColorsChangedEvent
303 304
	| ViewZonesChangedEvent
);