commonEditorConfig.ts 33.4 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';
16
import { EditorLayoutProvider } from 'vs/editor/common/viewLayout/editorLayoutProvider';
J
Johannes Rieken 已提交
17
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(
106 107
		outerWidth: number,
		outerHeight: number,
J
Johannes Rieken 已提交
108
		opts: editorCommon.IEditorOptions,
109
		fontInfo: FontInfo,
J
Johannes Rieken 已提交
110 111
		editorClassName: string,
		isDominatedByLongLines: boolean,
112
		maxLineNumber: number,
113 114
		canUseTranslate3d: boolean,
		pixelRatio: number
115
	): editorCommon.InternalEditorOptions {
E
Erich Gamma 已提交
116 117

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

J
Johannes Rieken 已提交
120
		let stopRenderingLineAfter: number;
E
Erich Gamma 已提交
121 122 123 124 125 126 127 128 129 130
		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);
131
		let minimap = this._sanitizeMinimapOpts(opts.minimap);
E
Erich Gamma 已提交
132 133 134 135

		let glyphMargin = toBoolean(opts.glyphMargin);
		let lineNumbers = opts.lineNumbers;
		let lineNumbersMinChars = toInteger(opts.lineNumbersMinChars, 1);
136 137 138 139 140 141 142 143

		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 已提交
144
		if (opts.folding) {
145
			lineDecorationsWidth += 16;
M
Martin Aeschlimann 已提交
146
		}
147
		let renderLineNumbers: boolean;
J
Johannes Rieken 已提交
148
		let renderCustomLineNumbers: (lineNumber: number) => string;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
		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 已提交
176 177 178 179
		let layoutInfo = EditorLayoutProvider.compute({
			outerWidth: outerWidth,
			outerHeight: outerHeight,
			showGlyphMargin: glyphMargin,
180
			lineHeight: fontInfo.lineHeight,
181
			showLineNumbers: renderLineNumbers,
E
Erich Gamma 已提交
182
			lineNumbersMinChars: lineNumbersMinChars,
A
Alex Dima 已提交
183
			maxLineNumber: maxLineNumber,
E
Erich Gamma 已提交
184
			lineDecorationsWidth: lineDecorationsWidth,
A
Alex Dima 已提交
185
			typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth,
186
			maxDigitWidth: fontInfo.maxDigitWidth,
E
Erich Gamma 已提交
187 188 189
			verticalScrollbarWidth: scrollbar.verticalScrollbarSize,
			horizontalScrollbarHeight: scrollbar.horizontalScrollbarSize,
			scrollbarArrowSize: scrollbar.arrowSize,
A
Alex Dima 已提交
190
			verticalScrollbarHasArrows: scrollbar.verticalHasArrows,
191
			minimap: minimap.enabled,
192
			pixelRatio: pixelRatio
E
Erich Gamma 已提交
193 194 195 196 197 198 199
		});

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

200
		let bareWrappingInfo: { isViewportWrapping: boolean; wrappingColumn: number; };
E
Erich Gamma 已提交
201 202
		if (wrappingColumn === 0) {
			// If viewport width wrapping is enabled
203
			bareWrappingInfo = {
E
Erich Gamma 已提交
204
				isViewportWrapping: true,
A
Alex Dima 已提交
205
				wrappingColumn: Math.max(1, layoutInfo.viewportColumn)
E
Erich Gamma 已提交
206
			};
207
		} else if (wrappingColumn > 0 && wordWrap === true) {
208 209 210
			// Enable smart viewport wrapping
			bareWrappingInfo = {
				isViewportWrapping: true,
A
Alex Dima 已提交
211
				wrappingColumn: Math.min(wrappingColumn, layoutInfo.viewportColumn)
212
			};
E
Erich Gamma 已提交
213 214
		} else if (wrappingColumn > 0) {
			// Wrapping is enabled
215
			bareWrappingInfo = {
E
Erich Gamma 已提交
216 217 218 219
				isViewportWrapping: false,
				wrappingColumn: wrappingColumn
			};
		} else {
220
			bareWrappingInfo = {
E
Erich Gamma 已提交
221 222 223 224
				isViewportWrapping: false,
				wrappingColumn: -1
			};
		}
225 226 227 228 229 230 231 232
		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 已提交
233

234 235
		let readOnly = toBoolean(opts.readOnly);

236
		let tabFocusMode = TabFocus.getTabFocusMode();
237 238 239 240
		if (readOnly) {
			tabFocusMode = true;
		}

241

242 243 244 245 246 247 248 249
		let renderWhitespace = opts.renderWhitespace;
		// Compatibility with old true or false values
		if (<any>renderWhitespace === true) {
			renderWhitespace = 'boundary';
		} else if (<any>renderWhitespace === false) {
			renderWhitespace = 'none';
		}

250 251 252 253 254 255 256 257
		let renderLineHighlight = opts.renderLineHighlight;
		// Compatibility with old true or false values
		if (<any>renderLineHighlight === true) {
			renderLineHighlight = 'line';
		} else if (<any>renderLineHighlight === false) {
			renderLineHighlight = 'none';
		}

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

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

314 315 316 317
		return new editorCommon.InternalEditorOptions({
			lineHeight: fontInfo.lineHeight, // todo -> duplicated in styling
			readOnly: readOnly,
			wordSeparators: String(opts.wordSeparators),
A
Alex Dima 已提交
318
			autoClosingBrackets: toBoolean(opts.autoClosingBrackets),
319
			useTabStops: toBoolean(opts.useTabStops),
320
			tabFocusMode: tabFocusMode,
E
Erich Gamma 已提交
321
			layoutInfo: layoutInfo,
322
			fontInfo: fontInfo,
323
			viewInfo: viewInfo,
E
Erich Gamma 已提交
324
			wrappingInfo: wrappingInfo,
A
Alex Dima 已提交
325
			contribInfo: contribInfo,
326
		});
E
Erich Gamma 已提交
327 328
	}

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

A
Alex Dima 已提交
331
		let visibilityFromString = (visibility: string) => {
A
Alex Dima 已提交
332 333 334 335 336 337 338 339 340 341
			switch (visibility) {
				case 'hidden':
					return ScrollbarVisibility.Hidden;
				case 'visible':
					return ScrollbarVisibility.Visible;
				default:
					return ScrollbarVisibility.Auto;
			}
		};

A
Alex Dima 已提交
342 343
		let horizontalScrollbarSize = toIntegerWithDefault(raw.horizontalScrollbarSize, 10);
		let verticalScrollbarSize = toIntegerWithDefault(raw.verticalScrollbarSize, 14);
A
Alex Dima 已提交
344 345 346
		return new editorCommon.InternalEditorScrollbarOptions({
			vertical: visibilityFromString(raw.vertical),
			horizontal: visibilityFromString(raw.horizontal),
E
Erich Gamma 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361

			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 已提交
362
		});
E
Erich Gamma 已提交
363
	}
364 365 366 367 368 369

	private static _sanitizeMinimapOpts(raw: editorCommon.IEditorMinimapOptions): editorCommon.InternalEditorMinimapOptions {
		return new editorCommon.InternalEditorMinimapOptions({
			enabled: toBooleanWithDefault(raw.enabled, false)
		});
	}
E
Erich Gamma 已提交
370 371
}

J
Johannes Rieken 已提交
372
function toBoolean(value: any): boolean {
E
Erich Gamma 已提交
373 374 375
	return value === 'false' ? false : Boolean(value);
}

J
Johannes Rieken 已提交
376
function toBooleanWithDefault(value: any, defaultValue: boolean): boolean {
E
Erich Gamma 已提交
377 378 379 380 381 382 383
	if (typeof value === 'undefined') {
		return defaultValue;
	}
	return toBoolean(value);
}

function toFloat(source: any, defaultValue: number): number {
A
Alex Dima 已提交
384
	let r = parseFloat(source);
E
Erich Gamma 已提交
385 386 387 388 389 390
	if (isNaN(r)) {
		r = defaultValue;
	}
	return r;
}

391
function toInteger(source: any, minimum: number = Constants.MIN_SAFE_SMALL_INTEGER, maximum: number = Constants.MAX_SAFE_SMALL_INTEGER): number {
A
Alex Dima 已提交
392
	let r = parseInt(source, 10);
E
Erich Gamma 已提交
393 394 395
	if (isNaN(r)) {
		r = 0;
	}
396 397 398
	r = Math.max(minimum, r);
	r = Math.min(maximum, r);
	return r | 0;
E
Erich Gamma 已提交
399 400
}

J
Johannes Rieken 已提交
401
function toSortedIntegerArray(source: any): number[] {
402 403 404 405 406 407 408 409 410
	if (!Array.isArray(source)) {
		return [];
	}
	let arrSource = <any[]>source;
	let r = arrSource.map(el => toInteger(el));
	r.sort();
	return r;
}

J
Johannes Rieken 已提交
411
function wrappingIndentFromString(wrappingIndent: string): editorCommon.WrappingIndent {
A
Alex Dima 已提交
412 413 414 415 416 417 418 419 420
	if (wrappingIndent === 'indent') {
		return editorCommon.WrappingIndent.Indent;
	} else if (wrappingIndent === 'same') {
		return editorCommon.WrappingIndent.Same;
	} else {
		return editorCommon.WrappingIndent.None;
	}
}

J
Johannes Rieken 已提交
421
function cursorStyleFromString(cursorStyle: string): editorCommon.TextEditorCursorStyle {
A
Alex Dima 已提交
422 423 424 425 426 427
	if (cursorStyle === 'line') {
		return editorCommon.TextEditorCursorStyle.Line;
	} else if (cursorStyle === 'block') {
		return editorCommon.TextEditorCursorStyle.Block;
	} else if (cursorStyle === 'underline') {
		return editorCommon.TextEditorCursorStyle.Underline;
428 429 430 431
	} else if (cursorStyle === 'line-thin') {
		return editorCommon.TextEditorCursorStyle.LineThin;
	} else if (cursorStyle === 'block-outline') {
		return editorCommon.TextEditorCursorStyle.BlockOutline;
432 433
	} else if (cursorStyle === 'underline-thin') {
		return editorCommon.TextEditorCursorStyle.UnderlineThin;
A
Alex Dima 已提交
434 435 436 437
	}
	return editorCommon.TextEditorCursorStyle.Line;
}

438
function cursorBlinkingStyleFromString(cursorBlinkingStyle: string): editorCommon.TextEditorCursorBlinkingStyle {
439 440 441 442 443 444 445 446 447 448 449 450
	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;
451 452 453 454
	}
	return editorCommon.TextEditorCursorBlinkingStyle.Blink;
}

J
Johannes Rieken 已提交
455
function toIntegerWithDefault(source: any, defaultValue: number): number {
E
Erich Gamma 已提交
456 457 458 459 460 461
	if (typeof source === 'undefined') {
		return defaultValue;
	}
	return toInteger(source);
}

462 463
export interface IElementSizeObserver {
	startObserving(): void;
J
Johannes Rieken 已提交
464
	observe(dimension?: editorCommon.IDimension): void;
465 466 467 468 469
	dispose(): void;
	getWidth(): number;
	getHeight(): number;
}

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

J
Johannes Rieken 已提交
472 473
	public editor: editorCommon.InternalEditorOptions;
	public editorClone: editorCommon.InternalEditorOptions;
E
Erich Gamma 已提交
474

J
Johannes Rieken 已提交
475
	protected _configWithDefaults: ConfigurationWithDefaults;
476
	protected _elementSizeObserver: IElementSizeObserver;
J
Johannes Rieken 已提交
477 478
	private _isDominatedByLongLines: boolean;
	private _maxLineNumber: number;
E
Erich Gamma 已提交
479

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

J
Johannes Rieken 已提交
483
	constructor(options: editorCommon.IEditorOptions, elementSizeObserver: IElementSizeObserver = null) {
A
Alex Dima 已提交
484
		super();
E
Erich Gamma 已提交
485
		this._configWithDefaults = new ConfigurationWithDefaults(options);
486
		this._elementSizeObserver = elementSizeObserver;
E
Erich Gamma 已提交
487
		this._isDominatedByLongLines = false;
488
		this._maxLineNumber = 1;
E
Erich Gamma 已提交
489
		this.editor = this._computeInternalOptions();
490
		this.editorClone = this.editor.clone();
491
		this._register(EditorZoom.onDidChangeZoomLevel(_ => this._recomputeOptions()));
492
		this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions()));
E
Erich Gamma 已提交
493 494 495 496 497 498 499
	}

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

	protected _recomputeOptions(): void {
500 501
		this._setOptions(this._computeInternalOptions());
	}
502

J
Johannes Rieken 已提交
503
	private _setOptions(newOptions: editorCommon.InternalEditorOptions): void {
504 505
		if (this.editor && this.editor.equals(newOptions)) {
			return;
E
Erich Gamma 已提交
506 507
		}

508 509 510 511
		let changeEvent = this.editor.createChangeEvent(newOptions);
		this.editor = newOptions;
		this.editorClone = this.editor.clone();
		this._onDidChange.fire(changeEvent);
E
Erich Gamma 已提交
512 513
	}

A
Alex Dima 已提交
514
	public getRawOptions(): editorCommon.IEditorOptions {
E
Erich Gamma 已提交
515 516 517
		return this._configWithDefaults.getEditorOptions();
	}

518
	private _computeInternalOptions(): editorCommon.InternalEditorOptions {
E
Erich Gamma 已提交
519 520
		let opts = this._configWithDefaults.getEditorOptions();

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

523 524 525 526 527 528
		let disableTranslate3d = toBoolean(opts.disableTranslate3d);
		let canUseTranslate3d = this._getCanUseTranslate3d();
		if (disableTranslate3d) {
			canUseTranslate3d = false;
		}

529 530
		let bareFontInfo = BareFontInfo.createFromRawSettings(opts);

531
		return InternalEditorOptionsHelper.createInternalEditorOptions(
E
Erich Gamma 已提交
532 533 534
			this.getOuterWidth(),
			this.getOuterHeight(),
			opts,
535
			this.readConfiguration(bareFontInfo),
536
			editorClassName,
E
Erich Gamma 已提交
537
			this._isDominatedByLongLines,
538
			this._maxLineNumber,
539 540
			canUseTranslate3d,
			this._getPixelRatio()
E
Erich Gamma 已提交
541 542 543
		);
	}

J
Johannes Rieken 已提交
544
	public updateOptions(newOptions: editorCommon.IEditorOptions): void {
E
Erich Gamma 已提交
545 546 547 548
		this._configWithDefaults.updateOptions(newOptions);
		this._recomputeOptions();
	}

J
Johannes Rieken 已提交
549
	public setIsDominatedByLongLines(isDominatedByLongLines: boolean): void {
E
Erich Gamma 已提交
550 551 552 553
		this._isDominatedByLongLines = isDominatedByLongLines;
		this._recomputeOptions();
	}

J
Johannes Rieken 已提交
554
	public setMaxLineNumber(maxLineNumber: number): void {
A
Alex Dima 已提交
555 556 557
		if (this._maxLineNumber === maxLineNumber) {
			return;
		}
558
		this._maxLineNumber = maxLineNumber;
E
Erich Gamma 已提交
559 560 561
		this._recomputeOptions();
	}

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

564
	protected abstract getOuterWidth(): number;
E
Erich Gamma 已提交
565

566
	protected abstract getOuterHeight(): number;
E
Erich Gamma 已提交
567

568 569
	protected abstract _getCanUseTranslate3d(): boolean;

570 571
	protected abstract _getPixelRatio(): number;

572
	protected abstract readConfiguration(styling: BareFontInfo): FontInfo;
E
Erich Gamma 已提交
573 574
}

575 576
const configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration);
const editorConfiguration: IConfigurationNode = {
E
Erich Gamma 已提交
577 578 579
	'id': 'editor',
	'order': 5,
	'type': 'object',
580
	'title': nls.localize('editorConfigurationTitle', "Editor"),
581
	'overridable': true,
J
Johannes Rieken 已提交
582 583
	'properties': {
		'editor.fontFamily': {
E
Erich Gamma 已提交
584 585 586 587
			'type': 'string',
			'default': DefaultConfig.editor.fontFamily,
			'description': nls.localize('fontFamily', "Controls the font family.")
		},
J
Johannes Rieken 已提交
588
		'editor.fontWeight': {
589
			'type': 'string',
590
			'enum': ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
591 592 593
			'default': DefaultConfig.editor.fontWeight,
			'description': nls.localize('fontWeight', "Controls the font weight.")
		},
J
Johannes Rieken 已提交
594
		'editor.fontSize': {
E
Erich Gamma 已提交
595 596
			'type': 'number',
			'default': DefaultConfig.editor.fontSize,
597
			'description': nls.localize('fontSize', "Controls the font size in pixels.")
E
Erich Gamma 已提交
598
		},
J
Johannes Rieken 已提交
599
		'editor.lineHeight': {
E
Erich Gamma 已提交
600 601
			'type': 'number',
			'default': DefaultConfig.editor.lineHeight,
602
			'description': nls.localize('lineHeight', "Controls the line height. Use 0 to compute the lineHeight from the fontSize.")
E
Erich Gamma 已提交
603
		},
J
Johannes Rieken 已提交
604
		'editor.lineNumbers': {
605 606
			'type': 'string',
			'enum': ['off', 'on', 'relative'],
E
Erich Gamma 已提交
607
			'default': DefaultConfig.editor.lineNumbers,
608
			'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 已提交
609
		},
J
Johannes Rieken 已提交
610
		'editor.rulers': {
611 612 613 614 615 616 617
			'type': 'array',
			'items': {
				'type': 'number'
			},
			'default': DefaultConfig.editor.rulers,
			'description': nls.localize('rulers', "Columns at which to show vertical rulers")
		},
J
Johannes Rieken 已提交
618
		'editor.wordSeparators': {
A
Alex Dima 已提交
619 620 621 622
			'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 已提交
623
		'editor.tabSize': {
624 625
			'type': 'number',
			'default': DEFAULT_INDENTATION.tabSize,
E
Erich Gamma 已提交
626
			'minimum': 1,
627
			'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."),
628
			'errorMessage': nls.localize('tabSize.errorMessage', "Expected 'number'. Note that the value \"auto\" has been replaced by the `editor.detectIndentation` setting.")
E
Erich Gamma 已提交
629
		},
J
Johannes Rieken 已提交
630
		'editor.insertSpaces': {
631 632
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.insertSpaces,
633
			'description': nls.localize('insertSpaces', "Insert spaces when pressing Tab. This setting is overriden based on the file contents when `editor.detectIndentation` is on."),
634
			'errorMessage': nls.localize('insertSpaces.errorMessage', "Expected 'boolean'. Note that the value \"auto\" has been replaced by the `editor.detectIndentation` setting.")
E
Erich Gamma 已提交
635
		},
J
Johannes Rieken 已提交
636
		'editor.detectIndentation': {
637 638
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.detectIndentation,
A
Alex Dima 已提交
639
			'description': nls.localize('detectIndentation', "When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.")
640
		},
J
Johannes Rieken 已提交
641
		'editor.roundedSelection': {
E
Erich Gamma 已提交
642 643 644 645
			'type': 'boolean',
			'default': DefaultConfig.editor.roundedSelection,
			'description': nls.localize('roundedSelection', "Controls if selections have rounded corners")
		},
J
Johannes Rieken 已提交
646
		'editor.scrollBeyondLastLine': {
E
Erich Gamma 已提交
647 648 649 650
			'type': 'boolean',
			'default': DefaultConfig.editor.scrollBeyondLastLine,
			'description': nls.localize('scrollBeyondLastLine', "Controls if the editor will scroll beyond the last line")
		},
651 652 653 654 655
		'editor.minimap.enabled': {
			'type': 'boolean',
			'default': DefaultConfig.editor.minimap.enabled,
			'description': nls.localize('minimap.enabled', "Controls if the minimap is shown")
		},
J
Johannes Rieken 已提交
656
		'editor.wrappingColumn': {
E
Erich Gamma 已提交
657 658 659
			'type': 'integer',
			'default': DefaultConfig.editor.wrappingColumn,
			'minimum': -1,
660
			'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 已提交
661
		},
J
Johannes Rieken 已提交
662
		'editor.wordWrap': {
663
			'type': 'boolean',
664 665
			'default': DefaultConfig.editor.wordWrap,
			'description': nls.localize('wordWrap', "Controls if lines should wrap. The lines will wrap at min(editor.wrappingColumn, viewportWidthInColumns).")
666
		},
J
Johannes Rieken 已提交
667
		'editor.wrappingIndent': {
E
Erich Gamma 已提交
668 669 670 671 672
			'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 已提交
673
		'editor.mouseWheelScrollSensitivity': {
E
Erich Gamma 已提交
674 675 676 677
			'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 已提交
678
		'editor.quickSuggestions': {
E
Erich Gamma 已提交
679 680 681 682
			'type': 'boolean',
			'default': DefaultConfig.editor.quickSuggestions,
			'description': nls.localize('quickSuggestions', "Controls if quick suggestions should show up or not while typing")
		},
J
Johannes Rieken 已提交
683
		'editor.quickSuggestionsDelay': {
E
Erich Gamma 已提交
684 685 686 687 688
			'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 已提交
689
		'editor.parameterHints': {
J
Joao Moreno 已提交
690 691 692 693
			'type': 'boolean',
			'default': DefaultConfig.editor.parameterHints,
			'description': nls.localize('parameterHints', "Enables parameter hints")
		},
J
Johannes Rieken 已提交
694
		'editor.autoClosingBrackets': {
E
Erich Gamma 已提交
695 696 697 698
			'type': 'boolean',
			'default': DefaultConfig.editor.autoClosingBrackets,
			'description': nls.localize('autoClosingBrackets', "Controls if the editor should automatically close brackets after opening them")
		},
J
Johannes Rieken 已提交
699
		'editor.formatOnType': {
E
Erich Gamma 已提交
700 701 702 703
			'type': 'boolean',
			'default': DefaultConfig.editor.formatOnType,
			'description': nls.localize('formatOnType', "Controls if the editor should automatically format the line after typing")
		},
704 705 706
		'editor.formatOnPaste': {
			'type': 'boolean',
			'default': DefaultConfig.editor.formatOnPaste,
707
			'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.")
708
		},
J
Johannes Rieken 已提交
709
		'editor.suggestOnTriggerCharacters': {
E
Erich Gamma 已提交
710 711 712 713
			'type': 'boolean',
			'default': DefaultConfig.editor.suggestOnTriggerCharacters,
			'description': nls.localize('suggestOnTriggerCharacters', "Controls if suggestions should automatically show up when typing trigger characters")
		},
J
Johannes Rieken 已提交
714
		'editor.acceptSuggestionOnEnter': {
715 716
			'type': 'boolean',
			'default': DefaultConfig.editor.acceptSuggestionOnEnter,
717 718 719 720 721 722
			'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.")
723
		},
724
		'editor.snippetSuggestions': {
725
			'type': 'string',
726 727 728
			'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.")
729
		},
730 731 732 733 734
		'editor.emptySelectionClipboard': {
			'type': 'boolean',
			'default': DefaultConfig.editor.emptySelectionClipboard,
			'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.")
		},
735 736 737 738 739
		'editor.wordBasedSuggestions': {
			'type': 'boolean',
			'default': DefaultConfig.editor.wordBasedSuggestions,
			'description': nls.localize('wordBasedSuggestions', "Enable word based suggestions.")
		},
J
Johannes Rieken 已提交
740
		'editor.suggestFontSize': {
J
Joao Moreno 已提交
741 742 743 744 745
			'type': 'integer',
			'default': 0,
			'minimum': 0,
			'description': nls.localize('suggestFontSize', "Font size for the suggest widget")
		},
J
Johannes Rieken 已提交
746
		'editor.suggestLineHeight': {
J
Joao Moreno 已提交
747 748 749 750 751
			'type': 'integer',
			'default': 0,
			'minimum': 0,
			'description': nls.localize('suggestLineHeight', "Line height for the suggest widget")
		},
752 753 754
		'editor.tabCompletion': {
			'type': 'boolean',
			'default': DefaultConfig.editor.tabCompletion,
755
			'description': nls.localize('tabCompletion', "Insert snippets when their prefix matches. Works best when 'quickSuggestions' aren't enabled.")
756
		},
J
Johannes Rieken 已提交
757
		'editor.selectionHighlight': {
E
Erich Gamma 已提交
758 759 760 761
			'type': 'boolean',
			'default': DefaultConfig.editor.selectionHighlight,
			'description': nls.localize('selectionHighlight', "Controls whether the editor should highlight similar matches to the selection")
		},
J
Johannes Rieken 已提交
762
		'editor.overviewRulerLanes': {
E
Erich Gamma 已提交
763 764 765 766
			'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 已提交
767
		'editor.cursorBlinking': {
768
			'type': 'string',
769
			'enum': ['blink', 'smooth', 'phase', 'expand', 'solid'],
770
			'default': DefaultConfig.editor.cursorBlinking,
771
			'description': nls.localize('cursorBlinking', "Control the cursor animation style, possible values are 'blink', 'smooth', 'phase', 'expand' and 'solid'")
772
		},
773 774 775 776 777
		'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 已提交
778
		'editor.cursorStyle': {
M
markrendle 已提交
779
			'type': 'string',
780
			'enum': ['block', 'block-outline', 'line', 'line-thin', 'underline', 'underline-thin'],
M
markrendle 已提交
781
			'default': DefaultConfig.editor.cursorStyle,
782
			'description': nls.localize('cursorStyle', "Controls the cursor style, accepted values are 'block', 'block-outline', 'line', 'line-thin', 'underline' and 'underline-thin'")
M
markrendle 已提交
783
		},
J
Johannes Rieken 已提交
784
		'editor.fontLigatures': {
785 786 787 788
			'type': 'boolean',
			'default': DefaultConfig.editor.fontLigatures,
			'description': nls.localize('fontLigatures', "Enables font ligatures")
		},
J
Johannes Rieken 已提交
789
		'editor.hideCursorInOverviewRuler': {
E
Erich Gamma 已提交
790 791 792 793 794
			'type': 'boolean',
			'default': DefaultConfig.editor.hideCursorInOverviewRuler,
			'description': nls.localize('hideCursorInOverviewRuler', "Controls if the cursor should be hidden in the overview ruler.")
		},
		'editor.renderWhitespace': {
795 796
			'type': 'string',
			'enum': ['none', 'boundary', 'all'],
E
Erich Gamma 已提交
797
			default: DefaultConfig.editor.renderWhitespace,
798
			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 已提交
799
		},
800 801 802 803 804
		'editor.renderControlCharacters': {
			'type': 'boolean',
			default: DefaultConfig.editor.renderControlCharacters,
			description: nls.localize('renderControlCharacters', "Controls whether the editor should render control characters")
		},
805 806 807 808 809
		'editor.renderIndentGuides': {
			'type': 'boolean',
			default: DefaultConfig.editor.renderIndentGuides,
			description: nls.localize('renderIndentGuides', "Controls whether the editor should render indent guides")
		},
810
		'editor.renderLineHighlight': {
811 812
			'type': 'string',
			'enum': ['none', 'gutter', 'line', 'all'],
813
			default: DefaultConfig.editor.renderLineHighlight,
814
			description: nls.localize('renderLineHighlight', "Controls how the editor should render the current line highlight, possibilities are 'none', 'gutter', 'line', and 'all'.")
815
		},
J
Johannes Rieken 已提交
816
		'editor.codeLens': {
E
Erich Gamma 已提交
817
			'type': 'boolean',
818 819
			'default': DefaultConfig.editor.codeLens,
			'description': nls.localize('codeLens', "Controls if the editor shows code lenses")
E
Erich Gamma 已提交
820
		},
J
Johannes Rieken 已提交
821
		'editor.folding': {
M
Martin Aeschlimann 已提交
822 823
			'type': 'boolean',
			'default': DefaultConfig.editor.folding,
824
			'description': nls.localize('folding', "Controls whether the editor has code folding enabled")
M
Martin Aeschlimann 已提交
825
		},
826 827 828 829 830
		'editor.highlightMatchingBrackets': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('highlightMatchingBrackets', "Highlight matching brackets when one of them is selected.")
		},
I
isidor 已提交
831 832 833 834 835
		'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 已提交
836
		'editor.useTabStops': {
837 838 839 840
			'type': 'boolean',
			'default': DefaultConfig.editor.useTabStops,
			'description': nls.localize('useTabStops', "Inserting and deleting whitespace follows tab stops")
		},
J
Johannes Rieken 已提交
841
		'editor.trimAutoWhitespace': {
842
			'type': 'boolean',
843
			'default': DEFAULT_TRIM_AUTO_WHITESPACE,
844 845
			'description': nls.localize('trimAutoWhitespace', "Remove trailing auto inserted whitespace")
		},
J
Johannes Rieken 已提交
846
		'editor.stablePeek': {
847
			'type': 'boolean',
848
			'default': false,
849
			'description': nls.localize('stablePeek', "Keep peek editors open even when double clicking their content or when hitting Escape.")
850
		},
J
Johannes Rieken 已提交
851
		'diffEditor.renderSideBySide': {
E
Erich Gamma 已提交
852 853 854 855
			'type': 'boolean',
			'default': true,
			'description': nls.localize('sideBySide', "Controls if the diff editor shows the diff side by side or inline")
		},
J
Johannes Rieken 已提交
856
		'diffEditor.ignoreTrimWhitespace': {
E
Erich Gamma 已提交
857 858 859
			'type': 'boolean',
			'default': true,
			'description': nls.localize('ignoreTrimWhitespace', "Controls if the diff editor shows changes in leading or trailing whitespace as diffs")
860 861 862 863 864
		},
		'diffEditor.renderIndicators': {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('renderIndicators', "Controls if the diff editor shows +/- indicators for added/removed changes")
E
Erich Gamma 已提交
865 866
		}
	}
A
Alex Dima 已提交
867 868 869 870 871 872 873 874 875 876
};

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.")
	};
}

877
configurationRegistry.registerConfiguration(editorConfiguration);