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

A
Alex Dima 已提交
7
import * as nls from 'vs/nls';
J
Johannes Rieken 已提交
8 9
import Event, { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
10
import * as objects from 'vs/base/common/objects';
A
Alex Dima 已提交
11
import * as platform from 'vs/base/common/platform';
J
Johannes Rieken 已提交
12 13
import { Extensions, IConfigurationRegistry, IConfigurationNode } from 'vs/platform/configuration/common/configurationRegistry';
import { Registry } from 'vs/platform/platform';
14
import { DefaultConfig, DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/common/config/defaultConfig';
A
Alex Dima 已提交
15
import * as editorCommon from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
16 17
import { EditorLayoutProvider } from 'vs/editor/common/viewLayout/editorLayoutProvider';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
18
import { FontInfo, BareFontInfo } from 'vs/editor/common/config/fontInfo';
19
import { Constants } from 'vs/editor/common/core/uint';
A
Alex Dima 已提交
20
import { EditorZoom } from 'vs/editor/common/config/editorZoom';
E
Erich Gamma 已提交
21

22 23 24 25 26 27 28
/**
 * Control what pressing Tab does.
 * If it is false, pressing Tab or Shift-Tab will be handled by the editor.
 * If it is true, pressing Tab or Shift-Tab will move the browser focus.
 * Defaults to false.
 */
export interface ITabFocus {
J
Johannes Rieken 已提交
29
	onDidChangeTabFocus: Event<boolean>;
30
	getTabFocusMode(): boolean;
J
Johannes Rieken 已提交
31
	setTabFocusMode(tabFocusMode: boolean): void;
32 33 34 35 36 37
}

export const TabFocus: ITabFocus = new class {
	private _tabFocus: boolean = false;

	private _onDidChangeTabFocus: Emitter<boolean> = new Emitter<boolean>();
J
Johannes Rieken 已提交
38
	public onDidChangeTabFocus: Event<boolean> = this._onDidChangeTabFocus.event;
39 40 41 42 43

	public getTabFocusMode(): boolean {
		return this._tabFocus;
	}

J
Johannes Rieken 已提交
44
	public setTabFocusMode(tabFocusMode: boolean): void {
45 46 47 48 49 50 51 52 53
		if (this._tabFocus === tabFocusMode) {
			return;
		}

		this._tabFocus = tabFocusMode;
		this._onDidChangeTabFocus.fire(this._tabFocus);
	}
};

54 55 56 57 58 59 60 61 62 63 64 65 66
/**
 * Experimental screen reader support toggle
 */
export class GlobalScreenReaderNVDA {

	private static _value = false;
	private static _onChange = new Emitter<boolean>();
	public static onChange: Event<boolean> = GlobalScreenReaderNVDA._onChange.event;

	public static getValue(): boolean {
		return this._value;
	}

J
Johannes Rieken 已提交
67
	public static setValue(value: boolean): void {
68 69 70 71 72 73 74 75
		if (this._value === value) {
			return;
		}
		this._value = value;
		this._onChange.fire(this._value);
	}
}

E
Erich Gamma 已提交
76 77
export class ConfigurationWithDefaults {

J
Johannes Rieken 已提交
78
	private _editor: editorCommon.IEditorOptions;
E
Erich Gamma 已提交
79

J
Johannes Rieken 已提交
80
	constructor(options: editorCommon.IEditorOptions) {
A
Alex Dima 已提交
81
		this._editor = <editorCommon.IEditorOptions>objects.clone(DefaultConfig.editor);
E
Erich Gamma 已提交
82 83 84 85

		this._mergeOptionsIn(options);
	}

A
Alex Dima 已提交
86
	public getEditorOptions(): editorCommon.IEditorOptions {
E
Erich Gamma 已提交
87 88 89
		return this._editor;
	}

J
Johannes Rieken 已提交
90
	private _mergeOptionsIn(newOptions: editorCommon.IEditorOptions): void {
A
Alex Dima 已提交
91
		this._editor = objects.mixin(this._editor, newOptions || {});
E
Erich Gamma 已提交
92 93
	}

J
Johannes Rieken 已提交
94
	public updateOptions(newOptions: editorCommon.IEditorOptions): void {
E
Erich Gamma 已提交
95 96 97 98 99 100 101 102 103 104 105
		// Apply new options
		this._mergeOptionsIn(newOptions);
	}
}

class InternalEditorOptionsHelper {

	constructor() {
	}

	public static createInternalEditorOptions(
J
Johannes Rieken 已提交
106 107
		outerWidth: number, outerHeight: number,
		opts: editorCommon.IEditorOptions,
108
		fontInfo: FontInfo,
J
Johannes Rieken 已提交
109 110
		editorClassName: string,
		isDominatedByLongLines: boolean,
111
		maxLineNumber: number,
112
		canUseTranslate3d: boolean
113
	): editorCommon.InternalEditorOptions {
E
Erich Gamma 已提交
114 115

		let wrappingColumn = toInteger(opts.wrappingColumn, -1);
116
		let wordWrap = toBoolean(opts.wordWrap);
E
Erich Gamma 已提交
117

J
Johannes Rieken 已提交
118
		let stopRenderingLineAfter: number;
E
Erich Gamma 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132
		if (typeof opts.stopRenderingLineAfter !== 'undefined') {
			stopRenderingLineAfter = toInteger(opts.stopRenderingLineAfter, -1);
		} else if (wrappingColumn >= 0) {
			stopRenderingLineAfter = -1;
		} else {
			stopRenderingLineAfter = 10000;
		}

		let mouseWheelScrollSensitivity = toFloat(opts.mouseWheelScrollSensitivity, 1);
		let scrollbar = this._sanitizeScrollbarOpts(opts.scrollbar, mouseWheelScrollSensitivity);

		let glyphMargin = toBoolean(opts.glyphMargin);
		let lineNumbers = opts.lineNumbers;
		let lineNumbersMinChars = toInteger(opts.lineNumbersMinChars, 1);
133 134 135 136 137 138 139 140

		let lineDecorationsWidth: number;
		if (typeof opts.lineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(opts.lineDecorationsWidth)) {
			let multiple = parseFloat(opts.lineDecorationsWidth.substr(0, opts.lineDecorationsWidth.length - 2));
			lineDecorationsWidth = multiple * fontInfo.typicalHalfwidthCharacterWidth;
		} else {
			lineDecorationsWidth = toInteger(opts.lineDecorationsWidth, 0);
		}
M
Martin Aeschlimann 已提交
141
		if (opts.folding) {
142
			lineDecorationsWidth += 16;
M
Martin Aeschlimann 已提交
143
		}
144
		let renderLineNumbers: boolean;
J
Johannes Rieken 已提交
145
		let renderCustomLineNumbers: (lineNumber: number) => string;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
		let renderRelativeLineNumbers: boolean;

		// Compatibility with old true or false values
		if (<any>lineNumbers === true) {
			lineNumbers = 'on';
		} else if (<any>lineNumbers === false) {
			lineNumbers = 'off';
		}

		if (typeof lineNumbers === 'function') {
			renderLineNumbers = true;
			renderCustomLineNumbers = lineNumbers;
			renderRelativeLineNumbers = false;
		} else if (lineNumbers === 'relative') {
			renderLineNumbers = true;
			renderCustomLineNumbers = null;
			renderRelativeLineNumbers = true;
		} else if (lineNumbers === 'on') {
			renderLineNumbers = true;
			renderCustomLineNumbers = null;
			renderRelativeLineNumbers = false;
		} else {
			renderLineNumbers = false;
			renderCustomLineNumbers = null;
			renderRelativeLineNumbers = false;
		}

E
Erich Gamma 已提交
173 174 175 176
		let layoutInfo = EditorLayoutProvider.compute({
			outerWidth: outerWidth,
			outerHeight: outerHeight,
			showGlyphMargin: glyphMargin,
177
			lineHeight: fontInfo.lineHeight,
178
			showLineNumbers: renderLineNumbers,
E
Erich Gamma 已提交
179 180
			lineNumbersMinChars: lineNumbersMinChars,
			lineDecorationsWidth: lineDecorationsWidth,
181
			maxDigitWidth: fontInfo.maxDigitWidth,
182
			maxLineNumber: maxLineNumber,
E
Erich Gamma 已提交
183 184 185 186 187 188 189 190 191 192 193
			verticalScrollbarWidth: scrollbar.verticalScrollbarSize,
			horizontalScrollbarHeight: scrollbar.horizontalScrollbarSize,
			scrollbarArrowSize: scrollbar.arrowSize,
			verticalScrollbarHasArrows: scrollbar.verticalHasArrows
		});

		if (isDominatedByLongLines && wrappingColumn > 0) {
			// Force viewport width wrapping if model is dominated by long lines
			wrappingColumn = 0;
		}

194
		let bareWrappingInfo: { isViewportWrapping: boolean; wrappingColumn: number; };
E
Erich Gamma 已提交
195 196
		if (wrappingColumn === 0) {
			// If viewport width wrapping is enabled
197
			bareWrappingInfo = {
E
Erich Gamma 已提交
198
				isViewportWrapping: true,
199
				wrappingColumn: Math.max(1, Math.floor((layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth) / fontInfo.typicalHalfwidthCharacterWidth))
E
Erich Gamma 已提交
200
			};
201
		} else if (wrappingColumn > 0 && wordWrap === true) {
202 203 204 205 206
			// Enable smart viewport wrapping
			bareWrappingInfo = {
				isViewportWrapping: true,
				wrappingColumn: Math.min(wrappingColumn, Math.floor((layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth) / fontInfo.typicalHalfwidthCharacterWidth))
			};
E
Erich Gamma 已提交
207 208
		} else if (wrappingColumn > 0) {
			// Wrapping is enabled
209
			bareWrappingInfo = {
E
Erich Gamma 已提交
210 211 212 213
				isViewportWrapping: false,
				wrappingColumn: wrappingColumn
			};
		} else {
214
			bareWrappingInfo = {
E
Erich Gamma 已提交
215 216 217 218
				isViewportWrapping: false,
				wrappingColumn: -1
			};
		}
219 220 221 222 223 224 225 226
		let wrappingInfo = new editorCommon.EditorWrappingInfo({
			isViewportWrapping: bareWrappingInfo.isViewportWrapping,
			wrappingColumn: bareWrappingInfo.wrappingColumn,
			wrappingIndent: wrappingIndentFromString(opts.wrappingIndent),
			wordWrapBreakBeforeCharacters: String(opts.wordWrapBreakBeforeCharacters),
			wordWrapBreakAfterCharacters: String(opts.wordWrapBreakAfterCharacters),
			wordWrapBreakObtrusiveCharacters: String(opts.wordWrapBreakObtrusiveCharacters),
		});
E
Erich Gamma 已提交
227

228 229
		let readOnly = toBoolean(opts.readOnly);

230
		let tabFocusMode = TabFocus.getTabFocusMode();
231 232 233 234
		if (readOnly) {
			tabFocusMode = true;
		}

235

236 237 238 239 240 241 242 243
		let renderWhitespace = opts.renderWhitespace;
		// Compatibility with old true or false values
		if (<any>renderWhitespace === true) {
			renderWhitespace = 'boundary';
		} else if (<any>renderWhitespace === false) {
			renderWhitespace = 'none';
		}

244 245 246 247 248 249 250 251
		let renderLineHighlight = opts.renderLineHighlight;
		// Compatibility with old true or false values
		if (<any>renderLineHighlight === true) {
			renderLineHighlight = 'line';
		} else if (<any>renderLineHighlight === false) {
			renderLineHighlight = 'none';
		}

252
		let viewInfo = new editorCommon.InternalEditorViewOptions({
253
			theme: opts.theme,
254
			canUseTranslate3d: canUseTranslate3d,
255
			disableMonospaceOptimizations: toBoolean(opts.disableMonospaceOptimizations),
256 257 258
			experimentalScreenReader: toBoolean(opts.experimentalScreenReader),
			rulers: toSortedIntegerArray(opts.rulers),
			ariaLabel: String(opts.ariaLabel),
259 260 261
			renderLineNumbers: renderLineNumbers,
			renderCustomLineNumbers: renderCustomLineNumbers,
			renderRelativeLineNumbers: renderRelativeLineNumbers,
E
Erich Gamma 已提交
262 263 264 265 266
			selectOnLineNumbers: toBoolean(opts.selectOnLineNumbers),
			glyphMargin: glyphMargin,
			revealHorizontalRightPadding: toInteger(opts.revealHorizontalRightPadding, 0),
			roundedSelection: toBoolean(opts.roundedSelection),
			overviewRulerLanes: toInteger(opts.overviewRulerLanes, 0, 3),
267
			cursorBlinking: cursorBlinkingStyleFromString(opts.cursorBlinking),
268
			mouseWheelZoom: toBoolean(opts.mouseWheelZoom),
A
Alex Dima 已提交
269
			cursorStyle: cursorStyleFromString(opts.cursorStyle),
E
Erich Gamma 已提交
270 271
			hideCursorInOverviewRuler: toBoolean(opts.hideCursorInOverviewRuler),
			scrollBeyondLastLine: toBoolean(opts.scrollBeyondLastLine),
272 273
			editorClassName: editorClassName,
			stopRenderingLineAfter: stopRenderingLineAfter,
274
			renderWhitespace: renderWhitespace,
275
			renderControlCharacters: toBoolean(opts.renderControlCharacters),
276
			renderIndentGuides: toBoolean(opts.renderIndentGuides),
277
			renderLineHighlight: renderLineHighlight,
278
			scrollbar: scrollbar,
J
Joao Moreno 已提交
279
			fixedOverflowWidgets: toBoolean(opts.fixedOverflowWidgets)
280 281
		});

A
Alex Dima 已提交
282
		let contribInfo = new editorCommon.EditorContribOptions({
283
			selectionClipboard: toBoolean(opts.selectionClipboard),
E
Erich Gamma 已提交
284 285 286 287
			hover: toBoolean(opts.hover),
			contextmenu: toBoolean(opts.contextmenu),
			quickSuggestions: toBoolean(opts.quickSuggestions),
			quickSuggestionsDelay: toInteger(opts.quickSuggestionsDelay),
J
Joao Moreno 已提交
288
			parameterHints: toBoolean(opts.parameterHints),
E
Erich Gamma 已提交
289 290
			iconsInSuggestions: toBoolean(opts.iconsInSuggestions),
			formatOnType: toBoolean(opts.formatOnType),
291
			formatOnPaste: toBoolean(opts.formatOnPaste),
E
Erich Gamma 已提交
292
			suggestOnTriggerCharacters: toBoolean(opts.suggestOnTriggerCharacters),
293
			acceptSuggestionOnEnter: toBoolean(opts.acceptSuggestionOnEnter),
294
			acceptSuggestionOnCommitCharacter: toBoolean(opts.acceptSuggestionOnCommitCharacter),
295
			snippetSuggestions: opts.snippetSuggestions,
296
			emptySelectionClipboard: opts.emptySelectionClipboard,
297
			tabCompletion: opts.tabCompletion,
298
			wordBasedSuggestions: opts.wordBasedSuggestions,
J
Joao Moreno 已提交
299 300
			suggestFontSize: opts.suggestFontSize,
			suggestLineHeight: opts.suggestLineHeight,
E
Erich Gamma 已提交
301
			selectionHighlight: toBoolean(opts.selectionHighlight),
302
			codeLens: opts.referenceInfos && opts.codeLens,
M
Martin Aeschlimann 已提交
303
			folding: toBoolean(opts.folding),
A
Alex Dima 已提交
304 305
		});

306 307 308 309
		return new editorCommon.InternalEditorOptions({
			lineHeight: fontInfo.lineHeight, // todo -> duplicated in styling
			readOnly: readOnly,
			wordSeparators: String(opts.wordSeparators),
A
Alex Dima 已提交
310
			autoClosingBrackets: toBoolean(opts.autoClosingBrackets),
311
			useTabStops: toBoolean(opts.useTabStops),
312
			tabFocusMode: tabFocusMode,
E
Erich Gamma 已提交
313
			layoutInfo: layoutInfo,
314
			fontInfo: fontInfo,
315
			viewInfo: viewInfo,
E
Erich Gamma 已提交
316
			wrappingInfo: wrappingInfo,
A
Alex Dima 已提交
317
			contribInfo: contribInfo,
318
		});
E
Erich Gamma 已提交
319 320
	}

J
Johannes Rieken 已提交
321
	private static _sanitizeScrollbarOpts(raw: editorCommon.IEditorScrollbarOptions, mouseWheelScrollSensitivity: number): editorCommon.InternalEditorScrollbarOptions {
A
Alex Dima 已提交
322

A
Alex Dima 已提交
323
		let visibilityFromString = (visibility: string) => {
A
Alex Dima 已提交
324 325 326 327 328 329 330 331 332 333
			switch (visibility) {
				case 'hidden':
					return ScrollbarVisibility.Hidden;
				case 'visible':
					return ScrollbarVisibility.Visible;
				default:
					return ScrollbarVisibility.Auto;
			}
		};

A
Alex Dima 已提交
334 335
		let horizontalScrollbarSize = toIntegerWithDefault(raw.horizontalScrollbarSize, 10);
		let verticalScrollbarSize = toIntegerWithDefault(raw.verticalScrollbarSize, 14);
A
Alex Dima 已提交
336 337 338
		return new editorCommon.InternalEditorScrollbarOptions({
			vertical: visibilityFromString(raw.vertical),
			horizontal: visibilityFromString(raw.horizontal),
E
Erich Gamma 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353

			arrowSize: toIntegerWithDefault(raw.arrowSize, 11),
			useShadows: toBooleanWithDefault(raw.useShadows, true),

			verticalHasArrows: toBooleanWithDefault(raw.verticalHasArrows, false),
			horizontalHasArrows: toBooleanWithDefault(raw.horizontalHasArrows, false),

			horizontalScrollbarSize: horizontalScrollbarSize,
			horizontalSliderSize: toIntegerWithDefault(raw.horizontalSliderSize, horizontalScrollbarSize),

			verticalScrollbarSize: verticalScrollbarSize,
			verticalSliderSize: toIntegerWithDefault(raw.verticalSliderSize, verticalScrollbarSize),

			handleMouseWheel: toBooleanWithDefault(raw.handleMouseWheel, true),
			mouseWheelScrollSensitivity: mouseWheelScrollSensitivity
A
Alex Dima 已提交
354
		});
E
Erich Gamma 已提交
355 356 357
	}
}

J
Johannes Rieken 已提交
358
function toBoolean(value: any): boolean {
E
Erich Gamma 已提交
359 360 361
	return value === 'false' ? false : Boolean(value);
}

J
Johannes Rieken 已提交
362
function toBooleanWithDefault(value: any, defaultValue: boolean): boolean {
E
Erich Gamma 已提交
363 364 365 366 367 368 369
	if (typeof value === 'undefined') {
		return defaultValue;
	}
	return toBoolean(value);
}

function toFloat(source: any, defaultValue: number): number {
A
Alex Dima 已提交
370
	let r = parseFloat(source);
E
Erich Gamma 已提交
371 372 373 374 375 376
	if (isNaN(r)) {
		r = defaultValue;
	}
	return r;
}

377
function toInteger(source: any, minimum: number = Constants.MIN_SAFE_SMALL_INTEGER, maximum: number = Constants.MAX_SAFE_SMALL_INTEGER): number {
A
Alex Dima 已提交
378
	let r = parseInt(source, 10);
E
Erich Gamma 已提交
379 380 381
	if (isNaN(r)) {
		r = 0;
	}
382 383 384
	r = Math.max(minimum, r);
	r = Math.min(maximum, r);
	return r | 0;
E
Erich Gamma 已提交
385 386
}

J
Johannes Rieken 已提交
387
function toSortedIntegerArray(source: any): number[] {
388 389 390 391 392 393 394 395 396
	if (!Array.isArray(source)) {
		return [];
	}
	let arrSource = <any[]>source;
	let r = arrSource.map(el => toInteger(el));
	r.sort();
	return r;
}

J
Johannes Rieken 已提交
397
function wrappingIndentFromString(wrappingIndent: string): editorCommon.WrappingIndent {
A
Alex Dima 已提交
398 399 400 401 402 403 404 405 406
	if (wrappingIndent === 'indent') {
		return editorCommon.WrappingIndent.Indent;
	} else if (wrappingIndent === 'same') {
		return editorCommon.WrappingIndent.Same;
	} else {
		return editorCommon.WrappingIndent.None;
	}
}

J
Johannes Rieken 已提交
407
function cursorStyleFromString(cursorStyle: string): editorCommon.TextEditorCursorStyle {
A
Alex Dima 已提交
408 409 410 411 412 413 414 415 416 417
	if (cursorStyle === 'line') {
		return editorCommon.TextEditorCursorStyle.Line;
	} else if (cursorStyle === 'block') {
		return editorCommon.TextEditorCursorStyle.Block;
	} else if (cursorStyle === 'underline') {
		return editorCommon.TextEditorCursorStyle.Underline;
	}
	return editorCommon.TextEditorCursorStyle.Line;
}

418
function cursorBlinkingStyleFromString(cursorBlinkingStyle: string): editorCommon.TextEditorCursorBlinkingStyle {
419 420 421 422 423 424 425 426 427 428 429 430
	switch (cursorBlinkingStyle) {
		case 'blink':
			return editorCommon.TextEditorCursorBlinkingStyle.Blink;
		case 'smooth':
			return editorCommon.TextEditorCursorBlinkingStyle.Smooth;
		case 'phase':
			return editorCommon.TextEditorCursorBlinkingStyle.Phase;
		case 'expand':
			return editorCommon.TextEditorCursorBlinkingStyle.Expand;
		case 'visible': // maintain compatibility
		case 'solid':
			return editorCommon.TextEditorCursorBlinkingStyle.Solid;
431 432 433 434
	}
	return editorCommon.TextEditorCursorBlinkingStyle.Blink;
}

J
Johannes Rieken 已提交
435
function toIntegerWithDefault(source: any, defaultValue: number): number {
E
Erich Gamma 已提交
436 437 438 439 440 441
	if (typeof source === 'undefined') {
		return defaultValue;
	}
	return toInteger(source);
}

442 443
export interface IElementSizeObserver {
	startObserving(): void;
J
Johannes Rieken 已提交
444
	observe(dimension?: editorCommon.IDimension): void;
445 446 447 448 449
	dispose(): void;
	getWidth(): number;
	getHeight(): number;
}

A
Alex Dima 已提交
450
export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration {
E
Erich Gamma 已提交
451

J
Johannes Rieken 已提交
452 453
	public editor: editorCommon.InternalEditorOptions;
	public editorClone: editorCommon.InternalEditorOptions;
E
Erich Gamma 已提交
454

J
Johannes Rieken 已提交
455
	protected _configWithDefaults: ConfigurationWithDefaults;
456
	protected _elementSizeObserver: IElementSizeObserver;
J
Johannes Rieken 已提交
457 458
	private _isDominatedByLongLines: boolean;
	private _maxLineNumber: number;
E
Erich Gamma 已提交
459

A
Alex Dima 已提交
460 461
	private _onDidChange = this._register(new Emitter<editorCommon.IConfigurationChangedEvent>());
	public onDidChange: Event<editorCommon.IConfigurationChangedEvent> = this._onDidChange.event;
A
Alex Dima 已提交
462

J
Johannes Rieken 已提交
463
	constructor(options: editorCommon.IEditorOptions, elementSizeObserver: IElementSizeObserver = null) {
A
Alex Dima 已提交
464
		super();
E
Erich Gamma 已提交
465
		this._configWithDefaults = new ConfigurationWithDefaults(options);
466
		this._elementSizeObserver = elementSizeObserver;
E
Erich Gamma 已提交
467
		this._isDominatedByLongLines = false;
468
		this._maxLineNumber = 1;
E
Erich Gamma 已提交
469
		this.editor = this._computeInternalOptions();
470
		this.editorClone = this.editor.clone();
471
		this._register(EditorZoom.onDidChangeZoomLevel(_ => this._recomputeOptions()));
472
		this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions()));
E
Erich Gamma 已提交
473 474 475 476 477 478 479
	}

	public dispose(): void {
		super.dispose();
	}

	protected _recomputeOptions(): void {
480 481
		this._setOptions(this._computeInternalOptions());
	}
482

J
Johannes Rieken 已提交
483
	private _setOptions(newOptions: editorCommon.InternalEditorOptions): void {
484 485
		if (this.editor && this.editor.equals(newOptions)) {
			return;
E
Erich Gamma 已提交
486 487
		}

488 489 490 491
		let changeEvent = this.editor.createChangeEvent(newOptions);
		this.editor = newOptions;
		this.editorClone = this.editor.clone();
		this._onDidChange.fire(changeEvent);
E
Erich Gamma 已提交
492 493
	}

A
Alex Dima 已提交
494
	public getRawOptions(): editorCommon.IEditorOptions {
E
Erich Gamma 已提交
495 496 497
		return this._configWithDefaults.getEditorOptions();
	}

498
	private _computeInternalOptions(): editorCommon.InternalEditorOptions {
E
Erich Gamma 已提交
499 500
		let opts = this._configWithDefaults.getEditorOptions();

501
		let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures));
E
Erich Gamma 已提交
502

503 504 505 506 507 508
		let disableTranslate3d = toBoolean(opts.disableTranslate3d);
		let canUseTranslate3d = this._getCanUseTranslate3d();
		if (disableTranslate3d) {
			canUseTranslate3d = false;
		}

509 510
		let bareFontInfo = BareFontInfo.createFromRawSettings(opts);

511
		return InternalEditorOptionsHelper.createInternalEditorOptions(
E
Erich Gamma 已提交
512 513 514
			this.getOuterWidth(),
			this.getOuterHeight(),
			opts,
515
			this.readConfiguration(bareFontInfo),
516
			editorClassName,
E
Erich Gamma 已提交
517
			this._isDominatedByLongLines,
518
			this._maxLineNumber,
519
			canUseTranslate3d
E
Erich Gamma 已提交
520 521 522
		);
	}

J
Johannes Rieken 已提交
523
	public updateOptions(newOptions: editorCommon.IEditorOptions): void {
E
Erich Gamma 已提交
524 525 526 527
		this._configWithDefaults.updateOptions(newOptions);
		this._recomputeOptions();
	}

J
Johannes Rieken 已提交
528
	public setIsDominatedByLongLines(isDominatedByLongLines: boolean): void {
E
Erich Gamma 已提交
529 530 531 532
		this._isDominatedByLongLines = isDominatedByLongLines;
		this._recomputeOptions();
	}

J
Johannes Rieken 已提交
533
	public setMaxLineNumber(maxLineNumber: number): void {
534
		this._maxLineNumber = maxLineNumber;
E
Erich Gamma 已提交
535 536 537
		this._recomputeOptions();
	}

J
Johannes Rieken 已提交
538
	protected abstract _getEditorClassName(theme: string, fontLigatures: boolean): string;
E
Erich Gamma 已提交
539

540
	protected abstract getOuterWidth(): number;
E
Erich Gamma 已提交
541

542
	protected abstract getOuterHeight(): number;
E
Erich Gamma 已提交
543

544 545
	protected abstract _getCanUseTranslate3d(): boolean;

546
	protected abstract readConfiguration(styling: BareFontInfo): FontInfo;
E
Erich Gamma 已提交
547 548
}

549 550
const configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration);
const editorConfiguration: IConfigurationNode = {
E
Erich Gamma 已提交
551 552 553
	'id': 'editor',
	'order': 5,
	'type': 'object',
554
	'title': nls.localize('editorConfigurationTitle', "Editor"),
555
	'overridable': true,
J
Johannes Rieken 已提交
556 557
	'properties': {
		'editor.fontFamily': {
E
Erich Gamma 已提交
558 559 560 561
			'type': 'string',
			'default': DefaultConfig.editor.fontFamily,
			'description': nls.localize('fontFamily', "Controls the font family.")
		},
J
Johannes Rieken 已提交
562
		'editor.fontWeight': {
563
			'type': 'string',
564
			'enum': ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
565 566 567
			'default': DefaultConfig.editor.fontWeight,
			'description': nls.localize('fontWeight', "Controls the font weight.")
		},
J
Johannes Rieken 已提交
568
		'editor.fontSize': {
E
Erich Gamma 已提交
569 570
			'type': 'number',
			'default': DefaultConfig.editor.fontSize,
571
			'description': nls.localize('fontSize', "Controls the font size in pixels.")
E
Erich Gamma 已提交
572
		},
J
Johannes Rieken 已提交
573
		'editor.lineHeight': {
E
Erich Gamma 已提交
574 575
			'type': 'number',
			'default': DefaultConfig.editor.lineHeight,
576
			'description': nls.localize('lineHeight', "Controls the line height. Use 0 to compute the lineHeight from the fontSize.")
E
Erich Gamma 已提交
577
		},
J
Johannes Rieken 已提交
578
		'editor.lineNumbers': {
579 580
			'type': 'string',
			'enum': ['off', 'on', 'relative'],
E
Erich Gamma 已提交
581
			'default': DefaultConfig.editor.lineNumbers,
582
			'description': nls.localize('lineNumbers', "Controls the display of line numbers. Possible values are 'on', 'off', and 'relative'. 'relative' shows the line count from the current cursor position.")
E
Erich Gamma 已提交
583
		},
J
Johannes Rieken 已提交
584
		'editor.rulers': {
585 586 587 588 589 590 591
			'type': 'array',
			'items': {
				'type': 'number'
			},
			'default': DefaultConfig.editor.rulers,
			'description': nls.localize('rulers', "Columns at which to show vertical rulers")
		},
J
Johannes Rieken 已提交
592
		'editor.wordSeparators': {
A
Alex Dima 已提交
593 594 595 596
			'type': 'string',
			'default': DefaultConfig.editor.wordSeparators,
			'description': nls.localize('wordSeparators', "Characters that will be used as word separators when doing word related navigations or operations")
		},
J
Johannes Rieken 已提交
597
		'editor.tabSize': {
598 599
			'type': 'number',
			'default': DEFAULT_INDENTATION.tabSize,
E
Erich Gamma 已提交
600
			'minimum': 1,
601
			'description': nls.localize('tabSize', "The number of spaces a tab is equal to. This setting is overriden based on the file contents when `editor.detectIndentation` is on."),
602
			'errorMessage': nls.localize('tabSize.errorMessage', "Expected 'number'. Note that the value \"auto\" has been replaced by the `editor.detectIndentation` setting.")
E
Erich Gamma 已提交
603
		},
J
Johannes Rieken 已提交
604
		'editor.insertSpaces': {
605 606
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.insertSpaces,
607
			'description': nls.localize('insertSpaces', "Insert spaces when pressing Tab. This setting is overriden based on the file contents when `editor.detectIndentation` is on."),
608
			'errorMessage': nls.localize('insertSpaces.errorMessage', "Expected 'boolean'. Note that the value \"auto\" has been replaced by the `editor.detectIndentation` setting.")
E
Erich Gamma 已提交
609
		},
J
Johannes Rieken 已提交
610
		'editor.detectIndentation': {
611 612
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.detectIndentation,
A
Alex Dima 已提交
613
			'description': nls.localize('detectIndentation', "When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.")
614
		},
J
Johannes Rieken 已提交
615
		'editor.roundedSelection': {
E
Erich Gamma 已提交
616 617 618 619
			'type': 'boolean',
			'default': DefaultConfig.editor.roundedSelection,
			'description': nls.localize('roundedSelection', "Controls if selections have rounded corners")
		},
J
Johannes Rieken 已提交
620
		'editor.scrollBeyondLastLine': {
E
Erich Gamma 已提交
621 622 623 624
			'type': 'boolean',
			'default': DefaultConfig.editor.scrollBeyondLastLine,
			'description': nls.localize('scrollBeyondLastLine', "Controls if the editor will scroll beyond the last line")
		},
J
Johannes Rieken 已提交
625
		'editor.wrappingColumn': {
E
Erich Gamma 已提交
626 627 628
			'type': 'integer',
			'default': DefaultConfig.editor.wrappingColumn,
			'minimum': -1,
629
			'description': nls.localize('wrappingColumn', "Controls after how many characters the editor will wrap to the next line. Setting this to 0 turns on viewport width wrapping (word wrapping). Setting this to -1 forces the editor to never wrap.")
E
Erich Gamma 已提交
630
		},
J
Johannes Rieken 已提交
631
		'editor.wordWrap': {
632
			'type': 'boolean',
633 634
			'default': DefaultConfig.editor.wordWrap,
			'description': nls.localize('wordWrap', "Controls if lines should wrap. The lines will wrap at min(editor.wrappingColumn, viewportWidthInColumns).")
635
		},
J
Johannes Rieken 已提交
636
		'editor.wrappingIndent': {
E
Erich Gamma 已提交
637 638 639 640 641
			'type': 'string',
			'enum': ['none', 'same', 'indent'],
			'default': DefaultConfig.editor.wrappingIndent,
			'description': nls.localize('wrappingIndent', "Controls the indentation of wrapped lines. Can be one of 'none', 'same' or 'indent'.")
		},
J
Johannes Rieken 已提交
642
		'editor.mouseWheelScrollSensitivity': {
E
Erich Gamma 已提交
643 644 645 646
			'type': 'number',
			'default': DefaultConfig.editor.mouseWheelScrollSensitivity,
			'description': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events")
		},
J
Johannes Rieken 已提交
647
		'editor.quickSuggestions': {
E
Erich Gamma 已提交
648 649 650 651
			'type': 'boolean',
			'default': DefaultConfig.editor.quickSuggestions,
			'description': nls.localize('quickSuggestions', "Controls if quick suggestions should show up or not while typing")
		},
J
Johannes Rieken 已提交
652
		'editor.quickSuggestionsDelay': {
E
Erich Gamma 已提交
653 654 655 656 657
			'type': 'integer',
			'default': DefaultConfig.editor.quickSuggestionsDelay,
			'minimum': 0,
			'description': nls.localize('quickSuggestionsDelay', "Controls the delay in ms after which quick suggestions will show up")
		},
J
Johannes Rieken 已提交
658
		'editor.parameterHints': {
J
Joao Moreno 已提交
659 660 661 662
			'type': 'boolean',
			'default': DefaultConfig.editor.parameterHints,
			'description': nls.localize('parameterHints', "Enables parameter hints")
		},
J
Johannes Rieken 已提交
663
		'editor.autoClosingBrackets': {
E
Erich Gamma 已提交
664 665 666 667
			'type': 'boolean',
			'default': DefaultConfig.editor.autoClosingBrackets,
			'description': nls.localize('autoClosingBrackets', "Controls if the editor should automatically close brackets after opening them")
		},
J
Johannes Rieken 已提交
668
		'editor.formatOnType': {
E
Erich Gamma 已提交
669 670 671 672
			'type': 'boolean',
			'default': DefaultConfig.editor.formatOnType,
			'description': nls.localize('formatOnType', "Controls if the editor should automatically format the line after typing")
		},
673 674 675
		'editor.formatOnPaste': {
			'type': 'boolean',
			'default': DefaultConfig.editor.formatOnPaste,
676
			'description': nls.localize('formatOnPaste', "Controls if the editor should automatically format the pasted content. A formatter must be available and the formatter should be able to format a range in a document.")
677
		},
J
Johannes Rieken 已提交
678
		'editor.suggestOnTriggerCharacters': {
E
Erich Gamma 已提交
679 680 681 682
			'type': 'boolean',
			'default': DefaultConfig.editor.suggestOnTriggerCharacters,
			'description': nls.localize('suggestOnTriggerCharacters', "Controls if suggestions should automatically show up when typing trigger characters")
		},
J
Johannes Rieken 已提交
683
		'editor.acceptSuggestionOnEnter': {
684 685
			'type': 'boolean',
			'default': DefaultConfig.editor.acceptSuggestionOnEnter,
686 687 688 689 690 691
			'description': nls.localize('acceptSuggestionOnEnter', "Controls if suggestions should be accepted on 'Enter' - in addition to 'Tab'. Helps to avoid ambiguity between inserting new lines or accepting suggestions.")
		},
		'editor.acceptSuggestionOnCommitCharacter': {
			'type': 'boolean',
			'default': DefaultConfig.editor.acceptSuggestionOnCommitCharacter,
			'description': nls.localize('acceptSuggestionOnCommitCharacter', "Controls if suggestions should be accepted on commit characters. For instance in JavaScript the semi-colon (';') can be a commit character that accepts a suggestion and types that character.")
692
		},
693
		'editor.snippetSuggestions': {
694
			'type': 'string',
695 696 697
			'enum': ['top', 'bottom', 'inline', 'none'],
			'default': DefaultConfig.editor.snippetSuggestions,
			'description': nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.")
698
		},
699 700 701 702 703
		'editor.emptySelectionClipboard': {
			'type': 'boolean',
			'default': DefaultConfig.editor.emptySelectionClipboard,
			'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.")
		},
704 705 706 707 708
		'editor.wordBasedSuggestions': {
			'type': 'boolean',
			'default': DefaultConfig.editor.wordBasedSuggestions,
			'description': nls.localize('wordBasedSuggestions', "Enable word based suggestions.")
		},
J
Johannes Rieken 已提交
709
		'editor.suggestFontSize': {
J
Joao Moreno 已提交
710 711 712 713 714
			'type': 'integer',
			'default': 0,
			'minimum': 0,
			'description': nls.localize('suggestFontSize', "Font size for the suggest widget")
		},
J
Johannes Rieken 已提交
715
		'editor.suggestLineHeight': {
J
Joao Moreno 已提交
716 717 718 719 720
			'type': 'integer',
			'default': 0,
			'minimum': 0,
			'description': nls.localize('suggestLineHeight', "Line height for the suggest widget")
		},
721 722 723
		'editor.tabCompletion': {
			'type': 'boolean',
			'default': DefaultConfig.editor.tabCompletion,
724
			'description': nls.localize('tabCompletion', "Insert snippets when their prefix matches. Works best when 'quickSuggestions' aren't enabled.")
725
		},
J
Johannes Rieken 已提交
726
		'editor.selectionHighlight': {
E
Erich Gamma 已提交
727 728 729 730
			'type': 'boolean',
			'default': DefaultConfig.editor.selectionHighlight,
			'description': nls.localize('selectionHighlight', "Controls whether the editor should highlight similar matches to the selection")
		},
J
Johannes Rieken 已提交
731
		'editor.overviewRulerLanes': {
E
Erich Gamma 已提交
732 733 734 735
			'type': 'integer',
			'default': 3,
			'description': nls.localize('overviewRulerLanes', "Controls the number of decorations that can show up at the same position in the overview ruler")
		},
J
Johannes Rieken 已提交
736
		'editor.cursorBlinking': {
737
			'type': 'string',
738
			'enum': ['blink', 'smooth', 'phase', 'expand', 'solid'],
739
			'default': DefaultConfig.editor.cursorBlinking,
740
			'description': nls.localize('cursorBlinking', "Control the cursor animation style, possible values are 'blink', 'smooth', 'phase', 'expand' and 'solid'")
741
		},
742 743 744 745 746
		'editor.mouseWheelZoom': {
			'type': 'boolean',
			'default': DefaultConfig.editor.mouseWheelZoom,
			'description': nls.localize('mouseWheelZoom', "Zoom the font of the editor when using mouse wheel and holding Ctrl")
		},
J
Johannes Rieken 已提交
747
		'editor.cursorStyle': {
M
markrendle 已提交
748
			'type': 'string',
749
			'enum': ['block', 'line', 'underline'],
M
markrendle 已提交
750
			'default': DefaultConfig.editor.cursorStyle,
751
			'description': nls.localize('cursorStyle', "Controls the cursor style, accepted values are 'block', 'line' and 'underline'")
M
markrendle 已提交
752
		},
J
Johannes Rieken 已提交
753
		'editor.fontLigatures': {
754 755 756 757
			'type': 'boolean',
			'default': DefaultConfig.editor.fontLigatures,
			'description': nls.localize('fontLigatures', "Enables font ligatures")
		},
J
Johannes Rieken 已提交
758
		'editor.hideCursorInOverviewRuler': {
E
Erich Gamma 已提交
759 760 761 762 763
			'type': 'boolean',
			'default': DefaultConfig.editor.hideCursorInOverviewRuler,
			'description': nls.localize('hideCursorInOverviewRuler', "Controls if the cursor should be hidden in the overview ruler.")
		},
		'editor.renderWhitespace': {
764 765
			'type': 'string',
			'enum': ['none', 'boundary', 'all'],
E
Erich Gamma 已提交
766
			default: DefaultConfig.editor.renderWhitespace,
767
			description: nls.localize('renderWhitespace', "Controls how the editor should render whitespace characters, possibilities are 'none', 'boundary', and 'all'. The 'boundary' option does not render single spaces between words.")
E
Erich Gamma 已提交
768
		},
769 770 771 772 773
		'editor.renderControlCharacters': {
			'type': 'boolean',
			default: DefaultConfig.editor.renderControlCharacters,
			description: nls.localize('renderControlCharacters', "Controls whether the editor should render control characters")
		},
774 775 776 777 778
		'editor.renderIndentGuides': {
			'type': 'boolean',
			default: DefaultConfig.editor.renderIndentGuides,
			description: nls.localize('renderIndentGuides', "Controls whether the editor should render indent guides")
		},
779
		'editor.renderLineHighlight': {
780 781
			'type': 'string',
			'enum': ['none', 'gutter', 'line', 'all'],
782
			default: DefaultConfig.editor.renderLineHighlight,
783
			description: nls.localize('renderLineHighlight', "Controls how the editor should render the current line highlight, possibilities are 'none', 'gutter', 'line', and 'all'.")
784
		},
J
Johannes Rieken 已提交
785
		'editor.codeLens': {
E
Erich Gamma 已提交
786
			'type': 'boolean',
787 788
			'default': DefaultConfig.editor.codeLens,
			'description': nls.localize('codeLens', "Controls if the editor shows code lenses")
E
Erich Gamma 已提交
789
		},
J
Johannes Rieken 已提交
790
		'editor.folding': {
M
Martin Aeschlimann 已提交
791 792
			'type': 'boolean',
			'default': DefaultConfig.editor.folding,
793
			'description': nls.localize('folding', "Controls whether the editor has code folding enabled")
M
Martin Aeschlimann 已提交
794
		},
I
isidor 已提交
795 796 797 798 799
		'editor.glyphMargin': {
			'type': 'boolean',
			'default': DefaultConfig.editor.glyphMargin,
			'description': nls.localize('glyphMargin', "Controls whether the editor should render the vertical glyph margin. Glyph margin is mostly used for debugging.")
		},
J
Johannes Rieken 已提交
800
		'editor.useTabStops': {
801 802 803 804
			'type': 'boolean',
			'default': DefaultConfig.editor.useTabStops,
			'description': nls.localize('useTabStops', "Inserting and deleting whitespace follows tab stops")
		},
J
Johannes Rieken 已提交
805
		'editor.trimAutoWhitespace': {
806
			'type': 'boolean',
807
			'default': DEFAULT_TRIM_AUTO_WHITESPACE,
808 809
			'description': nls.localize('trimAutoWhitespace', "Remove trailing auto inserted whitespace")
		},
J
Johannes Rieken 已提交
810
		'editor.stablePeek': {
811
			'type': 'boolean',
812
			'default': false,
813
			'description': nls.localize('stablePeek', "Keep peek editors open even when double clicking their content or when hitting Escape.")
814
		},
J
Johannes Rieken 已提交
815
		'diffEditor.renderSideBySide': {
E
Erich Gamma 已提交
816 817 818 819
			'type': 'boolean',
			'default': true,
			'description': nls.localize('sideBySide', "Controls if the diff editor shows the diff side by side or inline")
		},
J
Johannes Rieken 已提交
820
		'diffEditor.ignoreTrimWhitespace': {
E
Erich Gamma 已提交
821 822 823
			'type': 'boolean',
			'default': true,
			'description': nls.localize('ignoreTrimWhitespace', "Controls if the diff editor shows changes in leading or trailing whitespace as diffs")
824 825 826 827 828
		},
		'diffEditor.renderIndicators': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('renderIndicators', "Controls if the diff editor shows +/- indicators for added/removed changes")
E
Erich Gamma 已提交
829 830
		}
	}
A
Alex Dima 已提交
831 832 833 834 835 836 837 838 839 840
};

if (platform.isLinux) {
	editorConfiguration['properties']['editor.selectionClipboard'] = {
		'type': 'boolean',
		'default': DefaultConfig.editor.selectionClipboard,
		'description': nls.localize('selectionClipboard', "Controls if the Linux primary clipboard should be supported.")
	};
}

841
configurationRegistry.registerConfiguration(editorConfiguration);