commonEditorConfig.ts 33.7 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 8
import * as nls from 'vs/nls';
import Event, {Emitter} from 'vs/base/common/event';
A
Alex Dima 已提交
9 10 11
import {Disposable} from 'vs/base/common/lifecycle';
import * as objects from 'vs/base/common/objects';
import {Extensions, IConfigurationRegistry} from 'vs/platform/configuration/common/configurationRegistry';
E
Erich Gamma 已提交
12
import {Registry} from 'vs/platform/platform';
13
import {DefaultConfig, DEFAULT_INDENTATION} from 'vs/editor/common/config/defaultConfig';
E
Erich Gamma 已提交
14
import {HandlerDispatcher} from 'vs/editor/common/controller/handlerDispatcher';
A
Alex Dima 已提交
15
import * as editorCommon from 'vs/editor/common/editorCommon';
E
Erich Gamma 已提交
16 17
import {EditorLayoutProvider} from 'vs/editor/common/viewLayout/editorLayoutProvider';

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/**
 * 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;
	}

	public static setValue(value:boolean): void {
		if (this._value === value) {
			return;
		}
		this._value = value;
		this._onChange.fire(this._value);
	}
}

E
Erich Gamma 已提交
40 41
export class ConfigurationWithDefaults {

A
Alex Dima 已提交
42
	private _editor:editorCommon.IEditorOptions;
E
Erich Gamma 已提交
43

A
Alex Dima 已提交
44 45
	constructor(options:editorCommon.IEditorOptions) {
		this._editor = <editorCommon.IEditorOptions>objects.clone(DefaultConfig.editor);
E
Erich Gamma 已提交
46 47 48 49

		this._mergeOptionsIn(options);
	}

A
Alex Dima 已提交
50
	public getEditorOptions(): editorCommon.IEditorOptions {
E
Erich Gamma 已提交
51 52 53
		return this._editor;
	}

A
Alex Dima 已提交
54 55
	private _mergeOptionsIn(newOptions:editorCommon.IEditorOptions): void {
		this._editor = objects.mixin(this._editor, newOptions || {});
E
Erich Gamma 已提交
56 57
	}

A
Alex Dima 已提交
58
	public updateOptions(newOptions:editorCommon.IEditorOptions): void {
E
Erich Gamma 已提交
59 60 61 62 63
		// Apply new options
		this._mergeOptionsIn(newOptions);
	}
}

A
Alex Dima 已提交
64
function cloneInternalEditorOptions(opts: editorCommon.IInternalEditorOptions): editorCommon.IInternalEditorOptions {
A
Alex Dima 已提交
65 66 67
	return {
		experimentalScreenReader: opts.experimentalScreenReader,
		rulers: opts.rulers.slice(0),
A
Alex Dima 已提交
68
		wordSeparators: opts.wordSeparators,
A
Alex Dima 已提交
69 70 71 72 73 74 75 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 104 105 106 107 108 109 110 111 112 113
		ariaLabel: opts.ariaLabel,
		lineNumbers: opts.lineNumbers,
		selectOnLineNumbers: opts.selectOnLineNumbers,
		glyphMargin: opts.glyphMargin,
		revealHorizontalRightPadding: opts.revealHorizontalRightPadding,
		roundedSelection: opts.roundedSelection,
		theme: opts.theme,
		readOnly: opts.readOnly,
		scrollbar: {
			arrowSize: opts.scrollbar.arrowSize,
			vertical: opts.scrollbar.vertical,
			horizontal: opts.scrollbar.horizontal,
			useShadows: opts.scrollbar.useShadows,
			verticalHasArrows: opts.scrollbar.verticalHasArrows,
			horizontalHasArrows: opts.scrollbar.horizontalHasArrows,
			handleMouseWheel: opts.scrollbar.handleMouseWheel,
			horizontalScrollbarSize: opts.scrollbar.horizontalScrollbarSize,
			horizontalSliderSize: opts.scrollbar.horizontalSliderSize,
			verticalScrollbarSize: opts.scrollbar.verticalScrollbarSize,
			verticalSliderSize: opts.scrollbar.verticalSliderSize,
			mouseWheelScrollSensitivity: opts.scrollbar.mouseWheelScrollSensitivity,
		},
		overviewRulerLanes: opts.overviewRulerLanes,
		cursorBlinking: opts.cursorBlinking,
		cursorStyle: opts.cursorStyle,
		fontLigatures: opts.fontLigatures,
		hideCursorInOverviewRuler: opts.hideCursorInOverviewRuler,
		scrollBeyondLastLine: opts.scrollBeyondLastLine,
		wrappingIndent: opts.wrappingIndent,
		wordWrapBreakBeforeCharacters: opts.wordWrapBreakBeforeCharacters,
		wordWrapBreakAfterCharacters: opts.wordWrapBreakAfterCharacters,
		wordWrapBreakObtrusiveCharacters: opts.wordWrapBreakObtrusiveCharacters,
		tabFocusMode: opts.tabFocusMode,
		stopLineTokenizationAfter: opts.stopLineTokenizationAfter,
		stopRenderingLineAfter: opts.stopRenderingLineAfter,
		longLineBoundary: opts.longLineBoundary,
		forcedTokenizationBoundary: opts.forcedTokenizationBoundary,
		hover: opts.hover,
		contextmenu: opts.contextmenu,
		quickSuggestions: opts.quickSuggestions,
		quickSuggestionsDelay: opts.quickSuggestionsDelay,
		iconsInSuggestions: opts.iconsInSuggestions,
		autoClosingBrackets: opts.autoClosingBrackets,
		formatOnType: opts.formatOnType,
		suggestOnTriggerCharacters: opts.suggestOnTriggerCharacters,
114
		acceptSuggestionOnEnter: opts.acceptSuggestionOnEnter,
A
Alex Dima 已提交
115 116 117
		selectionHighlight: opts.selectionHighlight,
		outlineMarkers: opts.outlineMarkers,
		referenceInfos: opts.referenceInfos,
118
		folding: opts.folding,
A
Alex Dima 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
		renderWhitespace: opts.renderWhitespace,
		layoutInfo: {
			width: opts.layoutInfo.width,
			height: opts.layoutInfo.height,
			glyphMarginLeft: opts.layoutInfo.glyphMarginLeft,
			glyphMarginWidth: opts.layoutInfo.glyphMarginWidth,
			glyphMarginHeight: opts.layoutInfo.glyphMarginHeight,
			lineNumbersLeft: opts.layoutInfo.lineNumbersLeft,
			lineNumbersWidth: opts.layoutInfo.lineNumbersWidth,
			lineNumbersHeight: opts.layoutInfo.lineNumbersHeight,
			decorationsLeft: opts.layoutInfo.decorationsLeft,
			decorationsWidth: opts.layoutInfo.decorationsWidth,
			decorationsHeight: opts.layoutInfo.decorationsHeight,
			contentLeft: opts.layoutInfo.contentLeft,
			contentWidth: opts.layoutInfo.contentWidth,
			contentHeight: opts.layoutInfo.contentHeight,
			verticalScrollbarWidth: opts.layoutInfo.verticalScrollbarWidth,
			horizontalScrollbarHeight: opts.layoutInfo.horizontalScrollbarHeight,
			overviewRuler:{
				width: opts.layoutInfo.overviewRuler.width,
				height: opts.layoutInfo.overviewRuler.height,
				top: opts.layoutInfo.overviewRuler.top,
				right: opts.layoutInfo.overviewRuler.right,
			}
		},
		stylingInfo: {
			editorClassName: opts.stylingInfo.editorClassName,
			fontFamily: opts.stylingInfo.fontFamily,
			fontSize: opts.stylingInfo.fontSize,
			lineHeight: opts.stylingInfo.lineHeight,
		},
		wrappingInfo: {
			isViewportWrapping: opts.wrappingInfo.isViewportWrapping,
			wrappingColumn: opts.wrappingInfo.wrappingColumn,
		},
		observedOuterWidth: opts.observedOuterWidth,
		observedOuterHeight: opts.observedOuterHeight,
		lineHeight: opts.lineHeight,
		pageSize: opts.pageSize,
		typicalHalfwidthCharacterWidth: opts.typicalHalfwidthCharacterWidth,
		typicalFullwidthCharacterWidth: opts.typicalFullwidthCharacterWidth,
		fontSize: opts.fontSize,
	};
}

E
Erich Gamma 已提交
164 165 166 167 168 169 170 171
class InternalEditorOptionsHelper {

	constructor() {
	}

	public static createInternalEditorOptions(
		outerWidth:number,
		outerHeight:number,
A
Alex Dima 已提交
172
		opts:editorCommon.IEditorOptions,
E
Erich Gamma 已提交
173 174 175 176 177 178 179
		editorClassName:string,
		requestedFontFamily:string,
		requestedFontSize:number,
		requestedLineHeight:number,
		adjustedLineHeight:number,
		themeOpts: ICSSConfig,
		isDominatedByLongLines:boolean,
180
		lineCount: number
A
Alex Dima 已提交
181
	): editorCommon.IInternalEditorOptions {
E
Erich Gamma 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

		let wrappingColumn = toInteger(opts.wrappingColumn, -1);

		let stopLineTokenizationAfter:number;
		if (typeof opts.stopLineTokenizationAfter !== 'undefined') {
			stopLineTokenizationAfter = toInteger(opts.stopLineTokenizationAfter, -1);
		} else if (wrappingColumn >= 0) {
			stopLineTokenizationAfter = -1;
		} else {
			stopLineTokenizationAfter = 10000;
		}

		let stopRenderingLineAfter:number;
		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);
		let lineDecorationsWidth = toInteger(opts.lineDecorationsWidth, 0);
M
Martin Aeschlimann 已提交
210
		if (opts.folding) {
211
			lineDecorationsWidth += 16;
M
Martin Aeschlimann 已提交
212
		}
E
Erich Gamma 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
		let layoutInfo = EditorLayoutProvider.compute({
			outerWidth: outerWidth,
			outerHeight: outerHeight,
			showGlyphMargin: glyphMargin,
			lineHeight: themeOpts.lineHeight,
			showLineNumbers: !!lineNumbers,
			lineNumbersMinChars: lineNumbersMinChars,
			lineDecorationsWidth: lineDecorationsWidth,
			maxDigitWidth: themeOpts.maxDigitWidth,
			lineCount: lineCount,
			verticalScrollbarWidth: scrollbar.verticalScrollbarSize,
			horizontalScrollbarHeight: scrollbar.horizontalScrollbarSize,
			scrollbarArrowSize: scrollbar.arrowSize,
			verticalScrollbarHasArrows: scrollbar.verticalHasArrows
		});

		let pageSize = Math.floor(layoutInfo.height / themeOpts.lineHeight) - 2;

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

A
Alex Dima 已提交
236
		let wrappingInfo: editorCommon.IEditorWrappingInfo;
E
Erich Gamma 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

		if (wrappingColumn === 0) {
			// If viewport width wrapping is enabled
			wrappingInfo = {
				isViewportWrapping: true,
				wrappingColumn: Math.max(1, Math.floor((layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth) / themeOpts.typicalHalfwidthCharacterWidth))
			};
		} else if (wrappingColumn > 0) {
			// Wrapping is enabled
			wrappingInfo = {
				isViewportWrapping: false,
				wrappingColumn: wrappingColumn
			};
		} else {
			wrappingInfo = {
				isViewportWrapping: false,
				wrappingColumn: -1
			};
		}

257 258 259 260 261 262 263
		let readOnly = toBoolean(opts.readOnly);

		let tabFocusMode = toBoolean(opts.tabFocusMode);
		if (readOnly) {
			tabFocusMode = true;
		}

E
Erich Gamma 已提交
264 265 266 267 268 269 270 271
		return {
			// ---- Options that are transparent - get no massaging
			lineNumbers: lineNumbers,
			selectOnLineNumbers: toBoolean(opts.selectOnLineNumbers),
			glyphMargin: glyphMargin,
			revealHorizontalRightPadding: toInteger(opts.revealHorizontalRightPadding, 0),
			roundedSelection: toBoolean(opts.roundedSelection),
			theme: opts.theme,
272
			readOnly: readOnly,
E
Erich Gamma 已提交
273 274
			scrollbar: scrollbar,
			overviewRulerLanes: toInteger(opts.overviewRulerLanes, 0, 3),
275
			cursorBlinking: opts.cursorBlinking,
276
			experimentalScreenReader: toBoolean(opts.experimentalScreenReader),
277
			rulers: toSortedIntegerArray(opts.rulers),
A
Alex Dima 已提交
278
			wordSeparators: String(opts.wordSeparators),
279
			ariaLabel: String(opts.ariaLabel),
M
markrendle 已提交
280
			cursorStyle: opts.cursorStyle,
281
			fontLigatures: toBoolean(opts.fontLigatures),
E
Erich Gamma 已提交
282 283 284 285 286 287
			hideCursorInOverviewRuler: toBoolean(opts.hideCursorInOverviewRuler),
			scrollBeyondLastLine: toBoolean(opts.scrollBeyondLastLine),
			wrappingIndent: opts.wrappingIndent,
			wordWrapBreakBeforeCharacters: opts.wordWrapBreakBeforeCharacters,
			wordWrapBreakAfterCharacters: opts.wordWrapBreakAfterCharacters,
			wordWrapBreakObtrusiveCharacters: opts.wordWrapBreakObtrusiveCharacters,
288
			tabFocusMode: tabFocusMode,
E
Erich Gamma 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301
			stopLineTokenizationAfter: stopLineTokenizationAfter,
			stopRenderingLineAfter: stopRenderingLineAfter,
			longLineBoundary: toInteger(opts.longLineBoundary),
			forcedTokenizationBoundary: toInteger(opts.forcedTokenizationBoundary),

			hover: toBoolean(opts.hover),
			contextmenu: toBoolean(opts.contextmenu),
			quickSuggestions: toBoolean(opts.quickSuggestions),
			quickSuggestionsDelay: toInteger(opts.quickSuggestionsDelay),
			iconsInSuggestions: toBoolean(opts.iconsInSuggestions),
			autoClosingBrackets: toBoolean(opts.autoClosingBrackets),
			formatOnType: toBoolean(opts.formatOnType),
			suggestOnTriggerCharacters: toBoolean(opts.suggestOnTriggerCharacters),
302
			acceptSuggestionOnEnter: toBoolean(opts.acceptSuggestionOnEnter),
E
Erich Gamma 已提交
303 304 305
			selectionHighlight: toBoolean(opts.selectionHighlight),
			outlineMarkers: toBoolean(opts.outlineMarkers),
			referenceInfos: toBoolean(opts.referenceInfos),
M
Martin Aeschlimann 已提交
306
			folding: toBoolean(opts.folding),
E
Erich Gamma 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
			renderWhitespace: toBoolean(opts.renderWhitespace),

			layoutInfo: layoutInfo,
			stylingInfo: {
				editorClassName: editorClassName,
				fontFamily: requestedFontFamily,
				fontSize: requestedFontSize,
				lineHeight: adjustedLineHeight
			},
			wrappingInfo: wrappingInfo,

			observedOuterWidth: outerWidth,
			observedOuterHeight: outerHeight,

			lineHeight: themeOpts.lineHeight,

			pageSize: pageSize,

			typicalHalfwidthCharacterWidth: themeOpts.typicalHalfwidthCharacterWidth,
			typicalFullwidthCharacterWidth: themeOpts.typicalFullwidthCharacterWidth,

			fontSize: themeOpts.fontSize,
		};
	}

A
Alex Dima 已提交
332
	private static _sanitizeScrollbarOpts(raw:editorCommon.IEditorScrollbarOptions, mouseWheelScrollSensitivity:number): editorCommon.IInternalEditorScrollbarOptions {
A
Alex Dima 已提交
333 334
		let horizontalScrollbarSize = toIntegerWithDefault(raw.horizontalScrollbarSize, 10);
		let verticalScrollbarSize = toIntegerWithDefault(raw.verticalScrollbarSize, 14);
E
Erich Gamma 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
		return {
			vertical: toStringSet(raw.vertical, ['auto', 'visible', 'hidden'], 'auto'),
			horizontal: toStringSet(raw.horizontal, ['auto', 'visible', 'hidden'], 'auto'),

			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 已提交
356
	public static createConfigurationChangedEvent(prevOpts:editorCommon.IInternalEditorOptions, newOpts:editorCommon.IInternalEditorOptions): editorCommon.IConfigurationChangedEvent {
E
Erich Gamma 已提交
357
		return {
358
			experimentalScreenReader:		(prevOpts.experimentalScreenReader !== newOpts.experimentalScreenReader),
359
			rulers:							(!this._numberArraysEqual(prevOpts.rulers, newOpts.rulers)),
A
Alex Dima 已提交
360
			wordSeparators:					(prevOpts.wordSeparators !== newOpts.wordSeparators),
361
			ariaLabel:						(prevOpts.ariaLabel !== newOpts.ariaLabel),
362

363 364 365
			lineNumbers:					(prevOpts.lineNumbers !== newOpts.lineNumbers),
			selectOnLineNumbers:			(prevOpts.selectOnLineNumbers !== newOpts.selectOnLineNumbers),
			glyphMargin:					(prevOpts.glyphMargin !== newOpts.glyphMargin),
E
Erich Gamma 已提交
366 367 368 369 370 371
			revealHorizontalRightPadding:	(prevOpts.revealHorizontalRightPadding !== newOpts.revealHorizontalRightPadding),
			roundedSelection:				(prevOpts.roundedSelection !== newOpts.roundedSelection),
			theme:							(prevOpts.theme !== newOpts.theme),
			readOnly:						(prevOpts.readOnly !== newOpts.readOnly),
			scrollbar:						(!this._scrollbarOptsEqual(prevOpts.scrollbar, newOpts.scrollbar)),
			overviewRulerLanes:				(prevOpts.overviewRulerLanes !== newOpts.overviewRulerLanes),
372
			cursorBlinking:					(prevOpts.cursorBlinking !== newOpts.cursorBlinking),
373
			cursorStyle:					(prevOpts.cursorStyle !== newOpts.cursorStyle),
374
			fontLigatures:					(prevOpts.fontLigatures !== newOpts.fontLigatures),
E
Erich Gamma 已提交
375 376 377 378 379 380 381 382 383 384 385
			hideCursorInOverviewRuler:		(prevOpts.hideCursorInOverviewRuler !== newOpts.hideCursorInOverviewRuler),
			scrollBeyondLastLine:			(prevOpts.scrollBeyondLastLine !== newOpts.scrollBeyondLastLine),
			wrappingIndent:					(prevOpts.wrappingIndent !== newOpts.wrappingIndent),
			wordWrapBreakBeforeCharacters:	(prevOpts.wordWrapBreakBeforeCharacters !== newOpts.wordWrapBreakBeforeCharacters),
			wordWrapBreakAfterCharacters:	(prevOpts.wordWrapBreakAfterCharacters !== newOpts.wordWrapBreakAfterCharacters),
			wordWrapBreakObtrusiveCharacters:(prevOpts.wordWrapBreakObtrusiveCharacters !== newOpts.wordWrapBreakObtrusiveCharacters),
			tabFocusMode:					(prevOpts.tabFocusMode !== newOpts.tabFocusMode),
			stopLineTokenizationAfter:		(prevOpts.stopLineTokenizationAfter !== newOpts.stopLineTokenizationAfter),
			stopRenderingLineAfter:			(prevOpts.stopRenderingLineAfter !== newOpts.stopRenderingLineAfter),
			longLineBoundary:				(prevOpts.longLineBoundary !== newOpts.longLineBoundary),
			forcedTokenizationBoundary:		(prevOpts.forcedTokenizationBoundary !== newOpts.forcedTokenizationBoundary),
386

E
Erich Gamma 已提交
387
			hover:							(prevOpts.hover !== newOpts.hover),
388
			contextmenu:					(prevOpts.contextmenu !== newOpts.contextmenu),
E
Erich Gamma 已提交
389 390 391
			quickSuggestions:				(prevOpts.quickSuggestions !== newOpts.quickSuggestions),
			quickSuggestionsDelay:			(prevOpts.quickSuggestionsDelay !== newOpts.quickSuggestionsDelay),
			iconsInSuggestions:				(prevOpts.iconsInSuggestions !== newOpts.iconsInSuggestions),
392
			autoClosingBrackets:			(prevOpts.autoClosingBrackets !== newOpts.autoClosingBrackets),
E
Erich Gamma 已提交
393 394 395 396
			formatOnType:					(prevOpts.formatOnType !== newOpts.formatOnType),
			suggestOnTriggerCharacters:		(prevOpts.suggestOnTriggerCharacters !== newOpts.suggestOnTriggerCharacters),
			selectionHighlight:				(prevOpts.selectionHighlight !== newOpts.selectionHighlight),
			outlineMarkers:					(prevOpts.outlineMarkers !== newOpts.outlineMarkers),
397
			referenceInfos:					(prevOpts.referenceInfos !== newOpts.referenceInfos),
M
Martin Aeschlimann 已提交
398
			folding:						(prevOpts.folding !== newOpts.folding),
399 400
			renderWhitespace:				(prevOpts.renderWhitespace !== newOpts.renderWhitespace),

401
			layoutInfo: 					(!EditorLayoutProvider.layoutEqual(prevOpts.layoutInfo, newOpts.layoutInfo)),
402 403 404
			stylingInfo: 					(!this._stylingInfoEqual(prevOpts.stylingInfo, newOpts.stylingInfo)),
			wrappingInfo:					(!this._wrappingInfoEqual(prevOpts.wrappingInfo, newOpts.wrappingInfo)),
			observedOuterWidth:				(prevOpts.observedOuterWidth !== newOpts.observedOuterWidth),
405
			observedOuterHeight:			(prevOpts.observedOuterHeight !== newOpts.observedOuterHeight),
406 407 408 409 410
			lineHeight:						(prevOpts.lineHeight !== newOpts.lineHeight),
			pageSize:						(prevOpts.pageSize !== newOpts.pageSize),
			typicalHalfwidthCharacterWidth:	(prevOpts.typicalHalfwidthCharacterWidth !== newOpts.typicalHalfwidthCharacterWidth),
			typicalFullwidthCharacterWidth:	(prevOpts.typicalFullwidthCharacterWidth !== newOpts.typicalFullwidthCharacterWidth),
			fontSize:						(prevOpts.fontSize !== newOpts.fontSize)
E
Erich Gamma 已提交
411 412 413
		};
	}

A
Alex Dima 已提交
414
	private static _scrollbarOptsEqual(a:editorCommon.IInternalEditorScrollbarOptions, b:editorCommon.IInternalEditorScrollbarOptions): boolean {
E
Erich Gamma 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
		return (
			a.arrowSize === b.arrowSize
			&& a.vertical === b.vertical
			&& a.horizontal === b.horizontal
			&& a.useShadows === b.useShadows
			&& a.verticalHasArrows === b.verticalHasArrows
			&& a.horizontalHasArrows === b.horizontalHasArrows
			&& a.handleMouseWheel === b.handleMouseWheel
			&& a.horizontalScrollbarSize === b.horizontalScrollbarSize
			&& a.horizontalSliderSize === b.horizontalSliderSize
			&& a.verticalScrollbarSize === b.verticalScrollbarSize
			&& a.verticalSliderSize === b.verticalSliderSize
			&& a.mouseWheelScrollSensitivity === b.mouseWheelScrollSensitivity
		);
	}

A
Alex Dima 已提交
431
	private static _stylingInfoEqual(a:editorCommon.IEditorStyling, b:editorCommon.IEditorStyling): boolean {
E
Erich Gamma 已提交
432 433 434 435 436 437 438 439
		return (
			a.editorClassName === b.editorClassName
			&& a.fontFamily === b.fontFamily
			&& a.fontSize === b.fontSize
			&& a.lineHeight === b.lineHeight
		);
	}

A
Alex Dima 已提交
440
	private static _wrappingInfoEqual(a:editorCommon.IEditorWrappingInfo, b:editorCommon.IEditorWrappingInfo): boolean {
E
Erich Gamma 已提交
441 442 443 444 445 446
		return (
			a.isViewportWrapping === b.isViewportWrapping
			&& a.wrappingColumn === b.wrappingColumn
		);
	}

447 448 449 450 451 452 453 454 455 456 457
	private static _numberArraysEqual(a:number[], b:number[]): boolean {
		if (a.length !== b.length) {
			return false;
		}
		for (let i = 0; i < a.length; i++) {
			if (a[i] !== b[i]) {
				return false;
			}
		}
		return true;
	}
E
Erich Gamma 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
}

export interface ICSSConfig {
	typicalHalfwidthCharacterWidth:number;
	typicalFullwidthCharacterWidth:number;
	maxDigitWidth: number;
	lineHeight:number;
	font:string;
	fontSize:number;
}

function toBoolean(value:any): boolean {
	return value === 'false' ? false : Boolean(value);
}

function toBooleanWithDefault(value:any, defaultValue:boolean): boolean {
	if (typeof value === 'undefined') {
		return defaultValue;
	}
	return toBoolean(value);
}

function toFloat(source: any, defaultValue: number): number {
A
Alex Dima 已提交
481
	let r = parseFloat(source);
E
Erich Gamma 已提交
482 483 484 485 486 487 488
	if (isNaN(r)) {
		r = defaultValue;
	}
	return r;
}

function toInteger(source:any, minimum?:number, maximum?:number): number {
A
Alex Dima 已提交
489
	let r = parseInt(source, 10);
E
Erich Gamma 已提交
490 491 492 493 494 495 496 497 498 499 500 501
	if (isNaN(r)) {
		r = 0;
	}
	if (typeof minimum === 'number') {
		r = Math.max(minimum, r);
	}
	if (typeof maximum === 'number') {
		r = Math.min(maximum, r);
	}
	return r;
}

502 503 504 505 506 507 508 509 510 511
function toSortedIntegerArray(source:any): number[] {
	if (!Array.isArray(source)) {
		return [];
	}
	let arrSource = <any[]>source;
	let r = arrSource.map(el => toInteger(el));
	r.sort();
	return r;
}

E
Erich Gamma 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
function toIntegerWithDefault(source:any, defaultValue:number): number {
	if (typeof source === 'undefined') {
		return defaultValue;
	}
	return toInteger(source);
}

function toStringSet(source:any, allowedValues:string[], defaultValue:string): string {
	if (typeof source !== 'string') {
		return defaultValue;
	}
	if (allowedValues.indexOf(source) === -1) {
		return defaultValue;
	}
	return source;
}

interface IValidatedIndentationOptions {
	tabSizeIsAuto: boolean;
	tabSize: number;
	insertSpacesIsAuto: boolean;
	insertSpaces: boolean;
}

536 537 538 539 540 541 542 543
export interface IElementSizeObserver {
	startObserving(): void;
	observe(dimension?:editorCommon.IDimension): void;
	dispose(): void;
	getWidth(): number;
	getHeight(): number;
}

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

A
Alex Dima 已提交
546 547 548
	public handlerDispatcher:editorCommon.IHandlerDispatcher;
	public editor:editorCommon.IInternalEditorOptions;
	public editorClone:editorCommon.IInternalEditorOptions;
E
Erich Gamma 已提交
549 550

	protected _configWithDefaults:ConfigurationWithDefaults;
551
	protected _elementSizeObserver: IElementSizeObserver;
E
Erich Gamma 已提交
552 553 554
	private _isDominatedByLongLines:boolean;
	private _lineCount:number;

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

558
	constructor(options:editorCommon.IEditorOptions, elementSizeObserver: IElementSizeObserver = null) {
A
Alex Dima 已提交
559
		super();
E
Erich Gamma 已提交
560
		this._configWithDefaults = new ConfigurationWithDefaults(options);
561
		this._elementSizeObserver = elementSizeObserver;
E
Erich Gamma 已提交
562 563 564 565 566 567
		this._isDominatedByLongLines = false;
		this._lineCount = 1;

		this.handlerDispatcher = new HandlerDispatcher();

		this.editor = this._computeInternalOptions();
A
Alex Dima 已提交
568
		this.editorClone = cloneInternalEditorOptions(this.editor);
E
Erich Gamma 已提交
569 570 571 572 573 574 575 576 577
	}

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

	protected _recomputeOptions(): void {
		let oldOpts = this.editor;
		this.editor = this._computeInternalOptions();
A
Alex Dima 已提交
578
		this.editorClone = cloneInternalEditorOptions(this.editor);
E
Erich Gamma 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591 592

		let changeEvent = InternalEditorOptionsHelper.createConfigurationChangedEvent(oldOpts, this.editor);

		let hasChanged = false;
		for (let key in changeEvent) {
			if (changeEvent.hasOwnProperty(key)) {
				if (changeEvent[key]) {
					hasChanged = true;
					break;
				}
			}
		}

		if (hasChanged) {
A
Alex Dima 已提交
593
			this._onDidChange.fire(changeEvent);
E
Erich Gamma 已提交
594 595 596
		}
	}

A
Alex Dima 已提交
597
	public getRawOptions(): editorCommon.IEditorOptions {
E
Erich Gamma 已提交
598 599 600
		return this._configWithDefaults.getEditorOptions();
	}

A
Alex Dima 已提交
601
	private _computeInternalOptions(): editorCommon.IInternalEditorOptions {
E
Erich Gamma 已提交
602 603
		let opts = this._configWithDefaults.getEditorOptions();

604
		let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures));
E
Erich Gamma 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
		let requestedFontFamily = opts.fontFamily || '';
		let requestedFontSize = toInteger(opts.fontSize, 0, 100);
		let requestedLineHeight = toInteger(opts.lineHeight, 0, 150);

		let adjustedLineHeight = requestedLineHeight;
		if (requestedFontSize > 0 && requestedLineHeight === 0) {
			adjustedLineHeight = Math.round(1.3 * requestedFontSize);
		}

		return InternalEditorOptionsHelper.createInternalEditorOptions(
			this.getOuterWidth(),
			this.getOuterHeight(),
			opts,
			editorClassName,
			requestedFontFamily,
			requestedFontSize,
			requestedLineHeight,
			adjustedLineHeight,
			this.readConfiguration(editorClassName, requestedFontFamily, requestedFontSize, adjustedLineHeight),
			this._isDominatedByLongLines,
625
			this._lineCount
E
Erich Gamma 已提交
626 627 628
		);
	}

A
Alex Dima 已提交
629
	public updateOptions(newOptions:editorCommon.IEditorOptions): void {
E
Erich Gamma 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643
		this._configWithDefaults.updateOptions(newOptions);
		this._recomputeOptions();
	}

	public setIsDominatedByLongLines(isDominatedByLongLines:boolean): void {
		this._isDominatedByLongLines = isDominatedByLongLines;
		this._recomputeOptions();
	}

	public setLineCount(lineCount:number): void {
		this._lineCount = lineCount;
		this._recomputeOptions();
	}

644
	protected abstract _getEditorClassName(theme:string, fontLigatures:boolean): string;
E
Erich Gamma 已提交
645

646
	protected abstract getOuterWidth(): number;
E
Erich Gamma 已提交
647

648
	protected abstract getOuterHeight(): number;
E
Erich Gamma 已提交
649

650
	protected abstract readConfiguration(editorClassName: string, fontFamily: string, fontSize: number, lineHeight: number): ICSSConfig;
E
Erich Gamma 已提交
651 652 653 654 655 656 657 658 659 660 661 662
}

/**
 * Helper to update Monaco Editor Settings from configurations service.
 */
export class EditorConfiguration {
	public static EDITOR_SECTION = 'editor';
	public static DIFF_EDITOR_SECTION = 'diffEditor';

	/**
	 * Ask the provided configuration service to apply its configuration to the provided editor.
	 */
A
Alex Dima 已提交
663 664
	public static apply(config:any, editor?:editorCommon.IEditor): void;
	public static apply(config:any, editor?:editorCommon.IEditor[]): void;
E
Erich Gamma 已提交
665 666 667 668 669
	public static apply(config:any, editorOrArray?:any): void {
		if (!config) {
			return;
		}

A
Alex Dima 已提交
670
		let editors:editorCommon.IEditor[] = editorOrArray;
E
Erich Gamma 已提交
671 672 673 674
		if (!Array.isArray(editorOrArray)) {
			editors = [editorOrArray];
		}

A
Alex Dima 已提交
675 676
		for (let i = 0; i < editors.length; i++) {
			let editor = editors[i];
E
Erich Gamma 已提交
677 678 679

			// Editor Settings (Code Editor, Diff, Terminal)
			if (editor && typeof editor.updateOptions === 'function') {
A
Alex Dima 已提交
680
				let type = editor.getEditorType();
A
Alex Dima 已提交
681
				if (type !== editorCommon.EditorType.ICodeEditor && type !== editorCommon.EditorType.IDiffEditor) {
E
Erich Gamma 已提交
682 683 684
					continue;
				}

A
Alex Dima 已提交
685
				let editorConfig = config[EditorConfiguration.EDITOR_SECTION];
A
Alex Dima 已提交
686
				if (type === editorCommon.EditorType.IDiffEditor) {
A
Alex Dima 已提交
687
					let diffEditorConfig = config[EditorConfiguration.DIFF_EDITOR_SECTION];
E
Erich Gamma 已提交
688 689 690 691
					if (diffEditorConfig) {
						if (!editorConfig) {
							editorConfig = diffEditorConfig;
						} else {
A
Alex Dima 已提交
692
							editorConfig = objects.mixin(editorConfig, diffEditorConfig);
E
Erich Gamma 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705
						}
					}
				}

				if (editorConfig) {
					delete editorConfig.readOnly; // Prevent someone from making editor readonly
					editor.updateOptions(editorConfig);
				}
			}
		}
	}
}

A
Alex Dima 已提交
706
let configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration);
E
Erich Gamma 已提交
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
configurationRegistry.registerConfiguration({
	'id': 'editor',
	'order': 5,
	'type': 'object',
	'title': nls.localize('editorConfigurationTitle', "Editor configuration"),
	'properties' : {
		'editor.fontFamily' : {
			'type': 'string',
			'default': DefaultConfig.editor.fontFamily,
			'description': nls.localize('fontFamily', "Controls the font family.")
		},
		'editor.fontSize' : {
			'type': 'number',
			'default': DefaultConfig.editor.fontSize,
			'description': nls.localize('fontSize', "Controls the font size.")
		},
		'editor.lineHeight' : {
			'type': 'number',
			'default': DefaultConfig.editor.lineHeight,
			'description': nls.localize('lineHeight', "Controls the line height.")
		},
		'editor.lineNumbers' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.lineNumbers,
			'description': nls.localize('lineNumbers', "Controls visibility of line numbers")
		},
		'editor.glyphMargin' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.glyphMargin,
			'description': nls.localize('glyphMargin', "Controls visibility of the glyph margin")
		},
738 739 740 741 742 743 744 745
		'editor.rulers' : {
			'type': 'array',
			'items': {
				'type': 'number'
			},
			'default': DefaultConfig.editor.rulers,
			'description': nls.localize('rulers', "Columns at which to show vertical rulers")
		},
A
Alex Dima 已提交
746 747 748 749 750
		'editor.wordSeparators' : {
			'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")
		},
E
Erich Gamma 已提交
751
		'editor.tabSize' : {
752 753
			'type': 'number',
			'default': DEFAULT_INDENTATION.tabSize,
E
Erich Gamma 已提交
754
			'minimum': 1,
A
Alex Dima 已提交
755
			'description': nls.localize('tabSize', "The number of spaces a tab is equal to.")
E
Erich Gamma 已提交
756 757
		},
		'editor.insertSpaces' : {
758 759
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.insertSpaces,
A
Alex Dima 已提交
760
			'description': nls.localize('insertSpaces', "Insert spaces when pressing Tab.")
E
Erich Gamma 已提交
761
		},
762 763 764
		'editor.detectIndentation' : {
			'type': 'boolean',
			'default': DEFAULT_INDENTATION.detectIndentation,
A
Alex Dima 已提交
765
			'description': nls.localize('detectIndentation', "When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.")
766
		},
E
Erich Gamma 已提交
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
		'editor.roundedSelection' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.roundedSelection,
			'description': nls.localize('roundedSelection', "Controls if selections have rounded corners")
		},
		'editor.scrollBeyondLastLine' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.scrollBeyondLastLine,
			'description': nls.localize('scrollBeyondLastLine', "Controls if the editor will scroll beyond the last line")
		},
		'editor.wrappingColumn' : {
			'type': 'integer',
			'default': DefaultConfig.editor.wrappingColumn,
			'minimum': -1,
			'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")
		},
		'editor.wrappingIndent' : {
			'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'.")
		},
		'editor.mouseWheelScrollSensitivity' : {
			'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")
		},
		'editor.quickSuggestions' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.quickSuggestions,
			'description': nls.localize('quickSuggestions', "Controls if quick suggestions should show up or not while typing")
		},
		'editor.quickSuggestionsDelay' : {
			'type': 'integer',
			'default': DefaultConfig.editor.quickSuggestionsDelay,
			'minimum': 0,
			'description': nls.localize('quickSuggestionsDelay', "Controls the delay in ms after which quick suggestions will show up")
		},
		'editor.autoClosingBrackets' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.autoClosingBrackets,
			'description': nls.localize('autoClosingBrackets', "Controls if the editor should automatically close brackets after opening them")
		},
		'editor.formatOnType' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.formatOnType,
			'description': nls.localize('formatOnType', "Controls if the editor should automatically format the line after typing")
		},
		'editor.suggestOnTriggerCharacters' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.suggestOnTriggerCharacters,
			'description': nls.localize('suggestOnTriggerCharacters', "Controls if suggestions should automatically show up when typing trigger characters")
		},
820 821 822 823 824
		'editor.acceptSuggestionOnEnter' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.acceptSuggestionOnEnter,
			'description': nls.localize('acceptSuggestionOnEnter', "Controls if suggestions should be accepted 'Enter' - in addition to 'Tab'. Helps to avoid ambiguity between inserting new lines or accepting suggestions.")
		},
E
Erich Gamma 已提交
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
		'editor.selectionHighlight' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.selectionHighlight,
			'description': nls.localize('selectionHighlight', "Controls whether the editor should highlight similar matches to the selection")
		},
//		'editor.outlineMarkers' : {
//			'type': 'boolean',
//			'default': DefaultConfig.editor.outlineMarkers,
//			'description': nls.localize('outlineMarkers', "Controls whether the editor should draw horizontal lines before classes and methods")
//		},
		'editor.overviewRulerLanes' : {
			'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")
		},
840 841 842 843
		'editor.cursorBlinking' : {
			'type': 'string',
			'enum': ['blink', 'visible', 'hidden'],
			'default': DefaultConfig.editor.cursorBlinking,
C
Chris Dias 已提交
844
			'description': nls.localize('cursorBlinking', "Controls the cursor blinking animation, accepted values are 'blink', 'visible', and 'hidden'")
845
		},
M
markrendle 已提交
846 847 848 849 850 851
		'editor.cursorStyle' : {
			'type': 'string',
			'enum': ['block', 'line'],
			'default': DefaultConfig.editor.cursorStyle,
			'description': nls.localize('cursorStyle', "Controls the cursor style, accepted values are 'block' and 'line'")
		},
852 853 854 855 856
		'editor.fontLigatures' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.fontLigatures,
			'description': nls.localize('fontLigatures', "Enables font ligatures")
		},
E
Erich Gamma 已提交
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
		'editor.hideCursorInOverviewRuler' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.hideCursorInOverviewRuler,
			'description': nls.localize('hideCursorInOverviewRuler', "Controls if the cursor should be hidden in the overview ruler.")
		},
		'editor.renderWhitespace': {
			'type': 'boolean',
			default: DefaultConfig.editor.renderWhitespace,
			description: nls.localize('renderWhitespace', "Controls whether the editor should render whitespace characters")
		},
		'editor.referenceInfos' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.referenceInfos,
			'description': nls.localize('referenceInfos', "Controls if the editor shows reference information for the modes that support it")
		},
M
Martin Aeschlimann 已提交
872 873 874
		'editor.folding' : {
			'type': 'boolean',
			'default': DefaultConfig.editor.folding,
875
			'description': nls.localize('folding', "Controls whether the editor has code folding enabled")
M
Martin Aeschlimann 已提交
876
		},
E
Erich Gamma 已提交
877 878 879 880 881 882 883 884 885 886 887 888
		'diffEditor.renderSideBySide' : {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('sideBySide', "Controls if the diff editor shows the diff side by side or inline")
		},
		'diffEditor.ignoreTrimWhitespace' : {
			'type': 'boolean',
			'default': true,
			'description': nls.localize('ignoreTrimWhitespace', "Controls if the diff editor shows changes in leading or trailing whitespace as diffs")
		}
	}
});