codeEditorWidget.ts 68.8 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import 'vs/css!./media/editor';
import 'vs/css!./media/tokens';
A
Alex Dima 已提交
8 9
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
A
Alex Dima 已提交
10 11 12
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { Color } from 'vs/base/common/color';
J
Johannes Rieken 已提交
13
import { onUnexpectedError } from 'vs/base/common/errors';
A
Alex Dima 已提交
14 15
import { Emitter, Event } from 'vs/base/common/event';
import { hash } from 'vs/base/common/hash';
A
Alex Dima 已提交
16
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
17
import { Schemas } from 'vs/base/common/network';
J
Johannes Rieken 已提交
18
import { Configuration } from 'vs/editor/browser/config/configuration';
A
Alex Dima 已提交
19 20 21 22 23 24 25 26
import { CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { EditorExtensionsRegistry, IEditorContributionCtor } from 'vs/editor/browser/editorExtensions';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICommandDelegate } from 'vs/editor/browser/view/viewController';
import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
A
Alex Dima 已提交
27
import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor';
A
Alex Dima 已提交
28
import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon';
A
Alex Dima 已提交
29
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
A
Alex Dima 已提交
30 31 32 33 34
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { ISelection, Selection } from 'vs/editor/common/core/selection';
import { InternalEditorAction } from 'vs/editor/common/editorAction';
import * as editorCommon from 'vs/editor/common/editorCommon';
A
Alex Dima 已提交
35
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
A
Alex Dima 已提交
36 37
import { EndOfLinePreference, IIdentifiedSingleEditOperation, IModelDecoration, IModelDecorationOptions, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { ClassName } from 'vs/editor/common/model/intervalTree';
A
Alex Dima 已提交
38
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
A
Alex Dima 已提交
39
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent } from 'vs/editor/common/model/textModelEvents';
A
Alex Dima 已提交
40
import * as modes from 'vs/editor/common/modes';
A
Alex Dima 已提交
41 42 43 44
import { editorErrorBorder, editorErrorForeground, editorHintBorder, editorHintForeground, editorInfoBorder, editorInfoForeground, editorUnnecessaryCodeBorder, editorUnnecessaryCodeOpacity, editorWarningBorder, editorWarningForeground } from 'vs/editor/common/view/editorColorRegistry';
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
A
Alex Dima 已提交
45
import { ICommandService } from 'vs/platform/commands/common/commands';
A
Alex Dima 已提交
46 47 48 49
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { INotificationService } from 'vs/platform/notification/common/notification';
A
Alex Dima 已提交
50
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
E
Erich Gamma 已提交
51

A
Alex Dima 已提交
52 53
let EDITOR_ID = 0;

54 55
const SHOW_UNUSED_ENABLED_CLASS = 'showUnused';

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
export interface ICodeEditorWidgetOptions {
	/**
	 * Is this a simple widget (not a real code editor) ?
	 * Defaults to false.
	 */
	isSimpleWidget?: boolean;

	/**
	 * Contributions to instantiate.
	 * Defaults to EditorExtensionsRegistry.getEditorContributions().
	 */
	contributions?: IEditorContributionCtor[];

	/**
	 * Telemetry data associated with this CodeEditorWidget.
	 * Defaults to null.
	 */
	telemetryData?: object;
}

A
Alex Dima 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
class ModelData {
	public readonly model: ITextModel;
	public readonly viewModel: ViewModel;
	public readonly cursor: Cursor;
	public readonly view: View;
	public readonly hasRealView: boolean;
	public readonly listenersToRemove: IDisposable[];

	constructor(model: ITextModel, viewModel: ViewModel, cursor: Cursor, view: View, hasRealView: boolean, listenersToRemove: IDisposable[]) {
		this.model = model;
		this.viewModel = viewModel;
		this.cursor = cursor;
		this.view = view;
		this.hasRealView = hasRealView;
		this.listenersToRemove = listenersToRemove;
	}

	public dispose(): void {
		dispose(this.listenersToRemove);
		this.model.onBeforeDetached();
		if (this.hasRealView) {
			this.view.dispose();
		}
		this.cursor.dispose();
		this.viewModel.dispose();
	}
}

A
Alex Dima 已提交
104
export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeEditor {
A
Alex Dima 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

	//#region Eventing
	private readonly _onDidDispose: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidDispose: Event<void> = this._onDidDispose.event;

	private readonly _onDidChangeModelContent: Emitter<IModelContentChangedEvent> = this._register(new Emitter<IModelContentChangedEvent>());
	public readonly onDidChangeModelContent: Event<IModelContentChangedEvent> = this._onDidChangeModelContent.event;

	private readonly _onDidChangeModelLanguage: Emitter<IModelLanguageChangedEvent> = this._register(new Emitter<IModelLanguageChangedEvent>());
	public readonly onDidChangeModelLanguage: Event<IModelLanguageChangedEvent> = this._onDidChangeModelLanguage.event;

	private readonly _onDidChangeModelLanguageConfiguration: Emitter<IModelLanguageConfigurationChangedEvent> = this._register(new Emitter<IModelLanguageConfigurationChangedEvent>());
	public readonly onDidChangeModelLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent> = this._onDidChangeModelLanguageConfiguration.event;

	private readonly _onDidChangeModelOptions: Emitter<IModelOptionsChangedEvent> = this._register(new Emitter<IModelOptionsChangedEvent>());
	public readonly onDidChangeModelOptions: Event<IModelOptionsChangedEvent> = this._onDidChangeModelOptions.event;

	private readonly _onDidChangeModelDecorations: Emitter<IModelDecorationsChangedEvent> = this._register(new Emitter<IModelDecorationsChangedEvent>());
	public readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent> = this._onDidChangeModelDecorations.event;

	private readonly _onDidChangeConfiguration: Emitter<editorOptions.IConfigurationChangedEvent> = this._register(new Emitter<editorOptions.IConfigurationChangedEvent>());
	public readonly onDidChangeConfiguration: Event<editorOptions.IConfigurationChangedEvent> = this._onDidChangeConfiguration.event;

	protected readonly _onDidChangeModel: Emitter<editorCommon.IModelChangedEvent> = this._register(new Emitter<editorCommon.IModelChangedEvent>());
	public readonly onDidChangeModel: Event<editorCommon.IModelChangedEvent> = this._onDidChangeModel.event;

	private readonly _onDidChangeCursorPosition: Emitter<ICursorPositionChangedEvent> = this._register(new Emitter<ICursorPositionChangedEvent>());
	public readonly onDidChangeCursorPosition: Event<ICursorPositionChangedEvent> = this._onDidChangeCursorPosition.event;

	private readonly _onDidChangeCursorSelection: Emitter<ICursorSelectionChangedEvent> = this._register(new Emitter<ICursorSelectionChangedEvent>());
	public readonly onDidChangeCursorSelection: Event<ICursorSelectionChangedEvent> = this._onDidChangeCursorSelection.event;

	private readonly _onDidAttemptReadOnlyEdit: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidAttemptReadOnlyEdit: Event<void> = this._onDidAttemptReadOnlyEdit.event;

	private readonly _onDidLayoutChange: Emitter<editorOptions.EditorLayoutInfo> = this._register(new Emitter<editorOptions.EditorLayoutInfo>());
	public readonly onDidLayoutChange: Event<editorOptions.EditorLayoutInfo> = this._onDidLayoutChange.event;

A
Alex Dima 已提交
143
	private _editorTextFocus: BooleanEventEmitter = this._register(new BooleanEventEmitter());
A
Alex Dima 已提交
144 145 146
	public readonly onDidFocusEditorText: Event<void> = this._editorTextFocus.onDidChangeToTrue;
	public readonly onDidBlurEditorText: Event<void> = this._editorTextFocus.onDidChangeToFalse;

A
Alex Dima 已提交
147 148 149
	private _editorWidgetFocus: BooleanEventEmitter = this._register(new BooleanEventEmitter());
	public readonly onDidFocusEditorWidget: Event<void> = this._editorWidgetFocus.onDidChangeToTrue;
	public readonly onDidBlurEditorWidget: Event<void> = this._editorWidgetFocus.onDidChangeToFalse;
A
Alex Dima 已提交
150 151 152 153 154 155 156

	private readonly _onWillType: Emitter<string> = this._register(new Emitter<string>());
	public readonly onWillType = this._onWillType.event;

	private readonly _onDidType: Emitter<string> = this._register(new Emitter<string>());
	public readonly onDidType = this._onDidType.event;

J
Johannes Rieken 已提交
157 158 159 160 161 162
	private readonly _onCompositionStart: Emitter<void> = this._register(new Emitter<void>());
	public readonly onCompositionStart = this._onCompositionStart.event;

	private readonly _onCompositionEnd: Emitter<void> = this._register(new Emitter<void>());
	public readonly onCompositionEnd = this._onCompositionEnd.event;

A
Alex Dima 已提交
163 164
	private readonly _onDidPaste: Emitter<Range> = this._register(new Emitter<Range>());
	public readonly onDidPaste = this._onDidPaste.event;
E
Erich Gamma 已提交
165

A
Alex Dima 已提交
166 167 168 169 170 171 172 173 174
	private readonly _onMouseUp: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
	public readonly onMouseUp: Event<editorBrowser.IEditorMouseEvent> = this._onMouseUp.event;

	private readonly _onMouseDown: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
	public readonly onMouseDown: Event<editorBrowser.IEditorMouseEvent> = this._onMouseDown.event;

	private readonly _onMouseDrag: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
	public readonly onMouseDrag: Event<editorBrowser.IEditorMouseEvent> = this._onMouseDrag.event;

A
Alex Dima 已提交
175 176
	private readonly _onMouseDrop: Emitter<editorBrowser.IPartialEditorMouseEvent> = this._register(new Emitter<editorBrowser.IPartialEditorMouseEvent>());
	public readonly onMouseDrop: Event<editorBrowser.IPartialEditorMouseEvent> = this._onMouseDrop.event;
A
Alex Dima 已提交
177 178 179 180 181 182 183

	private readonly _onContextMenu: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
	public readonly onContextMenu: Event<editorBrowser.IEditorMouseEvent> = this._onContextMenu.event;

	private readonly _onMouseMove: Emitter<editorBrowser.IEditorMouseEvent> = this._register(new Emitter<editorBrowser.IEditorMouseEvent>());
	public readonly onMouseMove: Event<editorBrowser.IEditorMouseEvent> = this._onMouseMove.event;

A
Alex Dima 已提交
184 185
	private readonly _onMouseLeave: Emitter<editorBrowser.IPartialEditorMouseEvent> = this._register(new Emitter<editorBrowser.IPartialEditorMouseEvent>());
	public readonly onMouseLeave: Event<editorBrowser.IPartialEditorMouseEvent> = this._onMouseLeave.event;
A
Alex Dima 已提交
186 187 188 189 190 191 192 193 194 195 196 197

	private readonly _onKeyUp: Emitter<IKeyboardEvent> = this._register(new Emitter<IKeyboardEvent>());
	public readonly onKeyUp: Event<IKeyboardEvent> = this._onKeyUp.event;

	private readonly _onKeyDown: Emitter<IKeyboardEvent> = this._register(new Emitter<IKeyboardEvent>());
	public readonly onKeyDown: Event<IKeyboardEvent> = this._onKeyDown.event;

	private readonly _onDidScrollChange: Emitter<editorCommon.IScrollEvent> = this._register(new Emitter<editorCommon.IScrollEvent>());
	public readonly onDidScrollChange: Event<editorCommon.IScrollEvent> = this._onDidScrollChange.event;

	private readonly _onDidChangeViewZones: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidChangeViewZones: Event<void> = this._onDidChangeViewZones.event;
A
Alex Dima 已提交
198
	//#endregion
A
Alex Dima 已提交
199

A
Alex Dima 已提交
200
	public readonly isSimpleWidget: boolean;
M
Matt Bierner 已提交
201
	private readonly _telemetryData?: object;
202

A
Alex Dima 已提交
203 204
	private readonly _domElement: HTMLElement;
	private readonly _id: number;
A
Alex Dima 已提交
205 206
	private readonly _configuration: editorCommon.IConfiguration;

A
Alex Dima 已提交
207 208
	protected readonly _contributions: { [key: string]: editorCommon.IEditorContribution; };
	protected readonly _actions: { [key: string]: editorCommon.IEditorAction; };
A
Alex Dima 已提交
209 210

	// --- Members logically associated to a model
A
Alex Dima 已提交
211
	protected _modelData: ModelData | null;
E
Erich Gamma 已提交
212

A
Alex Dima 已提交
213 214 215 216 217 218 219
	protected readonly _instantiationService: IInstantiationService;
	protected readonly _contextKeyService: IContextKeyService;
	private readonly _notificationService: INotificationService;
	private readonly _codeEditorService: ICodeEditorService;
	private readonly _commandService: ICommandService;
	private readonly _themeService: IThemeService;

A
Alex Dima 已提交
220
	private readonly _focusTracker: CodeEditorWidgetFocusTracker;
221

A
Alex Dima 已提交
222 223
	private readonly _contentWidgets: { [key: string]: IContentWidgetData; };
	private readonly _overlayWidgets: { [key: string]: IOverlayWidgetData; };
E
Erich Gamma 已提交
224

A
Alex Dima 已提交
225 226 227 228 229
	/**
	 * map from "parent" decoration type to live decoration ids.
	 */
	private _decorationTypeKeysToIds: { [decorationTypeKey: string]: string[] };
	private _decorationTypeSubtypes: { [decorationTypeKey: string]: { [subtype: string]: boolean } };
E
Erich Gamma 已提交
230 231

	constructor(
J
Johannes Rieken 已提交
232
		domElement: HTMLElement,
A
Alex Dima 已提交
233
		options: editorOptions.IEditorOptions,
234
		codeEditorWidgetOptions: ICodeEditorWidgetOptions,
E
Erich Gamma 已提交
235 236
		@IInstantiationService instantiationService: IInstantiationService,
		@ICodeEditorService codeEditorService: ICodeEditorService,
237
		@ICommandService commandService: ICommandService,
238
		@IContextKeyService contextKeyService: IContextKeyService,
239 240
		@IThemeService themeService: IThemeService,
		@INotificationService notificationService: INotificationService
E
Erich Gamma 已提交
241
	) {
A
Alex Dima 已提交
242
		super();
A
Alex Dima 已提交
243 244
		this._domElement = domElement;
		this._id = (++EDITOR_ID);
A
Alex Dima 已提交
245 246
		this._decorationTypeKeysToIds = {};
		this._decorationTypeSubtypes = {};
247
		this.isSimpleWidget = codeEditorWidgetOptions.isSimpleWidget || false;
M
Matt Bierner 已提交
248
		this._telemetryData = codeEditorWidgetOptions.telemetryData;
A
Alex Dima 已提交
249 250 251 252 253 254 255 256 257

		options = options || {};
		this._configuration = this._register(this._createConfiguration(options));
		this._register(this._configuration.onDidChange((e) => {
			this._onDidChangeConfiguration.fire(e);

			if (e.layoutInfo) {
				this._onDidLayoutChange.fire(this._configuration.editor.layoutInfo);
			}
258
			if (this._configuration.editor.showUnused) {
A
Alex Dima 已提交
259
				this._domElement.classList.add(SHOW_UNUSED_ENABLED_CLASS);
260
			} else {
A
Alex Dima 已提交
261
				this._domElement.classList.remove(SHOW_UNUSED_ENABLED_CLASS);
262
			}
A
Alex Dima 已提交
263 264
		}));

A
Alex Dima 已提交
265
		this._contextKeyService = this._register(contextKeyService.createScoped(this._domElement));
A
Alex Dima 已提交
266
		this._notificationService = notificationService;
267
		this._codeEditorService = codeEditorService;
268
		this._commandService = commandService;
269
		this._themeService = themeService;
A
Alex Dima 已提交
270 271 272 273 274 275 276 277 278
		this._register(new EditorContextKeysManager(this, this._contextKeyService));
		this._register(new EditorModeContext(this, this._contextKeyService));

		this._instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, this._contextKeyService]));

		this._attachModel(null);

		this._contributions = {};
		this._actions = {};
E
Erich Gamma 已提交
279

280
		this._focusTracker = new CodeEditorWidgetFocusTracker(domElement);
A
Alex Dima 已提交
281
		this._focusTracker.onChange(() => {
A
Alex Dima 已提交
282
			this._editorWidgetFocus.setValue(this._focusTracker.hasFocus());
E
Erich Gamma 已提交
283 284
		});

A
Alex Dima 已提交
285 286
		this._contentWidgets = {};
		this._overlayWidgets = {};
E
Erich Gamma 已提交
287

A
Alex Dima 已提交
288 289 290 291
		let contributions: IEditorContributionCtor[];
		if (Array.isArray(codeEditorWidgetOptions.contributions)) {
			contributions = codeEditorWidgetOptions.contributions;
		} else {
292 293
			contributions = EditorExtensionsRegistry.getEditorContributions();
		}
294 295
		for (let i = 0, len = contributions.length; i < len; i++) {
			let ctor = contributions[i];
E
Erich Gamma 已提交
296
			try {
297
				let contribution = this._instantiationService.createInstance(ctor, this);
A
Alex Dima 已提交
298
				this._contributions[contribution.getId()] = contribution;
E
Erich Gamma 已提交
299
			} catch (err) {
300
				onUnexpectedError(err);
E
Erich Gamma 已提交
301 302
			}
		}
303

304
		EditorExtensionsRegistry.getEditorActions().forEach((action) => {
305 306 307 308 309
			const internalAction = new InternalEditorAction(
				action.id,
				action.label,
				action.alias,
				action.precondition,
310
				(): Promise<void> => {
311
					return this._instantiationService.invokeFunction((accessor) => {
312
						return Promise.resolve(action.runEditorCommand(accessor, this, null));
313 314 315 316
					});
				},
				this._contextKeyService
			);
A
Alex Dima 已提交
317
			this._actions[internalAction.id] = internalAction;
318
		});
319 320

		this._codeEditorService.addCodeEditor(this);
E
Erich Gamma 已提交
321 322
	}

A
Alex Dima 已提交
323
	protected _createConfiguration(options: editorOptions.IEditorOptions): editorCommon.IConfiguration {
A
Alex Dima 已提交
324
		return new Configuration(options, this._domElement);
A
Alex Dima 已提交
325 326 327
	}

	public getId(): string {
A
Alex Dima 已提交
328
		return this.getEditorType() + ':' + this._id;
A
Alex Dima 已提交
329 330 331 332
	}

	public getEditorType(): string {
		return editorCommon.EditorType.ICodeEditor;
E
Erich Gamma 已提交
333 334 335
	}

	public dispose(): void {
336 337
		this._codeEditorService.removeCodeEditor(this);

338
		this._focusTracker.dispose();
A
Alex Dima 已提交
339 340 341 342 343 344 345 346 347 348 349 350

		let keys = Object.keys(this._contributions);
		for (let i = 0, len = keys.length; i < len; i++) {
			let contributionId = keys[i];
			this._contributions[contributionId].dispose();
		}

		this._removeDecorationTypes();
		this._postDetachModelCleanup(this._detachModel());

		this._onDidDispose.fire();

E
Erich Gamma 已提交
351 352 353
		super.dispose();
	}

A
Alex Dima 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
	public invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T {
		return this._instantiationService.invokeFunction(fn);
	}

	public updateOptions(newOptions: editorOptions.IEditorOptions): void {
		this._configuration.updateOptions(newOptions);
	}

	public getConfiguration(): editorOptions.InternalEditorOptions {
		return this._configuration.editor;
	}

	public getRawConfiguration(): editorOptions.IEditorOptions {
		return this._configuration.getRawOptions();
	}

A
Alex Dima 已提交
370 371 372
	public getValue(options: { preserveBOM: boolean; lineEnding: string; } | null = null): string {
		if (!this._modelData) {
			return '';
A
Alex Dima 已提交
373
		}
A
Alex Dima 已提交
374 375 376 377 378 379 380 381 382

		let preserveBOM: boolean = (options && options.preserveBOM) ? true : false;
		let eolPreference = EndOfLinePreference.TextDefined;
		if (options && options.lineEnding && options.lineEnding === '\n') {
			eolPreference = EndOfLinePreference.LF;
		} else if (options && options.lineEnding && options.lineEnding === '\r\n') {
			eolPreference = EndOfLinePreference.CRLF;
		}
		return this._modelData.model.getValue(eolPreference, preserveBOM);
A
Alex Dima 已提交
383 384 385
	}

	public setValue(newValue: string): void {
A
Alex Dima 已提交
386 387
		if (!this._modelData) {
			return;
A
Alex Dima 已提交
388
		}
A
Alex Dima 已提交
389
		this._modelData.model.setValue(newValue);
A
Alex Dima 已提交
390 391
	}

A
Alex Dima 已提交
392 393 394 395 396
	public getModel(): ITextModel | null {
		if (!this._modelData) {
			return null;
		}
		return this._modelData.model;
A
Alex Dima 已提交
397 398
	}

A
Alex Dima 已提交
399 400
	public setModel(_model: ITextModel | editorCommon.IDiffEditorModel | null = null): void {
		const model = <ITextModel | null>_model;
A
Alex Dima 已提交
401 402 403 404 405
		if (this._modelData === null && model === null) {
			// Current model is the new model
			return;
		}
		if (this._modelData && this._modelData.model === model) {
A
Alex Dima 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
			// Current model is the new model
			return;
		}

		let detachedModel = this._detachModel();
		this._attachModel(model);

		let e: editorCommon.IModelChangedEvent = {
			oldModelUrl: detachedModel ? detachedModel.uri : null,
			newModelUrl: model ? model.uri : null
		};

		this._removeDecorationTypes();
		this._onDidChangeModel.fire(e);
		this._postDetachModelCleanup(detachedModel);
	}

	private _removeDecorationTypes(): void {
		this._decorationTypeKeysToIds = {};
		if (this._decorationTypeSubtypes) {
			for (let decorationType in this._decorationTypeSubtypes) {
				let subTypes = this._decorationTypeSubtypes[decorationType];
				for (let subType in subTypes) {
					this._removeDecorationType(decorationType + '-' + subType);
				}
			}
			this._decorationTypeSubtypes = {};
		}
	}

	public getVisibleRanges(): Range[] {
A
Alex Dima 已提交
437
		if (!this._modelData) {
A
Alex Dima 已提交
438 439
			return [];
		}
A
Alex Dima 已提交
440
		return this._modelData.viewModel.getVisibleRanges();
A
Alex Dima 已提交
441 442 443
	}

	public getWhitespaces(): IEditorWhitespace[] {
A
Alex Dima 已提交
444
		if (!this._modelData) {
A
Alex Dima 已提交
445 446
			return [];
		}
A
Alex Dima 已提交
447
		return this._modelData.viewModel.viewLayout.getWhitespaces();
A
Alex Dima 已提交
448 449
	}

A
Alex Dima 已提交
450 451
	private static _getVerticalOffsetForPosition(modelData: ModelData, modelLineNumber: number, modelColumn: number): number {
		let modelPosition = modelData.model.validatePosition({
A
Alex Dima 已提交
452 453 454
			lineNumber: modelLineNumber,
			column: modelColumn
		});
A
Alex Dima 已提交
455 456
		let viewPosition = modelData.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
		return modelData.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
A
Alex Dima 已提交
457 458 459
	}

	public getTopForLineNumber(lineNumber: number): number {
A
Alex Dima 已提交
460
		if (!this._modelData) {
A
Alex Dima 已提交
461 462
			return -1;
		}
A
Alex Dima 已提交
463
		return CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, lineNumber, 1);
A
Alex Dima 已提交
464 465 466
	}

	public getTopForPosition(lineNumber: number, column: number): number {
A
Alex Dima 已提交
467
		if (!this._modelData) {
A
Alex Dima 已提交
468 469
			return -1;
		}
A
Alex Dima 已提交
470
		return CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, lineNumber, column);
A
Alex Dima 已提交
471 472 473
	}

	public setHiddenAreas(ranges: IRange[]): void {
A
Alex Dima 已提交
474 475
		if (this._modelData) {
			this._modelData.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)));
A
Alex Dima 已提交
476 477 478 479
		}
	}

	public getVisibleColumnFromPosition(rawPosition: IPosition): number {
A
Alex Dima 已提交
480
		if (!this._modelData) {
A
Alex Dima 已提交
481 482 483
			return rawPosition.column;
		}

A
Alex Dima 已提交
484 485
		let position = this._modelData.model.validatePosition(rawPosition);
		let tabSize = this._modelData.model.getOptions().tabSize;
A
Alex Dima 已提交
486

A
Alex Dima 已提交
487
		return CursorColumns.visibleColumnFromColumn(this._modelData.model.getLineContent(position.lineNumber), position.column, tabSize) + 1;
A
Alex Dima 已提交
488 489
	}

A
Alex Dima 已提交
490 491
	public getPosition(): Position | null {
		if (!this._modelData) {
A
Alex Dima 已提交
492 493
			return null;
		}
A
Alex Dima 已提交
494
		return this._modelData.cursor.getPosition();
A
Alex Dima 已提交
495 496 497
	}

	public setPosition(position: IPosition): void {
A
Alex Dima 已提交
498
		if (!this._modelData) {
A
Alex Dima 已提交
499 500 501 502 503
			return;
		}
		if (!Position.isIPosition(position)) {
			throw new Error('Invalid arguments');
		}
A
Alex Dima 已提交
504
		this._modelData.cursor.setSelections('api', [{
A
Alex Dima 已提交
505 506 507 508 509 510 511 512
			selectionStartLineNumber: position.lineNumber,
			selectionStartColumn: position.column,
			positionLineNumber: position.lineNumber,
			positionColumn: position.column
		}]);
	}

	private _sendRevealRange(modelRange: Range, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
A
Alex Dima 已提交
513
		if (!this._modelData) {
A
Alex Dima 已提交
514 515 516 517 518
			return;
		}
		if (!Range.isIRange(modelRange)) {
			throw new Error('Invalid arguments');
		}
A
Alex Dima 已提交
519 520
		const validatedModelRange = this._modelData.model.validateRange(modelRange);
		const viewRange = this._modelData.viewModel.coordinatesConverter.convertModelRangeToViewRange(validatedModelRange);
A
Alex Dima 已提交
521

A
Alex Dima 已提交
522
		this._modelData.cursor.emitCursorRevealRange(viewRange, verticalType, revealHorizontal, scrollType);
A
Alex Dima 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	}

	public revealLine(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLine(lineNumber, VerticalRevealType.Simple, scrollType);
	}

	public revealLineInCenter(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLine(lineNumber, VerticalRevealType.Center, scrollType);
	}

	public revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLine(lineNumber, VerticalRevealType.CenterIfOutsideViewport, scrollType);
	}

	private _revealLine(lineNumber: number, revealType: VerticalRevealType, scrollType: editorCommon.ScrollType): void {
		if (typeof lineNumber !== 'number') {
			throw new Error('Invalid arguments');
		}

		this._sendRevealRange(
			new Range(lineNumber, 1, lineNumber, 1),
			revealType,
			false,
			scrollType
		);
	}

	public revealPosition(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealPosition(
			position,
			VerticalRevealType.Simple,
			true,
			scrollType
		);
	}

	public revealPositionInCenter(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealPosition(
			position,
			VerticalRevealType.Center,
			true,
			scrollType
		);
	}

	public revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealPosition(
			position,
			VerticalRevealType.CenterIfOutsideViewport,
			true,
			scrollType
		);
	}

	private _revealPosition(position: IPosition, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
		if (!Position.isIPosition(position)) {
			throw new Error('Invalid arguments');
		}

		this._sendRevealRange(
			new Range(position.lineNumber, position.column, position.lineNumber, position.column),
			verticalType,
			revealHorizontal,
			scrollType
		);
	}

A
Alex Dima 已提交
590 591
	public getSelection(): Selection | null {
		if (!this._modelData) {
A
Alex Dima 已提交
592 593
			return null;
		}
A
Alex Dima 已提交
594
		return this._modelData.cursor.getSelection();
A
Alex Dima 已提交
595 596
	}

A
Alex Dima 已提交
597 598
	public getSelections(): Selection[] | null {
		if (!this._modelData) {
A
Alex Dima 已提交
599 600
			return null;
		}
A
Alex Dima 已提交
601
		return this._modelData.cursor.getSelections();
A
Alex Dima 已提交
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
	}

	public setSelection(range: IRange): void;
	public setSelection(editorRange: Range): void;
	public setSelection(selection: ISelection): void;
	public setSelection(editorSelection: Selection): void;
	public setSelection(something: any): void {
		let isSelection = Selection.isISelection(something);
		let isRange = Range.isIRange(something);

		if (!isSelection && !isRange) {
			throw new Error('Invalid arguments');
		}

		if (isSelection) {
			this._setSelectionImpl(<ISelection>something);
		} else if (isRange) {
			// act as if it was an IRange
			let selection: ISelection = {
				selectionStartLineNumber: something.startLineNumber,
				selectionStartColumn: something.startColumn,
				positionLineNumber: something.endLineNumber,
				positionColumn: something.endColumn
			};
			this._setSelectionImpl(selection);
		}
	}

	private _setSelectionImpl(sel: ISelection): void {
A
Alex Dima 已提交
631
		if (!this._modelData) {
A
Alex Dima 已提交
632 633 634
			return;
		}
		let selection = new Selection(sel.selectionStartLineNumber, sel.selectionStartColumn, sel.positionLineNumber, sel.positionColumn);
A
Alex Dima 已提交
635
		this._modelData.cursor.setSelections('api', [selection]);
A
Alex Dima 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
	}

	public revealLines(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLines(
			startLineNumber,
			endLineNumber,
			VerticalRevealType.Simple,
			scrollType
		);
	}

	public revealLinesInCenter(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLines(
			startLineNumber,
			endLineNumber,
			VerticalRevealType.Center,
			scrollType
		);
	}

	public revealLinesInCenterIfOutsideViewport(startLineNumber: number, endLineNumber: number, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealLines(
			startLineNumber,
			endLineNumber,
			VerticalRevealType.CenterIfOutsideViewport,
			scrollType
		);
	}

	private _revealLines(startLineNumber: number, endLineNumber: number, verticalType: VerticalRevealType, scrollType: editorCommon.ScrollType): void {
		if (typeof startLineNumber !== 'number' || typeof endLineNumber !== 'number') {
			throw new Error('Invalid arguments');
		}

		this._sendRevealRange(
			new Range(startLineNumber, 1, endLineNumber, 1),
			verticalType,
			false,
			scrollType
		);
	}

	public revealRange(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth, revealVerticalInCenter: boolean = false, revealHorizontal: boolean = true): void {
		this._revealRange(
			range,
			revealVerticalInCenter ? VerticalRevealType.Center : VerticalRevealType.Simple,
			revealHorizontal,
			scrollType
		);
	}

	public revealRangeInCenter(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealRange(
			range,
			VerticalRevealType.Center,
			true,
			scrollType
		);
	}

	public revealRangeInCenterIfOutsideViewport(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealRange(
			range,
			VerticalRevealType.CenterIfOutsideViewport,
			true,
			scrollType
		);
	}

	public revealRangeAtTop(range: IRange, scrollType: editorCommon.ScrollType = editorCommon.ScrollType.Smooth): void {
		this._revealRange(
			range,
			VerticalRevealType.Top,
			true,
			scrollType
		);
	}

	private _revealRange(range: IRange, verticalType: VerticalRevealType, revealHorizontal: boolean, scrollType: editorCommon.ScrollType): void {
		if (!Range.isIRange(range)) {
			throw new Error('Invalid arguments');
		}

		this._sendRevealRange(
			Range.lift(range),
			verticalType,
			revealHorizontal,
			scrollType
		);
	}

A
Alex Dima 已提交
727
	public setSelections(ranges: ISelection[], source: string = 'api'): void {
A
Alex Dima 已提交
728
		if (!this._modelData) {
A
Alex Dima 已提交
729 730 731 732 733 734 735 736 737 738
			return;
		}
		if (!ranges || ranges.length === 0) {
			throw new Error('Invalid arguments');
		}
		for (let i = 0, len = ranges.length; i < len; i++) {
			if (!Selection.isISelection(ranges[i])) {
				throw new Error('Invalid arguments');
			}
		}
A
Alex Dima 已提交
739
		this._modelData.cursor.setSelections(source, ranges);
A
Alex Dima 已提交
740 741 742
	}

	public getScrollWidth(): number {
A
Alex Dima 已提交
743
		if (!this._modelData) {
A
Alex Dima 已提交
744 745
			return -1;
		}
A
Alex Dima 已提交
746
		return this._modelData.viewModel.viewLayout.getScrollWidth();
A
Alex Dima 已提交
747 748
	}
	public getScrollLeft(): number {
A
Alex Dima 已提交
749
		if (!this._modelData) {
A
Alex Dima 已提交
750 751
			return -1;
		}
A
Alex Dima 已提交
752
		return this._modelData.viewModel.viewLayout.getCurrentScrollLeft();
A
Alex Dima 已提交
753 754 755
	}

	public getScrollHeight(): number {
A
Alex Dima 已提交
756
		if (!this._modelData) {
A
Alex Dima 已提交
757 758
			return -1;
		}
A
Alex Dima 已提交
759
		return this._modelData.viewModel.viewLayout.getScrollHeight();
A
Alex Dima 已提交
760 761
	}
	public getScrollTop(): number {
A
Alex Dima 已提交
762
		if (!this._modelData) {
A
Alex Dima 已提交
763 764
			return -1;
		}
A
Alex Dima 已提交
765
		return this._modelData.viewModel.viewLayout.getCurrentScrollTop();
A
Alex Dima 已提交
766 767 768
	}

	public setScrollLeft(newScrollLeft: number): void {
A
Alex Dima 已提交
769
		if (!this._modelData) {
A
Alex Dima 已提交
770 771 772 773 774
			return;
		}
		if (typeof newScrollLeft !== 'number') {
			throw new Error('Invalid arguments');
		}
A
Alex Dima 已提交
775
		this._modelData.viewModel.viewLayout.setScrollPositionNow({
A
Alex Dima 已提交
776 777 778 779
			scrollLeft: newScrollLeft
		});
	}
	public setScrollTop(newScrollTop: number): void {
A
Alex Dima 已提交
780
		if (!this._modelData) {
A
Alex Dima 已提交
781 782 783 784 785
			return;
		}
		if (typeof newScrollTop !== 'number') {
			throw new Error('Invalid arguments');
		}
A
Alex Dima 已提交
786
		this._modelData.viewModel.viewLayout.setScrollPositionNow({
A
Alex Dima 已提交
787 788 789 790
			scrollTop: newScrollTop
		});
	}
	public setScrollPosition(position: editorCommon.INewScrollPosition): void {
A
Alex Dima 已提交
791
		if (!this._modelData) {
A
Alex Dima 已提交
792 793
			return;
		}
A
Alex Dima 已提交
794
		this._modelData.viewModel.viewLayout.setScrollPositionNow(position);
A
Alex Dima 已提交
795 796
	}

A
Alex Dima 已提交
797 798
	public saveViewState(): editorCommon.ICodeEditorViewState | null {
		if (!this._modelData) {
A
Alex Dima 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811
			return null;
		}
		const contributionsState: { [key: string]: any } = {};

		const keys = Object.keys(this._contributions);
		for (let i = 0, len = keys.length; i < len; i++) {
			const id = keys[i];
			const contribution = this._contributions[id];
			if (typeof contribution.saveViewState === 'function') {
				contributionsState[id] = contribution.saveViewState();
			}
		}

A
Alex Dima 已提交
812 813
		const cursorState = this._modelData.cursor.saveState();
		const viewState = this._modelData.viewModel.saveState();
A
Alex Dima 已提交
814 815 816 817 818 819 820
		return {
			cursorState: cursorState,
			viewState: viewState,
			contributionsState: contributionsState
		};
	}

M
Matt Bierner 已提交
821
	public restoreViewState(s: editorCommon.IEditorViewState | null): void {
A
Alex Dima 已提交
822
		if (!this._modelData || !this._modelData.hasRealView) {
A
Alex Dima 已提交
823 824
			return;
		}
M
Matt Bierner 已提交
825 826
		const codeEditorState = s as editorCommon.ICodeEditorViewState | null;
		if (codeEditorState && codeEditorState.cursorState && codeEditorState.viewState) {
A
Alex Dima 已提交
827 828
			let cursorState = <any>codeEditorState.cursorState;
			if (Array.isArray(cursorState)) {
A
Alex Dima 已提交
829
				this._modelData.cursor.restoreState(<editorCommon.ICursorState[]>cursorState);
A
Alex Dima 已提交
830 831
			} else {
				// Backwards compatibility
A
Alex Dima 已提交
832
				this._modelData.cursor.restoreState([<editorCommon.ICursorState>cursorState]);
A
Alex Dima 已提交
833 834
			}

M
Matt Bierner 已提交
835
			let contributionsState = codeEditorState.contributionsState || {};
A
Alex Dima 已提交
836 837 838 839 840 841 842 843 844
			let keys = Object.keys(this._contributions);
			for (let i = 0, len = keys.length; i < len; i++) {
				let id = keys[i];
				let contribution = this._contributions[id];
				if (typeof contribution.restoreViewState === 'function') {
					contribution.restoreViewState(contributionsState[id]);
				}
			}

M
Matt Bierner 已提交
845
			const reducedState = this._modelData.viewModel.reduceRestoreState(codeEditorState.viewState);
A
Alex Dima 已提交
846 847 848 849 850
			const linesViewportData = this._modelData.viewModel.viewLayout.getLinesViewportDataAtScrollTop(reducedState.scrollTop);
			const startPosition = this._modelData.viewModel.coordinatesConverter.convertViewPositionToModelPosition(new Position(linesViewportData.startLineNumber, 1));
			const endPosition = this._modelData.viewModel.coordinatesConverter.convertViewPositionToModelPosition(new Position(linesViewportData.endLineNumber, 1));
			this._modelData.model.tokenizeViewport(startPosition.lineNumber, endPosition.lineNumber);
			this._modelData.view.restoreState(reducedState);
A
Alex Dima 已提交
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
		}
	}

	public onVisible(): void {
	}

	public onHide(): void {
	}

	public getContribution<T extends editorCommon.IEditorContribution>(id: string): T {
		return <T>(this._contributions[id] || null);
	}

	public getActions(): editorCommon.IEditorAction[] {
		let result: editorCommon.IEditorAction[] = [];

		let keys = Object.keys(this._actions);
		for (let i = 0, len = keys.length; i < len; i++) {
			let id = keys[i];
			result.push(this._actions[id]);
		}

		return result;
	}

	public getSupportedActions(): editorCommon.IEditorAction[] {
		let result = this.getActions();

		result = result.filter(action => action.isSupported());

		return result;
	}

	public getAction(id: string): editorCommon.IEditorAction {
		return this._actions[id] || null;
	}

	public trigger(source: string, handlerId: string, payload: any): void {
		payload = payload || {};

		// Special case for typing
		if (handlerId === editorCommon.Handler.Type) {
A
Alex Dima 已提交
893
			if (!this._modelData || typeof payload.text !== 'string' || payload.text.length === 0) {
A
Alex Dima 已提交
894 895 896 897 898 899
				// nothing to do
				return;
			}
			if (source === 'keyboard') {
				this._onWillType.fire(payload.text);
			}
A
Alex Dima 已提交
900
			this._modelData.cursor.trigger(source, handlerId, payload);
A
Alex Dima 已提交
901 902 903 904 905 906 907 908
			if (source === 'keyboard') {
				this._onDidType.fire(payload.text);
			}
			return;
		}

		// Special case for pasting
		if (handlerId === editorCommon.Handler.Paste) {
A
Alex Dima 已提交
909
			if (!this._modelData || typeof payload.text !== 'string' || payload.text.length === 0) {
A
Alex Dima 已提交
910 911 912
				// nothing to do
				return;
			}
A
Alex Dima 已提交
913 914 915
			const startPosition = this._modelData.cursor.getSelection().getStartPosition();
			this._modelData.cursor.trigger(source, handlerId, payload);
			const endPosition = this._modelData.cursor.getSelection().getStartPosition();
A
Alex Dima 已提交
916 917 918 919 920 921 922 923
			if (source === 'keyboard') {
				this._onDidPaste.fire(
					new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column)
				);
			}
			return;
		}

J
Johannes Rieken 已提交
924 925 926 927 928 929 930
		if (handlerId === editorCommon.Handler.CompositionStart) {
			this._onCompositionStart.fire();
		}
		if (handlerId === editorCommon.Handler.CompositionEnd) {
			this._onCompositionEnd.fire();
		}

A
Alex Dima 已提交
931 932
		const action = this.getAction(handlerId);
		if (action) {
R
Rob Lourens 已提交
933
			Promise.resolve(action.run()).then(undefined, onUnexpectedError);
A
Alex Dima 已提交
934 935 936
			return;
		}

A
Alex Dima 已提交
937
		if (!this._modelData) {
A
Alex Dima 已提交
938 939 940 941 942 943 944
			return;
		}

		if (this._triggerEditorCommand(source, handlerId, payload)) {
			return;
		}

A
Alex Dima 已提交
945
		this._modelData.cursor.trigger(source, handlerId, payload);
A
Alex Dima 已提交
946 947 948 949 950 951 952
	}

	private _triggerEditorCommand(source: string, handlerId: string, payload: any): boolean {
		const command = EditorExtensionsRegistry.getEditorCommand(handlerId);
		if (command) {
			payload = payload || {};
			payload.source = source;
A
Alex Dima 已提交
953
			this._instantiationService.invokeFunction((accessor) => {
R
Rob Lourens 已提交
954
				Promise.resolve(command.runEditorCommand(accessor, this, payload)).then(undefined, onUnexpectedError);
A
Alex Dima 已提交
955
			});
A
Alex Dima 已提交
956 957 958 959 960 961
			return true;
		}

		return false;
	}

A
Alex Dima 已提交
962 963 964 965 966
	public _getCursors(): ICursors | null {
		if (!this._modelData) {
			return null;
		}
		return this._modelData.cursor;
A
Alex Dima 已提交
967 968 969
	}

	public pushUndoStop(): boolean {
A
Alex Dima 已提交
970
		if (!this._modelData) {
A
Alex Dima 已提交
971 972 973 974 975 976
			return false;
		}
		if (this._configuration.editor.readOnly) {
			// read only editor => sorry!
			return false;
		}
A
Alex Dima 已提交
977
		this._modelData.model.pushStackElement();
A
Alex Dima 已提交
978 979 980 981
		return true;
	}

	public executeEdits(source: string, edits: IIdentifiedSingleEditOperation[], endCursorState?: Selection[]): boolean {
A
Alex Dima 已提交
982
		if (!this._modelData) {
A
Alex Dima 已提交
983 984 985 986 987 988 989
			return false;
		}
		if (this._configuration.editor.readOnly) {
			// read only editor => sorry!
			return false;
		}

A
Alex Dima 已提交
990
		this._modelData.model.pushEditOperations(this._modelData.cursor.getSelections(), edits, () => {
A
Alex Dima 已提交
991 992 993 994
			return endCursorState ? endCursorState : null;
		});

		if (endCursorState) {
A
Alex Dima 已提交
995
			this._modelData.cursor.setSelections(source, endCursorState);
A
Alex Dima 已提交
996 997 998 999 1000 1001
		}

		return true;
	}

	public executeCommand(source: string, command: editorCommon.ICommand): void {
A
Alex Dima 已提交
1002
		if (!this._modelData) {
A
Alex Dima 已提交
1003 1004
			return;
		}
A
Alex Dima 已提交
1005
		this._modelData.cursor.trigger(source, editorCommon.Handler.ExecuteCommand, command);
A
Alex Dima 已提交
1006 1007 1008
	}

	public executeCommands(source: string, commands: editorCommon.ICommand[]): void {
A
Alex Dima 已提交
1009
		if (!this._modelData) {
A
Alex Dima 已提交
1010 1011
			return;
		}
A
Alex Dima 已提交
1012
		this._modelData.cursor.trigger(source, editorCommon.Handler.ExecuteCommands, commands);
A
Alex Dima 已提交
1013 1014 1015
	}

	public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
A
Alex Dima 已提交
1016
		if (!this._modelData) {
A
Alex Dima 已提交
1017 1018 1019
			// callback will not be called
			return null;
		}
A
Alex Dima 已提交
1020
		return this._modelData.model.changeDecorations(callback, this._id);
A
Alex Dima 已提交
1021 1022
	}

A
Alex Dima 已提交
1023 1024
	public getLineDecorations(lineNumber: number): IModelDecoration[] | null {
		if (!this._modelData) {
A
Alex Dima 已提交
1025 1026
			return null;
		}
A
Alex Dima 已提交
1027
		return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.editor.readOnly);
A
Alex Dima 已提交
1028 1029 1030
	}

	public deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[] {
A
Alex Dima 已提交
1031
		if (!this._modelData) {
A
Alex Dima 已提交
1032 1033 1034 1035 1036 1037 1038
			return [];
		}

		if (oldDecorations.length === 0 && newDecorations.length === 0) {
			return oldDecorations;
		}

A
Alex Dima 已提交
1039
		return this._modelData.model.deltaDecorations(oldDecorations, newDecorations, this._id);
A
Alex Dima 已提交
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
	}

	public setDecorations(decorationTypeKey: string, decorationOptions: editorCommon.IDecorationOptions[]): void {

		let newDecorationsSubTypes: { [key: string]: boolean } = {};
		let oldDecorationsSubTypes = this._decorationTypeSubtypes[decorationTypeKey] || {};
		this._decorationTypeSubtypes[decorationTypeKey] = newDecorationsSubTypes;

		let newModelDecorations: IModelDeltaDecoration[] = [];

		for (let decorationOption of decorationOptions) {
			let typeKey = decorationTypeKey;
			if (decorationOption.renderOptions) {
				// identify custom reder options by a hash code over all keys and values
				// For custom render options register a decoration type if necessary
				let subType = hash(decorationOption.renderOptions).toString(16);
				// The fact that `decorationTypeKey` appears in the typeKey has no influence
				// it is just a mechanism to get predictable and unique keys (repeatable for the same options and unique across clients)
				typeKey = decorationTypeKey + '-' + subType;
				if (!oldDecorationsSubTypes[subType] && !newDecorationsSubTypes[subType]) {
					// decoration type did not exist before, register new one
					this._registerDecorationType(typeKey, decorationOption.renderOptions, decorationTypeKey);
				}
				newDecorationsSubTypes[subType] = true;
			}
			let opts = this._resolveDecorationOptions(typeKey, !!decorationOption.hoverMessage);
			if (decorationOption.hoverMessage) {
				opts.hoverMessage = decorationOption.hoverMessage;
			}
			newModelDecorations.push({ range: decorationOption.range, options: opts });
		}

		// remove decoration sub types that are no longer used, deregister decoration type if necessary
		for (let subType in oldDecorationsSubTypes) {
			if (!newDecorationsSubTypes[subType]) {
				this._removeDecorationType(decorationTypeKey + '-' + subType);
			}
		}

		// update all decorations
		let oldDecorationsIds = this._decorationTypeKeysToIds[decorationTypeKey] || [];
		this._decorationTypeKeysToIds[decorationTypeKey] = this.deltaDecorations(oldDecorationsIds, newModelDecorations);
	}

	public setDecorationsFast(decorationTypeKey: string, ranges: IRange[]): void {

		// remove decoration sub types that are no longer used, deregister decoration type if necessary
		let oldDecorationsSubTypes = this._decorationTypeSubtypes[decorationTypeKey] || {};
		for (let subType in oldDecorationsSubTypes) {
			this._removeDecorationType(decorationTypeKey + '-' + subType);
		}
		this._decorationTypeSubtypes[decorationTypeKey] = {};

		const opts = ModelDecorationOptions.createDynamic(this._resolveDecorationOptions(decorationTypeKey, false));
		let newModelDecorations: IModelDeltaDecoration[] = new Array<IModelDeltaDecoration>(ranges.length);
		for (let i = 0, len = ranges.length; i < len; i++) {
			newModelDecorations[i] = { range: ranges[i], options: opts };
		}

		// update all decorations
		let oldDecorationsIds = this._decorationTypeKeysToIds[decorationTypeKey] || [];
		this._decorationTypeKeysToIds[decorationTypeKey] = this.deltaDecorations(oldDecorationsIds, newModelDecorations);
	}

	public removeDecorations(decorationTypeKey: string): void {
		// remove decorations for type and sub type
		let oldDecorationsIds = this._decorationTypeKeysToIds[decorationTypeKey];
		if (oldDecorationsIds) {
			this.deltaDecorations(oldDecorationsIds, []);
		}
		if (this._decorationTypeKeysToIds.hasOwnProperty(decorationTypeKey)) {
			delete this._decorationTypeKeysToIds[decorationTypeKey];
		}
		if (this._decorationTypeSubtypes.hasOwnProperty(decorationTypeKey)) {
			delete this._decorationTypeSubtypes[decorationTypeKey];
		}
	}

	public getLayoutInfo(): editorOptions.EditorLayoutInfo {
		return this._configuration.editor.layoutInfo;
	}

A
Alex Dima 已提交
1122 1123 1124 1125 1126
	public createOverviewRuler(cssClassName: string): editorBrowser.IOverviewRuler | null {
		if (!this._modelData || !this._modelData.hasRealView) {
			return null;
		}
		return this._modelData.view.createOverviewRuler(cssClassName);
E
Erich Gamma 已提交
1127 1128
	}

A
Alex Dima 已提交
1129 1130
	public getDomNode(): HTMLElement | null {
		if (!this._modelData || !this._modelData.hasRealView) {
E
Erich Gamma 已提交
1131 1132
			return null;
		}
A
Alex Dima 已提交
1133
		return this._modelData.view.domNode.domNode;
E
Erich Gamma 已提交
1134 1135
	}

1136
	public delegateVerticalScrollbarMouseDown(browserEvent: IMouseEvent): void {
A
Alex Dima 已提交
1137
		if (!this._modelData || !this._modelData.hasRealView) {
1138
			return;
E
Erich Gamma 已提交
1139
		}
A
Alex Dima 已提交
1140
		this._modelData.view.delegateVerticalScrollbarMouseDown(browserEvent);
E
Erich Gamma 已提交
1141 1142
	}

J
Johannes Rieken 已提交
1143
	public layout(dimension?: editorCommon.IDimension): void {
E
Erich Gamma 已提交
1144
		this._configuration.observeReferenceElement(dimension);
1145
		this.render();
E
Erich Gamma 已提交
1146 1147 1148
	}

	public focus(): void {
A
Alex Dima 已提交
1149
		if (!this._modelData || !this._modelData.hasRealView) {
E
Erich Gamma 已提交
1150 1151
			return;
		}
A
Alex Dima 已提交
1152
		this._modelData.view.focus();
E
Erich Gamma 已提交
1153 1154
	}

A
Alex Dima 已提交
1155
	public hasTextFocus(): boolean {
A
Alex Dima 已提交
1156 1157 1158 1159
		if (!this._modelData || !this._modelData.hasRealView) {
			return false;
		}
		return this._modelData.view.isFocused();
E
Erich Gamma 已提交
1160 1161
	}

1162
	public hasWidgetFocus(): boolean {
1163
		return this._focusTracker && this._focusTracker.hasFocus();
1164 1165
	}

A
Alex Dima 已提交
1166
	public addContentWidget(widget: editorBrowser.IContentWidget): void {
A
Alex Dima 已提交
1167
		let widgetData: IContentWidgetData = {
E
Erich Gamma 已提交
1168 1169 1170 1171
			widget: widget,
			position: widget.getPosition()
		};

A
Alex Dima 已提交
1172
		if (this._contentWidgets.hasOwnProperty(widget.getId())) {
E
Erich Gamma 已提交
1173 1174 1175
			console.warn('Overwriting a content widget with the same id.');
		}

A
Alex Dima 已提交
1176
		this._contentWidgets[widget.getId()] = widgetData;
E
Erich Gamma 已提交
1177

A
Alex Dima 已提交
1178 1179
		if (this._modelData && this._modelData.hasRealView) {
			this._modelData.view.addContentWidget(widgetData);
E
Erich Gamma 已提交
1180 1181 1182
		}
	}

A
Alex Dima 已提交
1183
	public layoutContentWidget(widget: editorBrowser.IContentWidget): void {
A
Alex Dima 已提交
1184
		let widgetId = widget.getId();
A
Alex Dima 已提交
1185 1186
		if (this._contentWidgets.hasOwnProperty(widgetId)) {
			let widgetData = this._contentWidgets[widgetId];
E
Erich Gamma 已提交
1187
			widgetData.position = widget.getPosition();
A
Alex Dima 已提交
1188 1189
			if (this._modelData && this._modelData.hasRealView) {
				this._modelData.view.layoutContentWidget(widgetData);
E
Erich Gamma 已提交
1190 1191 1192 1193
			}
		}
	}

A
Alex Dima 已提交
1194
	public removeContentWidget(widget: editorBrowser.IContentWidget): void {
A
Alex Dima 已提交
1195
		let widgetId = widget.getId();
A
Alex Dima 已提交
1196 1197 1198
		if (this._contentWidgets.hasOwnProperty(widgetId)) {
			let widgetData = this._contentWidgets[widgetId];
			delete this._contentWidgets[widgetId];
A
Alex Dima 已提交
1199 1200
			if (this._modelData && this._modelData.hasRealView) {
				this._modelData.view.removeContentWidget(widgetData);
E
Erich Gamma 已提交
1201 1202 1203 1204
			}
		}
	}

A
Alex Dima 已提交
1205
	public addOverlayWidget(widget: editorBrowser.IOverlayWidget): void {
A
Alex Dima 已提交
1206
		let widgetData: IOverlayWidgetData = {
E
Erich Gamma 已提交
1207 1208 1209 1210
			widget: widget,
			position: widget.getPosition()
		};

A
Alex Dima 已提交
1211
		if (this._overlayWidgets.hasOwnProperty(widget.getId())) {
E
Erich Gamma 已提交
1212 1213 1214
			console.warn('Overwriting an overlay widget with the same id.');
		}

A
Alex Dima 已提交
1215
		this._overlayWidgets[widget.getId()] = widgetData;
E
Erich Gamma 已提交
1216

A
Alex Dima 已提交
1217 1218
		if (this._modelData && this._modelData.hasRealView) {
			this._modelData.view.addOverlayWidget(widgetData);
E
Erich Gamma 已提交
1219 1220 1221
		}
	}

A
Alex Dima 已提交
1222
	public layoutOverlayWidget(widget: editorBrowser.IOverlayWidget): void {
A
Alex Dima 已提交
1223
		let widgetId = widget.getId();
A
Alex Dima 已提交
1224 1225
		if (this._overlayWidgets.hasOwnProperty(widgetId)) {
			let widgetData = this._overlayWidgets[widgetId];
E
Erich Gamma 已提交
1226
			widgetData.position = widget.getPosition();
A
Alex Dima 已提交
1227 1228
			if (this._modelData && this._modelData.hasRealView) {
				this._modelData.view.layoutOverlayWidget(widgetData);
E
Erich Gamma 已提交
1229 1230 1231 1232
			}
		}
	}

A
Alex Dima 已提交
1233
	public removeOverlayWidget(widget: editorBrowser.IOverlayWidget): void {
A
Alex Dima 已提交
1234
		let widgetId = widget.getId();
A
Alex Dima 已提交
1235 1236 1237
		if (this._overlayWidgets.hasOwnProperty(widgetId)) {
			let widgetData = this._overlayWidgets[widgetId];
			delete this._overlayWidgets[widgetId];
A
Alex Dima 已提交
1238 1239
			if (this._modelData && this._modelData.hasRealView) {
				this._modelData.view.removeOverlayWidget(widgetData);
E
Erich Gamma 已提交
1240 1241 1242 1243
			}
		}
	}

J
Johannes Rieken 已提交
1244
	public changeViewZones(callback: (accessor: editorBrowser.IViewZoneChangeAccessor) => void): void {
A
Alex Dima 已提交
1245
		if (!this._modelData || !this._modelData.hasRealView) {
E
Erich Gamma 已提交
1246 1247
			return;
		}
A
Alex Dima 已提交
1248
		let hasChanges = this._modelData.view.change(callback);
E
Erich Gamma 已提交
1249
		if (hasChanges) {
A
Alex Dima 已提交
1250
			this._onDidChangeViewZones.fire();
E
Erich Gamma 已提交
1251 1252 1253
		}
	}

A
Alex Dima 已提交
1254 1255
	public getTargetAtClientPoint(clientX: number, clientY: number): editorBrowser.IMouseTarget | null {
		if (!this._modelData || !this._modelData.hasRealView) {
1256 1257
			return null;
		}
A
Alex Dima 已提交
1258
		return this._modelData.view.getTargetAtClientPoint(clientX, clientY);
1259 1260
	}

A
Alex Dima 已提交
1261 1262
	public getScrolledVisiblePosition(rawPosition: IPosition): { top: number; left: number; height: number; } | null {
		if (!this._modelData || !this._modelData.hasRealView) {
E
Erich Gamma 已提交
1263 1264 1265
			return null;
		}

A
Alex Dima 已提交
1266
		let position = this._modelData.model.validatePosition(rawPosition);
A
Alex Dima 已提交
1267
		let layoutInfo = this._configuration.editor.layoutInfo;
E
Erich Gamma 已提交
1268

A
Alex Dima 已提交
1269 1270
		let top = CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, position.lineNumber, position.column) - this.getScrollTop();
		let left = this._modelData.view.getOffsetForColumn(position.lineNumber, position.column) + layoutInfo.glyphMarginWidth + layoutInfo.lineNumbersWidth + layoutInfo.decorationsWidth - this.getScrollLeft();
E
Erich Gamma 已提交
1271 1272 1273 1274 1275 1276 1277 1278

		return {
			top: top,
			left: left,
			height: this._configuration.editor.lineHeight
		};
	}

J
Johannes Rieken 已提交
1279
	public getOffsetForColumn(lineNumber: number, column: number): number {
A
Alex Dima 已提交
1280
		if (!this._modelData || !this._modelData.hasRealView) {
E
Erich Gamma 已提交
1281 1282
			return -1;
		}
A
Alex Dima 已提交
1283
		return this._modelData.view.getOffsetForColumn(lineNumber, column);
E
Erich Gamma 已提交
1284 1285
	}

1286
	public render(): void {
A
Alex Dima 已提交
1287
		if (!this._modelData || !this._modelData.hasRealView) {
1288 1289
			return;
		}
A
Alex Dima 已提交
1290
		this._modelData.view.render(true, false);
1291 1292
	}

J
Johannes Rieken 已提交
1293
	public applyFontInfo(target: HTMLElement): void {
1294 1295 1296
		Configuration.applyFontInfoSlow(target, this._configuration.editor.fontInfo);
	}

A
Alex Dima 已提交
1297 1298 1299 1300 1301
	protected _attachModel(model: ITextModel | null): void {
		if (!model) {
			this._modelData = null;
			return;
		}
E
Erich Gamma 已提交
1302

A
Alex Dima 已提交
1303
		const listenersToRemove: IDisposable[] = [];
A
Alex Dima 已提交
1304

A
Alex Dima 已提交
1305
		this._domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
A
Alex Dima 已提交
1306 1307
		this._configuration.setIsDominatedByLongLines(model.isDominatedByLongLines());
		this._configuration.setMaxLineNumber(model.getLineCount());
A
Alex Dima 已提交
1308

A
Alex Dima 已提交
1309
		model.onBeforeAttached();
A
Alex Dima 已提交
1310

A
Alex Dima 已提交
1311
		const viewModel = new ViewModel(this._id, this._configuration, model, (callback) => dom.scheduleAtNextAnimationFrame(callback));
A
Alex Dima 已提交
1312

A
Alex Dima 已提交
1313 1314
		listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e)));
		listenersToRemove.push(model.onDidChangeLanguage((e) => {
A
Alex Dima 已提交
1315
			this._domElement.setAttribute('data-mode-id', model.getLanguageIdentifier().language);
A
Alex Dima 已提交
1316 1317 1318 1319 1320 1321 1322
			this._onDidChangeModelLanguage.fire(e);
		}));
		listenersToRemove.push(model.onDidChangeLanguageConfiguration((e) => this._onDidChangeModelLanguageConfiguration.fire(e)));
		listenersToRemove.push(model.onDidChangeContent((e) => this._onDidChangeModelContent.fire(e)));
		listenersToRemove.push(model.onDidChangeOptions((e) => this._onDidChangeModelOptions.fire(e)));
		// Someone might destroy the model from under the editor, so prevent any exceptions by setting a null model
		listenersToRemove.push(model.onWillDispose(() => this.setModel(null)));
A
Alex Dima 已提交
1323

A
Alex Dima 已提交
1324
		const cursor = new Cursor(this._configuration, model, viewModel);
A
Alex Dima 已提交
1325

A
Alex Dima 已提交
1326 1327 1328
		listenersToRemove.push(cursor.onDidReachMaxCursorCount(() => {
			this._notificationService.warn(nls.localize('cursors.maximum', "The number of cursors has been limited to {0}.", Cursor.MAX_CURSOR_COUNT));
		}));
A
Alex Dima 已提交
1329

A
Alex Dima 已提交
1330
		listenersToRemove.push(cursor.onDidAttemptReadOnlyEdit(() => {
R
Rob Lourens 已提交
1331
			this._onDidAttemptReadOnlyEdit.fire(undefined);
A
Alex Dima 已提交
1332
		}));
A
Alex Dima 已提交
1333

A
Alex Dima 已提交
1334 1335 1336 1337 1338
		listenersToRemove.push(cursor.onDidChange((e: CursorStateChangedEvent) => {
			let positions: Position[] = [];
			for (let i = 0, len = e.selections.length; i < len; i++) {
				positions[i] = e.selections[i].getPosition();
			}
A
Alex Dima 已提交
1339

A
Alex Dima 已提交
1340 1341 1342 1343 1344 1345 1346
			const e1: ICursorPositionChangedEvent = {
				position: positions[0],
				secondaryPositions: positions.slice(1),
				reason: e.reason,
				source: e.source
			};
			this._onDidChangeCursorPosition.fire(e1);
A
Alex Dima 已提交
1347

A
Alex Dima 已提交
1348 1349 1350 1351 1352 1353 1354 1355
			const e2: ICursorSelectionChangedEvent = {
				selection: e.selections[0],
				secondarySelections: e.selections.slice(1),
				source: e.source,
				reason: e.reason
			};
			this._onDidChangeCursorSelection.fire(e2);
		}));
E
Erich Gamma 已提交
1356

A
Alex Dima 已提交
1357 1358
		const [view, hasRealView] = this._createView(viewModel, cursor);
		if (hasRealView) {
A
Alex Dima 已提交
1359
			this._domElement.appendChild(view.domNode.domNode);
E
Erich Gamma 已提交
1360

A
Alex Dima 已提交
1361
			let keys = Object.keys(this._contentWidgets);
A
Alex Dima 已提交
1362 1363
			for (let i = 0, len = keys.length; i < len; i++) {
				let widgetId = keys[i];
A
Alex Dima 已提交
1364
				view.addContentWidget(this._contentWidgets[widgetId]);
A
Alex Dima 已提交
1365
			}
E
Erich Gamma 已提交
1366

A
Alex Dima 已提交
1367
			keys = Object.keys(this._overlayWidgets);
A
Alex Dima 已提交
1368 1369
			for (let i = 0, len = keys.length; i < len; i++) {
				let widgetId = keys[i];
A
Alex Dima 已提交
1370
				view.addOverlayWidget(this._overlayWidgets[widgetId]);
A
Alex Dima 已提交
1371
			}
E
Erich Gamma 已提交
1372

A
Alex Dima 已提交
1373 1374
			view.render(false, true);
			view.domNode.domNode.setAttribute('data-uri', model.uri.toString());
E
Erich Gamma 已提交
1375
		}
A
Alex Dima 已提交
1376 1377

		this._modelData = new ModelData(model, viewModel, cursor, view, hasRealView, listenersToRemove);
E
Erich Gamma 已提交
1378 1379
	}

A
Alex Dima 已提交
1380
	protected _createView(viewModel: ViewModel, cursor: Cursor): [View, boolean] {
1381 1382 1383
		let commandDelegate: ICommandDelegate;
		if (this.isSimpleWidget) {
			commandDelegate = {
A
Alex Dima 已提交
1384 1385 1386 1387
				executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
					editorCommand.runCoreEditorCommand(cursor, args);
				},
				paste: (source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[] | null) => {
1388
					this.trigger(source, editorCommon.Handler.Paste, { text, pasteOnNewLine, multicursorText });
1389 1390
				},
				type: (source: string, text: string) => {
1391
					this.trigger(source, editorCommon.Handler.Type, { text });
1392 1393
				},
				replacePreviousChar: (source: string, text: string, replaceCharCnt: number) => {
1394
					this.trigger(source, editorCommon.Handler.ReplacePreviousChar, { text, replaceCharCnt });
1395 1396
				},
				compositionStart: (source: string) => {
1397
					this.trigger(source, editorCommon.Handler.CompositionStart, undefined);
1398 1399
				},
				compositionEnd: (source: string) => {
1400
					this.trigger(source, editorCommon.Handler.CompositionEnd, undefined);
1401 1402
				},
				cut: (source: string) => {
1403
					this.trigger(source, editorCommon.Handler.Cut, undefined);
1404 1405 1406 1407
				}
			};
		} else {
			commandDelegate = {
A
Alex Dima 已提交
1408 1409 1410 1411
				executeEditorCommand: (editorCommand: CoreEditorCommand, args: any): void => {
					editorCommand.runCoreEditorCommand(cursor, args);
				},
				paste: (source: string, text: string, pasteOnNewLine: boolean, multicursorText: string[] | null) => {
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
					this._commandService.executeCommand(editorCommon.Handler.Paste, {
						text: text,
						pasteOnNewLine: pasteOnNewLine,
						multicursorText: multicursorText
					});
				},
				type: (source: string, text: string) => {
					this._commandService.executeCommand(editorCommon.Handler.Type, {
						text: text
					});
				},
				replacePreviousChar: (source: string, text: string, replaceCharCnt: number) => {
					this._commandService.executeCommand(editorCommon.Handler.ReplacePreviousChar, {
						text: text,
						replaceCharCnt: replaceCharCnt
					});
				},
				compositionStart: (source: string) => {
					this._commandService.executeCommand(editorCommon.Handler.CompositionStart, {});
				},
				compositionEnd: (source: string) => {
					this._commandService.executeCommand(editorCommon.Handler.CompositionEnd, {});
				},
				cut: (source: string) => {
					this._commandService.executeCommand(editorCommon.Handler.Cut, {});
				}
			};
		}

A
Alex Dima 已提交
1441 1442
		const viewOutgoingEvents = new ViewOutgoingEvents(viewModel);
		viewOutgoingEvents.onDidGainFocus = () => {
1443
			this._editorTextFocus.setValue(true);
A
Alex Dima 已提交
1444
			// In IE, the focus is not synchronous, so we give it a little help
A
Alex Dima 已提交
1445
			this._editorWidgetFocus.setValue(true);
A
Alex Dima 已提交
1446
		};
A
Alex Dima 已提交
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
		viewOutgoingEvents.onDidScroll = (e) => this._onDidScrollChange.fire(e);
		viewOutgoingEvents.onDidLoseFocus = () => this._editorTextFocus.setValue(false);
		viewOutgoingEvents.onContextMenu = (e) => this._onContextMenu.fire(e);
		viewOutgoingEvents.onMouseDown = (e) => this._onMouseDown.fire(e);
		viewOutgoingEvents.onMouseUp = (e) => this._onMouseUp.fire(e);
		viewOutgoingEvents.onMouseDrag = (e) => this._onMouseDrag.fire(e);
		viewOutgoingEvents.onMouseDrop = (e) => this._onMouseDrop.fire(e);
		viewOutgoingEvents.onKeyUp = (e) => this._onKeyUp.fire(e);
		viewOutgoingEvents.onMouseMove = (e) => this._onMouseMove.fire(e);
		viewOutgoingEvents.onMouseLeave = (e) => this._onMouseLeave.fire(e);
		viewOutgoingEvents.onKeyDown = (e) => this._onKeyDown.fire(e);

		const view = new View(
			commandDelegate,
			this._configuration,
			this._themeService,
			viewModel,
			cursor,
			viewOutgoingEvents
		);
A
Alex Dima 已提交
1467

A
Alex Dima 已提交
1468
		return [view, true];
1469
	}
E
Erich Gamma 已提交
1470

A
Alex Dima 已提交
1471
	protected _postDetachModelCleanup(detachedModel: ITextModel | null): void {
A
Alex Dima 已提交
1472
		if (detachedModel) {
A
Alex Dima 已提交
1473
			detachedModel.removeAllDecorationsWithOwnerId(this._id);
1474 1475 1476
		}
	}

A
Alex Dima 已提交
1477 1478 1479
	private _detachModel(): ITextModel | null {
		if (!this._modelData) {
			return null;
A
Alex Dima 已提交
1480
		}
A
Alex Dima 已提交
1481 1482
		const model = this._modelData.model;
		const removeDomNode = this._modelData.hasRealView ? this._modelData.view.domNode.domNode : null;
A
Alex Dima 已提交
1483

A
Alex Dima 已提交
1484 1485
		this._modelData.dispose();
		this._modelData = null;
A
Alex Dima 已提交
1486

A
Alex Dima 已提交
1487
		this._domElement.removeAttribute('data-mode-id');
E
Erich Gamma 已提交
1488
		if (removeDomNode) {
A
Alex Dima 已提交
1489
			this._domElement.removeChild(removeDomNode);
E
Erich Gamma 已提交
1490 1491
		}

A
Alex Dima 已提交
1492
		return model;
E
Erich Gamma 已提交
1493
	}
1494

A
Alex Dima 已提交
1495
	private _registerDecorationType(key: string, options: editorCommon.IDecorationRenderOptions, parentTypeKey?: string): void {
1496 1497 1498
		this._codeEditorService.registerDecorationType(key, options, parentTypeKey);
	}

A
Alex Dima 已提交
1499
	private _removeDecorationType(key: string): void {
1500 1501 1502
		this._codeEditorService.removeDecorationType(key);
	}

A
Alex Dima 已提交
1503
	private _resolveDecorationOptions(typeKey: string, writable: boolean): IModelDecorationOptions {
1504 1505 1506
		return this._codeEditorService.resolveDecorationOptions(typeKey, writable);
	}

A
Alex Dima 已提交
1507 1508 1509
	/* __GDPR__FRAGMENT__
		"EditorTelemetryData" : {}
	*/
M
Matt Bierner 已提交
1510
	public getTelemetryData(): { [key: string]: any; } | undefined {
1511
		return this._telemetryData;
A
Alex Dima 已提交
1512
	}
A
Alex Dima 已提交
1513 1514 1515 1516

	public hasModel(): this is editorBrowser.IActiveCodeEditor {
		return (this._modelData !== null);
	}
A
Alex Dima 已提交
1517
}
1518

A
Alex Dima 已提交
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
const enum BooleanEventValue {
	NotSet,
	False,
	True
}

export class BooleanEventEmitter extends Disposable {
	private readonly _onDidChangeToTrue: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidChangeToTrue: Event<void> = this._onDidChangeToTrue.event;

	private readonly _onDidChangeToFalse: Emitter<void> = this._register(new Emitter<void>());
	public readonly onDidChangeToFalse: Event<void> = this._onDidChangeToFalse.event;

	private _value: BooleanEventValue;

	constructor() {
		super();
		this._value = BooleanEventValue.NotSet;
	}

	public setValue(_value: boolean) {
		let value = (_value ? BooleanEventValue.True : BooleanEventValue.False);
		if (this._value === value) {
			return;
1543
		}
A
Alex Dima 已提交
1544 1545 1546 1547 1548 1549 1550 1551
		this._value = value;
		if (this._value === BooleanEventValue.True) {
			this._onDidChangeToTrue.fire();
		} else if (this._value === BooleanEventValue.False) {
			this._onDidChangeToFalse.fire();
		}
	}
}
1552

A
Alex Dima 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
class EditorContextKeysManager extends Disposable {

	private _editor: CodeEditorWidget;
	private _editorFocus: IContextKey<boolean>;
	private _textInputFocus: IContextKey<boolean>;
	private _editorTextFocus: IContextKey<boolean>;
	private _editorTabMovesFocus: IContextKey<boolean>;
	private _editorReadonly: IContextKey<boolean>;
	private _hasMultipleSelections: IContextKey<boolean>;
	private _hasNonEmptySelection: IContextKey<boolean>;
A
Alex Dima 已提交
1563 1564
	private _canUndo: IContextKey<boolean>;
	private _canRedo: IContextKey<boolean>;
A
Alex Dima 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581

	constructor(
		editor: CodeEditorWidget,
		contextKeyService: IContextKeyService
	) {
		super();

		this._editor = editor;

		contextKeyService.createKey('editorId', editor.getId());
		this._editorFocus = EditorContextKeys.focus.bindTo(contextKeyService);
		this._textInputFocus = EditorContextKeys.textInputFocus.bindTo(contextKeyService);
		this._editorTextFocus = EditorContextKeys.editorTextFocus.bindTo(contextKeyService);
		this._editorTabMovesFocus = EditorContextKeys.tabMovesFocus.bindTo(contextKeyService);
		this._editorReadonly = EditorContextKeys.readOnly.bindTo(contextKeyService);
		this._hasMultipleSelections = EditorContextKeys.hasMultipleSelections.bindTo(contextKeyService);
		this._hasNonEmptySelection = EditorContextKeys.hasNonEmptySelection.bindTo(contextKeyService);
A
Alex Dima 已提交
1582 1583
		this._canUndo = EditorContextKeys.canUndo.bindTo(contextKeyService);
		this._canRedo = EditorContextKeys.canRedo.bindTo(contextKeyService);
A
Alex Dima 已提交
1584 1585 1586

		this._register(this._editor.onDidChangeConfiguration(() => this._updateFromConfig()));
		this._register(this._editor.onDidChangeCursorSelection(() => this._updateFromSelection()));
A
Alex Dima 已提交
1587 1588
		this._register(this._editor.onDidFocusEditorWidget(() => this._updateFromFocus()));
		this._register(this._editor.onDidBlurEditorWidget(() => this._updateFromFocus()));
A
Alex Dima 已提交
1589 1590
		this._register(this._editor.onDidFocusEditorText(() => this._updateFromFocus()));
		this._register(this._editor.onDidBlurEditorText(() => this._updateFromFocus()));
A
Alex Dima 已提交
1591 1592
		this._register(this._editor.onDidChangeModel(() => this._updateFromModel()));
		this._register(this._editor.onDidChangeConfiguration(() => this._updateFromModel()));
A
Alex Dima 已提交
1593 1594 1595 1596

		this._updateFromConfig();
		this._updateFromSelection();
		this._updateFromFocus();
A
Alex Dima 已提交
1597
		this._updateFromModel();
A
Alex Dima 已提交
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
	}

	private _updateFromConfig(): void {
		let config = this._editor.getConfiguration();

		this._editorTabMovesFocus.set(config.tabFocusMode);
		this._editorReadonly.set(config.readOnly);
	}

	private _updateFromSelection(): void {
		let selections = this._editor.getSelections();
		if (!selections) {
			this._hasMultipleSelections.reset();
			this._hasNonEmptySelection.reset();
		} else {
			this._hasMultipleSelections.set(selections.length > 1);
			this._hasNonEmptySelection.set(selections.some(s => !s.isEmpty()));
		}
	}

	private _updateFromFocus(): void {
		this._editorFocus.set(this._editor.hasWidgetFocus() && !this._editor.isSimpleWidget);
A
Alex Dima 已提交
1620 1621
		this._editorTextFocus.set(this._editor.hasTextFocus() && !this._editor.isSimpleWidget);
		this._textInputFocus.set(this._editor.hasTextFocus());
A
Alex Dima 已提交
1622
	}
A
Alex Dima 已提交
1623 1624 1625

	private _updateFromModel(): void {
		const model = this._editor.getModel();
A
Alex Dima 已提交
1626 1627
		this._canUndo.set(Boolean(model && model.canUndo()));
		this._canRedo.set(Boolean(model && model.canRedo()));
A
Alex Dima 已提交
1628
	}
A
Alex Dima 已提交
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
}

export class EditorModeContext extends Disposable {

	private _editor: CodeEditorWidget;

	private _langId: IContextKey<string>;
	private _hasCompletionItemProvider: IContextKey<boolean>;
	private _hasCodeActionsProvider: IContextKey<boolean>;
	private _hasCodeLensProvider: IContextKey<boolean>;
	private _hasDefinitionProvider: IContextKey<boolean>;
1640
	private _hasDeclarationProvider: IContextKey<boolean>;
A
Alex Dima 已提交
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664
	private _hasImplementationProvider: IContextKey<boolean>;
	private _hasTypeDefinitionProvider: IContextKey<boolean>;
	private _hasHoverProvider: IContextKey<boolean>;
	private _hasDocumentHighlightProvider: IContextKey<boolean>;
	private _hasDocumentSymbolProvider: IContextKey<boolean>;
	private _hasReferenceProvider: IContextKey<boolean>;
	private _hasRenameProvider: IContextKey<boolean>;
	private _hasDocumentFormattingProvider: IContextKey<boolean>;
	private _hasDocumentSelectionFormattingProvider: IContextKey<boolean>;
	private _hasSignatureHelpProvider: IContextKey<boolean>;
	private _isInWalkThrough: IContextKey<boolean>;

	constructor(
		editor: CodeEditorWidget,
		contextKeyService: IContextKeyService
	) {
		super();
		this._editor = editor;

		this._langId = EditorContextKeys.languageId.bindTo(contextKeyService);
		this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(contextKeyService);
		this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(contextKeyService);
		this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(contextKeyService);
		this._hasDefinitionProvider = EditorContextKeys.hasDefinitionProvider.bindTo(contextKeyService);
1665
		this._hasDeclarationProvider = EditorContextKeys.hasDeclarationProvider.bindTo(contextKeyService);
A
Alex Dima 已提交
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684
		this._hasImplementationProvider = EditorContextKeys.hasImplementationProvider.bindTo(contextKeyService);
		this._hasTypeDefinitionProvider = EditorContextKeys.hasTypeDefinitionProvider.bindTo(contextKeyService);
		this._hasHoverProvider = EditorContextKeys.hasHoverProvider.bindTo(contextKeyService);
		this._hasDocumentHighlightProvider = EditorContextKeys.hasDocumentHighlightProvider.bindTo(contextKeyService);
		this._hasDocumentSymbolProvider = EditorContextKeys.hasDocumentSymbolProvider.bindTo(contextKeyService);
		this._hasReferenceProvider = EditorContextKeys.hasReferenceProvider.bindTo(contextKeyService);
		this._hasRenameProvider = EditorContextKeys.hasRenameProvider.bindTo(contextKeyService);
		this._hasDocumentFormattingProvider = EditorContextKeys.hasDocumentFormattingProvider.bindTo(contextKeyService);
		this._hasDocumentSelectionFormattingProvider = EditorContextKeys.hasDocumentSelectionFormattingProvider.bindTo(contextKeyService);
		this._hasSignatureHelpProvider = EditorContextKeys.hasSignatureHelpProvider.bindTo(contextKeyService);
		this._isInWalkThrough = EditorContextKeys.isInEmbeddedEditor.bindTo(contextKeyService);

		const update = () => this._update();

		// update when model/mode changes
		this._register(editor.onDidChangeModel(update));
		this._register(editor.onDidChangeModelLanguage(update));

		// update when registries change
1685
		this._register(modes.CompletionProviderRegistry.onDidChange(update));
A
Alex Dima 已提交
1686 1687 1688
		this._register(modes.CodeActionProviderRegistry.onDidChange(update));
		this._register(modes.CodeLensProviderRegistry.onDidChange(update));
		this._register(modes.DefinitionProviderRegistry.onDidChange(update));
1689
		this._register(modes.DeclarationProviderRegistry.onDidChange(update));
A
Alex Dima 已提交
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
		this._register(modes.ImplementationProviderRegistry.onDidChange(update));
		this._register(modes.TypeDefinitionProviderRegistry.onDidChange(update));
		this._register(modes.HoverProviderRegistry.onDidChange(update));
		this._register(modes.DocumentHighlightProviderRegistry.onDidChange(update));
		this._register(modes.DocumentSymbolProviderRegistry.onDidChange(update));
		this._register(modes.ReferenceProviderRegistry.onDidChange(update));
		this._register(modes.RenameProviderRegistry.onDidChange(update));
		this._register(modes.DocumentFormattingEditProviderRegistry.onDidChange(update));
		this._register(modes.DocumentRangeFormattingEditProviderRegistry.onDidChange(update));
		this._register(modes.SignatureHelpProviderRegistry.onDidChange(update));

		update();
	}

	dispose() {
		super.dispose();
	}

	reset() {
		this._langId.reset();
		this._hasCompletionItemProvider.reset();
		this._hasCodeActionsProvider.reset();
		this._hasCodeLensProvider.reset();
		this._hasDefinitionProvider.reset();
1714
		this._hasDeclarationProvider.reset();
A
Alex Dima 已提交
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
		this._hasImplementationProvider.reset();
		this._hasTypeDefinitionProvider.reset();
		this._hasHoverProvider.reset();
		this._hasDocumentHighlightProvider.reset();
		this._hasDocumentSymbolProvider.reset();
		this._hasReferenceProvider.reset();
		this._hasRenameProvider.reset();
		this._hasDocumentFormattingProvider.reset();
		this._hasDocumentSelectionFormattingProvider.reset();
		this._hasSignatureHelpProvider.reset();
		this._isInWalkThrough.reset();
	}

	private _update() {
		const model = this._editor.getModel();
		if (!model) {
			this.reset();
			return;
		}
		this._langId.set(model.getLanguageIdentifier().language);
1735
		this._hasCompletionItemProvider.set(modes.CompletionProviderRegistry.has(model));
A
Alex Dima 已提交
1736 1737 1738
		this._hasCodeActionsProvider.set(modes.CodeActionProviderRegistry.has(model));
		this._hasCodeLensProvider.set(modes.CodeLensProviderRegistry.has(model));
		this._hasDefinitionProvider.set(modes.DefinitionProviderRegistry.has(model));
1739
		this._hasDeclarationProvider.set(modes.DeclarationProviderRegistry.has(model));
A
Alex Dima 已提交
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
		this._hasImplementationProvider.set(modes.ImplementationProviderRegistry.has(model));
		this._hasTypeDefinitionProvider.set(modes.TypeDefinitionProviderRegistry.has(model));
		this._hasHoverProvider.set(modes.HoverProviderRegistry.has(model));
		this._hasDocumentHighlightProvider.set(modes.DocumentHighlightProviderRegistry.has(model));
		this._hasDocumentSymbolProvider.set(modes.DocumentSymbolProviderRegistry.has(model));
		this._hasReferenceProvider.set(modes.ReferenceProviderRegistry.has(model));
		this._hasRenameProvider.set(modes.RenameProviderRegistry.has(model));
		this._hasSignatureHelpProvider.set(modes.SignatureHelpProviderRegistry.has(model));
		this._hasDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.has(model) || modes.DocumentRangeFormattingEditProviderRegistry.has(model));
		this._hasDocumentSelectionFormattingProvider.set(modes.DocumentRangeFormattingEditProviderRegistry.has(model));
		this._isInWalkThrough.set(model.uri.scheme === Schemas.walkThroughSnippet);
1751
	}
E
Erich Gamma 已提交
1752 1753
}

1754 1755
class CodeEditorWidgetFocusTracker extends Disposable {

1756 1757
	private _hasFocus: boolean;
	private _domFocusTracker: dom.IFocusTracker;
1758

M
Matt Bierner 已提交
1759
	private readonly _onChange: Emitter<void> = this._register(new Emitter<void>());
1760
	public readonly onChange: Event<void> = this._onChange.event;
1761

J
Johannes Rieken 已提交
1762
	constructor(domElement: HTMLElement) {
1763 1764
		super();

1765 1766
		this._hasFocus = false;
		this._domFocusTracker = this._register(dom.trackFocus(domElement));
1767

1768
		this._register(this._domFocusTracker.onDidFocus(() => {
1769
			this._hasFocus = true;
R
Rob Lourens 已提交
1770
			this._onChange.fire(undefined);
1771 1772
		}));
		this._register(this._domFocusTracker.onDidBlur(() => {
1773
			this._hasFocus = false;
R
Rob Lourens 已提交
1774
			this._onChange.fire(undefined);
1775
		}));
1776 1777 1778
	}

	public hasFocus(): boolean {
1779
		return this._hasFocus;
1780 1781
	}
}
1782

1783
const squigglyStart = encodeURIComponent(`<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' enable-background='new 0 0 6 3' height='3' width='6'><g fill='`);
1784
const squigglyEnd = encodeURIComponent(`'><polygon points='5.5,0 2.5,3 1.1,3 4.1,0'/><polygon points='4,0 6,2 6,0.6 5.4,0'/><polygon points='0,2 1,3 2.4,3 0,0.6'/></g></svg>`);
1785

1786 1787 1788
function getSquigglySVGData(color: Color) {
	return squigglyStart + encodeURIComponent(color.toString()) + squigglyEnd;
}
1789

1790 1791 1792 1793 1794 1795 1796
const dotdotdotStart = encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" height="3" width="12"><g fill="`);
const dotdotdotEnd = encodeURIComponent(`"><circle cx="1" cy="1" r="1"/><circle cx="5" cy="1" r="1"/><circle cx="9" cy="1" r="1"/></g></svg>`);

function getDotDotDotSVGData(color: Color) {
	return dotdotdotStart + encodeURIComponent(color.toString()) + dotdotdotEnd;
}

1797
registerThemingParticipant((theme, collector) => {
M
Matt Bierner 已提交
1798
	const errorBorderColor = theme.getColor(editorErrorBorder);
1799
	if (errorBorderColor) {
1800
		collector.addRule(`.monaco-editor .${ClassName.EditorErrorDecoration} { border-bottom: 4px double ${errorBorderColor}; }`);
1801
	}
M
Matt Bierner 已提交
1802
	const errorForeground = theme.getColor(editorErrorForeground);
1803
	if (errorForeground) {
1804
		collector.addRule(`.monaco-editor .${ClassName.EditorErrorDecoration} { background: url("data:image/svg+xml,${getSquigglySVGData(errorForeground)}") repeat-x bottom left; }`);
1805 1806
	}

M
Matt Bierner 已提交
1807
	const warningBorderColor = theme.getColor(editorWarningBorder);
1808
	if (warningBorderColor) {
1809
		collector.addRule(`.monaco-editor .${ClassName.EditorWarningDecoration} { border-bottom: 4px double ${warningBorderColor}; }`);
1810
	}
M
Matt Bierner 已提交
1811
	const warningForeground = theme.getColor(editorWarningForeground);
1812
	if (warningForeground) {
1813
		collector.addRule(`.monaco-editor .${ClassName.EditorWarningDecoration} { background: url("data:image/svg+xml,${getSquigglySVGData(warningForeground)}") repeat-x bottom left; }`);
1814 1815
	}

M
Matt Bierner 已提交
1816
	const infoBorderColor = theme.getColor(editorInfoBorder);
1817 1818
	if (infoBorderColor) {
		collector.addRule(`.monaco-editor .${ClassName.EditorInfoDecoration} { border-bottom: 4px double ${infoBorderColor}; }`);
1819
	}
M
Matt Bierner 已提交
1820
	const infoForeground = theme.getColor(editorInfoForeground);
1821
	if (infoForeground) {
1822
		collector.addRule(`.monaco-editor .${ClassName.EditorInfoDecoration} { background: url("data:image/svg+xml,${getSquigglySVGData(infoForeground)}") repeat-x bottom left; }`);
1823
	}
1824

M
Matt Bierner 已提交
1825
	const hintBorderColor = theme.getColor(editorHintBorder);
1826
	if (hintBorderColor) {
1827
		collector.addRule(`.monaco-editor .${ClassName.EditorHintDecoration} { border-bottom: 2px dotted ${hintBorderColor}; }`);
1828
	}
M
Matt Bierner 已提交
1829
	const hintForeground = theme.getColor(editorHintForeground);
1830
	if (hintForeground) {
1831
		collector.addRule(`.monaco-editor .${ClassName.EditorHintDecoration} { background: url("data:image/svg+xml,${getDotDotDotSVGData(hintForeground)}") no-repeat bottom left; }`);
1832
	}
1833

1834
	const unnecessaryForeground = theme.getColor(editorUnnecessaryCodeOpacity);
1835
	if (unnecessaryForeground) {
1836
		collector.addRule(`.${SHOW_UNUSED_ENABLED_CLASS} .monaco-editor .${ClassName.EditorUnnecessaryInlineDecoration} { opacity: ${unnecessaryForeground.rgba.a}; }`);
1837 1838 1839 1840 1841
	}

	const unnecessaryBorder = theme.getColor(editorUnnecessaryCodeBorder);
	if (unnecessaryBorder) {
		collector.addRule(`.${SHOW_UNUSED_ENABLED_CLASS} .monaco-editor .${ClassName.EditorUnnecessaryDecoration} { border-bottom: 2px dashed ${unnecessaryBorder}; }`);
1842
	}
1843
});