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

6 7
import * as nls from 'vs/nls';
import * as platform from 'vs/base/common/platform';
8 9
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import { FontInfo } from 'vs/editor/common/config/fontInfo';
10
import { Constants } from 'vs/editor/common/core/uint';
11
import { USUAL_WORD_SEPARATORS } from 'vs/editor/common/model/wordHelper';
12
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
13
import { isObject } from 'vs/base/common/types';
14
import { IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
15

A
Alex Dima 已提交
16 17
//#region typed options

18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * Configuration options for editor scrollbars
 */
export interface IEditorScrollbarOptions {
	/**
	 * The size of arrows (if displayed).
	 * Defaults to 11.
	 */
	arrowSize?: number;
	/**
	 * Render vertical scrollbar.
	 * Defaults to 'auto'.
	 */
A
Alex Dima 已提交
31
	vertical?: 'auto' | 'visible' | 'hidden';
32 33 34 35
	/**
	 * Render horizontal scrollbar.
	 * Defaults to 'auto'.
	 */
A
Alex Dima 已提交
36
	horizontal?: 'auto' | 'visible' | 'hidden';
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	/**
	 * Cast horizontal and vertical shadows when the content is scrolled.
	 * Defaults to true.
	 */
	useShadows?: boolean;
	/**
	 * Render arrows at the top and bottom of the vertical scrollbar.
	 * Defaults to false.
	 */
	verticalHasArrows?: boolean;
	/**
	 * Render arrows at the left and right of the horizontal scrollbar.
	 * Defaults to false.
	 */
	horizontalHasArrows?: boolean;
	/**
	 * Listen to mouse wheel events and react to them by scrolling.
	 * Defaults to true.
	 */
	handleMouseWheel?: boolean;
	/**
	 * Height in pixels for the horizontal scrollbar.
	 * Defaults to 10 (px).
	 */
	horizontalScrollbarSize?: number;
	/**
	 * Width in pixels for the vertical scrollbar.
	 * Defaults to 10 (px).
	 */
	verticalScrollbarSize?: number;
	/**
	 * Width in pixels for the vertical slider.
	 * Defaults to `verticalScrollbarSize`.
	 */
	verticalSliderSize?: number;
	/**
	 * Height in pixels for the horizontal slider.
	 * Defaults to `horizontalScrollbarSize`.
	 */
	horizontalSliderSize?: number;
}

79 80 81 82
/**
 * Configuration options for editor find widget
 */
export interface IEditorFindOptions {
R
rebornix 已提交
83 84 85
	/**
	 * Controls if we seed search string in the Find Widget with editor selection.
	 */
86
	seedSearchStringFromSelection?: boolean;
R
rebornix 已提交
87 88 89
	/**
	 * Controls if Find in Selection flag is turned on when multiple lines of text are selected in the editor.
	 */
A
Alex Dima 已提交
90
	autoFindInSelection?: boolean;
91 92 93 94
	/*
	 * Controls whether the Find Widget should add extra lines on top of the editor.
	 */
	addExtraSpaceOnTop?: boolean;
95 96 97 98
	/**
	 * @internal
	 * Controls if the Find Widget should read or modify the shared find clipboard on macOS
	 */
A
Alex Dima 已提交
99
	globalFindClipboard?: boolean;
100 101
}

J
Jackson Kearl 已提交
102
/**
J
Jackson Kearl 已提交
103
 * Configuration options for auto closing quotes and brackets
J
Jackson Kearl 已提交
104
 */
J
Jackson Kearl 已提交
105 106 107 108 109
export type EditorAutoClosingStrategy = 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';

/**
 * Configuration options for auto wrapping quotes and brackets
 */
110
export type EditorAutoSurroundStrategy = 'languageDefined' | 'quotes' | 'brackets' | 'never';
J
Jackson Kearl 已提交
111

112 113 114 115 116
/**
 * Configuration options for typing over closing quotes or brackets
 */
export type EditorAutoClosingOvertypeStrategy = 'always' | 'auto' | 'never';

117 118 119 120 121 122
/**
 * Configuration options for editor minimap
 */
export interface IEditorMinimapOptions {
	/**
	 * Enable the rendering of the minimap.
123
	 * Defaults to true.
124 125
	 */
	enabled?: boolean;
126 127 128 129 130
	/**
	 * Control the side of the minimap in editor.
	 * Defaults to 'right'.
	 */
	side?: 'right' | 'left';
131 132 133 134 135
	/**
	 * Control the rendering of the minimap slider.
	 * Defaults to 'mouseover'.
	 */
	showSlider?: 'always' | 'mouseover';
136 137 138 139 140 141 142 143 144 145 146 147
	/**
	 * Render the actual text on a line (as opposed to color blocks).
	 * Defaults to true.
	 */
	renderCharacters?: boolean;
	/**
	 * Limit the width of the minimap to render at most a certain number of columns.
	 * Defaults to 120.
	 */
	maxColumn?: number;
}

148
/**
A
Alex Dima 已提交
149
 * Configuration options for editor lightbulb
150 151 152 153 154 155 156 157 158
 */
export interface IEditorLightbulbOptions {
	/**
	 * Enable the lightbulb code action.
	 * Defaults to true.
	 */
	enabled?: boolean;
}

A
Alex Dima 已提交
159 160 161 162 163 164 165 166 167
/**
 * Configuration options for editor hover
 */
export interface IEditorHoverOptions {
	/**
	 * Enable the hover.
	 * Defaults to true.
	 */
	enabled?: boolean;
168 169 170 171 172
	/**
	 * Delay for showing the hover.
	 * Defaults to 300.
	 */
	delay?: number;
173 174 175 176 177
	/**
	 * Is the hover sticky such that it can be clicked and its contents selected?
	 * Defaults to true.
	 */
	sticky?: boolean;
A
Alex Dima 已提交
178 179
}

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
/**
 * Configuration options for parameter hints
 */
export interface IEditorParameterHintOptions {
	/**
	 * Enable parameter hints.
	 * Defaults to true.
	 */
	enabled?: boolean;
	/**
	 * Enable cycling of parameter hints.
	 * Defaults to false.
	 */
	cycle?: boolean;
}

A
Alex Dima 已提交
196 197 198
/**
 * Configuration options for editor suggest widget
 */
199 200 201 202 203
export interface ISuggestOptions {
	/**
	 * Enable graceful matching. Defaults to true.
	 */
	filterGraceful?: boolean;
204 205 206 207
	/**
	 * Prevent quick suggestions when a snippet is active. Defaults to true.
	 */
	snippetsPreventQuickSuggestions?: boolean;
J
Johannes Rieken 已提交
208 209 210 211
	/**
	 * Favours words that appear close to the cursor.
	 */
	localityBonus?: boolean;
212 213 214
	/**
	 * Enable using global storage for remembering suggestions.
	 */
215
	shareSuggestSelections?: boolean;
216 217 218 219 220 221 222
	/**
	 * Enable or disable icons in suggestions. Defaults to true.
	 */
	showIcons?: boolean;
	/**
	 * Max suggestions to show in suggestions. Defaults to 12.
	 */
A
Alex Dima 已提交
223
	maxVisibleSuggestions?: number;
224 225 226 227
	/**
	 * Names of suggestion types to filter.
	 */
	filteredTypes?: Record<string, boolean>;
228 229
}

A
Alex Dima 已提交
230 231 232
/**
 * Configuration options for go to location
 */
233 234 235 236
export interface IGotoLocationOptions {
	/**
	 * Control how goto-command work when having multiple results.
	 */
J
Johannes Rieken 已提交
237
	multiple?: 'peek' | 'gotoAndPeek' | 'goto';
238 239
}

A
Alex Dima 已提交
240 241 242
/**
 * Configuration options for quick suggestions
 */
A
Alex Dima 已提交
243 244 245 246
export interface IQuickSuggestionsOptions {
	other: boolean;
	comments: boolean;
	strings: boolean;
247 248
}

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
/**
 * Configuration options for the editor.
 */
export interface IEditorOptions {
	/**
	 * This editor is used inside a diff editor.
	 */
	inDiffEditor?: boolean;
	/**
	 * The aria label for the editor's textarea (when it is focused).
	 */
	ariaLabel?: string;
	/**
	 * Render vertical lines at the specified columns.
	 * Defaults to empty array.
	 */
	rulers?: number[];
	/**
	 * A string containing the word separators used when doing word navigation.
	 * Defaults to `~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?
	 */
	wordSeparators?: string;
	/**
	 * Enable Linux primary clipboard.
	 * Defaults to true.
	 */
	selectionClipboard?: boolean;
	/**
	 * Control the rendering of line numbers.
	 * If it is a function, it will be invoked when rendering a line number and the return value will be rendered.
	 * Otherwise, if it is a truey, line numbers will be rendered normally (equivalent of using an identity function).
	 * Otherwise, line numbers will not be rendered.
	 * Defaults to true.
	 */
A
Alex Dima 已提交
283
	lineNumbers?: LineNumbersType;
P
Peng Lyu 已提交
284
	/**
285
	 * Controls the minimal number of visible leading and trailing lines surrounding the cursor.
P
Peng Lyu 已提交
286 287
	 * Defaults to 0.
	*/
288
	cursorSurroundingLines?: number;
A
Alex Dima 已提交
289 290
	/**
	 * Render last line number when the file ends with a newline.
A
Alex Dima 已提交
291
	 * Defaults to true.
292
	*/
A
Alex Dima 已提交
293
	renderFinalNewline?: boolean;
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
	/**
	 * Should the corresponding line be selected when clicking on the line number?
	 * Defaults to true.
	 */
	selectOnLineNumbers?: boolean;
	/**
	 * Control the width of line numbers, by reserving horizontal space for rendering at least an amount of digits.
	 * Defaults to 5.
	 */
	lineNumbersMinChars?: number;
	/**
	 * Enable the rendering of the glyph margin.
	 * Defaults to true in vscode and to false in monaco-editor.
	 */
	glyphMargin?: boolean;
	/**
	 * The width reserved for line decorations (in px).
	 * Line decorations are placed between line numbers and the editor content.
	 * You can pass in a string in the format floating point followed by "ch". e.g. 1.3ch.
	 * Defaults to 10.
	 */
	lineDecorationsWidth?: number | string;
	/**
	 * When revealing the cursor, a virtual padding (px) is added to the cursor, turning it into a rectangle.
	 * This virtual padding ensures that the cursor gets revealed before hitting the edge of the viewport.
	 * Defaults to 30 (px).
	 */
	revealHorizontalRightPadding?: number;
	/**
	 * Render the editor selection with rounded borders.
	 * Defaults to true.
	 */
	roundedSelection?: boolean;
	/**
328
	 * Class name to be added to the editor.
329
	 */
330
	extraEditorClassName?: string;
331 332 333 334 335 336 337 338 339 340 341 342 343
	/**
	 * Should the editor be read only.
	 * Defaults to false.
	 */
	readOnly?: boolean;
	/**
	 * Control the behavior and rendering of the scrollbars.
	 */
	scrollbar?: IEditorScrollbarOptions;
	/**
	 * Control the behavior and rendering of the minimap.
	 */
	minimap?: IEditorMinimapOptions;
344 345 346 347
	/**
	 * Control the behavior of the find widget.
	 */
	find?: IEditorFindOptions;
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
	/**
	 * Display overflow widgets as `fixed`.
	 * Defaults to `false`.
	 */
	fixedOverflowWidgets?: boolean;
	/**
	 * The number of vertical lanes the overview ruler should render.
	 * Defaults to 2.
	 */
	overviewRulerLanes?: number;
	/**
	 * Controls if a border should be drawn around the overview ruler.
	 * Defaults to `true`.
	 */
	overviewRulerBorder?: boolean;
	/**
	 * Control the cursor animation style, possible values are 'blink', 'smooth', 'phase', 'expand' and 'solid'.
	 * Defaults to 'blink'.
	 */
A
Alex Dima 已提交
367
	cursorBlinking?: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid';
368 369 370 371 372 373 374 375 376 377
	/**
	 * Zoom the font in the editor when using the mouse wheel in combination with holding Ctrl.
	 * Defaults to false.
	 */
	mouseWheelZoom?: boolean;
	/**
	 * Control the mouse pointer style, either 'text' or 'default' or 'copy'
	 * Defaults to 'text'
	 */
	mouseStyle?: 'text' | 'default' | 'copy';
378 379 380 381 382
	/**
	 * Enable smooth caret animation.
	 * Defaults to false.
	 */
	cursorSmoothCaretAnimation?: boolean;
383 384 385 386
	/**
	 * Control the cursor style, either 'block' or 'line'.
	 * Defaults to 'line'.
	 */
A
Alex Dima 已提交
387
	cursorStyle?: 'line' | 'block' | 'underline' | 'line-thin' | 'block-outline' | 'underline-thin';
388 389 390
	/**
	 * Control the width of the cursor when cursorStyle is set to 'line'
	 */
391
	cursorWidth?: number;
392 393 394 395 396 397
	/**
	 * Enable font ligatures.
	 * Defaults to false.
	 */
	fontLigatures?: boolean;
	/**
398 399
	 * Disable the use of `will-change` for the editor margin and lines layers.
	 * The usage of `will-change` acts as a hint for browsers to create an extra layer.
400 401
	 * Defaults to false.
	 */
402
	disableLayerHinting?: boolean;
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
	/**
	 * Disable the optimizations for monospace fonts.
	 * Defaults to false.
	 */
	disableMonospaceOptimizations?: boolean;
	/**
	 * Should the cursor be hidden in the overview ruler.
	 * Defaults to false.
	 */
	hideCursorInOverviewRuler?: boolean;
	/**
	 * Enable that scrolling can go one screen size after the last line.
	 * Defaults to true.
	 */
	scrollBeyondLastLine?: boolean;
418 419 420 421 422
	/**
	 * Enable that scrolling can go beyond the last column by a number of columns.
	 * Defaults to 5.
	 */
	scrollBeyondLastColumn?: number;
423 424
	/**
	 * Enable that the editor animates scrolling to a position.
425
	 * Defaults to false.
426 427
	 */
	smoothScrolling?: boolean;
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
	/**
	 * Enable that the editor will install an interval to check if its container dom node size has changed.
	 * Enabling this might have a severe performance impact.
	 * Defaults to false.
	 */
	automaticLayout?: boolean;
	/**
	 * Control the wrapping of the editor.
	 * When `wordWrap` = "off", the lines will never wrap.
	 * When `wordWrap` = "on", the lines will wrap at the viewport width.
	 * When `wordWrap` = "wordWrapColumn", the lines will wrap at `wordWrapColumn`.
	 * When `wordWrap` = "bounded", the lines will wrap at min(viewport width, wordWrapColumn).
	 * Defaults to "off".
	 */
	wordWrap?: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
	/**
	 * Control the wrapping of the editor.
	 * When `wordWrap` = "off", the lines will never wrap.
	 * When `wordWrap` = "on", the lines will wrap at the viewport width.
	 * When `wordWrap` = "wordWrapColumn", the lines will wrap at `wordWrapColumn`.
	 * When `wordWrap` = "bounded", the lines will wrap at min(viewport width, wordWrapColumn).
	 * Defaults to 80.
	 */
	wordWrapColumn?: number;
	/**
	 * Force word wrapping when the text appears to be of a minified/generated file.
	 * Defaults to true.
	 */
	wordWrapMinified?: boolean;
	/**
458
	 * Control indentation of wrapped lines. Can be: 'none', 'same', 'indent' or 'deepIndent'.
459 460
	 * Defaults to 'same' in vscode and to 'none' in monaco-editor.
	 */
A
Alex Dima 已提交
461
	wrappingIndent?: 'none' | 'same' | 'indent' | 'deepIndent';
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
	/**
	 * Configure word wrapping characters. A break will be introduced before these characters.
	 * Defaults to '{([+'.
	 */
	wordWrapBreakBeforeCharacters?: string;
	/**
	 * Configure word wrapping characters. A break will be introduced after these characters.
	 * Defaults to ' \t})]?|&,;'.
	 */
	wordWrapBreakAfterCharacters?: string;
	/**
	 * Configure word wrapping characters. A break will be introduced after these characters only if no `wordWrapBreakBeforeCharacters` or `wordWrapBreakAfterCharacters` were found.
	 * Defaults to '.'.
	 */
	wordWrapBreakObtrusiveCharacters?: string;

	/**
	 * Performance guard: Stop rendering a line after x characters.
	 * Defaults to 10000.
	 * Use -1 to never stop rendering
	 */
	stopRenderingLineAfter?: number;
	/**
A
Alex Dima 已提交
485
	 * Configure the editor's hover.
486
	 */
A
Alex Dima 已提交
487
	hover?: IEditorHoverOptions;
488 489 490 491 492
	/**
	 * Enable detecting links and making them clickable.
	 * Defaults to true.
	 */
	links?: boolean;
493
	/**
494
	 * Enable inline color decorators and color picker rendering.
495
	 */
R
rebornix 已提交
496
	colorDecorators?: boolean;
497 498 499 500 501 502 503 504 505 506
	/**
	 * Enable custom contextmenu.
	 * Defaults to true.
	 */
	contextmenu?: boolean;
	/**
	 * A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.
	 * Defaults to 1.
	 */
	mouseWheelScrollSensitivity?: number;
T
Tiago Ribeiro 已提交
507
	/**
508 509
	 * FastScrolling mulitplier speed when pressing `Alt`
	 * Defaults to 5.
T
Tiago Ribeiro 已提交
510 511
	 */
	fastScrollSensitivity?: number;
512 513 514 515
	/**
	 * The modifier to be used to add multiple cursors with the mouse.
	 * Defaults to 'alt'
	 */
516
	multiCursorModifier?: 'ctrlCmd' | 'alt';
517
	/**
A
Alex Dima 已提交
518
	 * Merge overlapping selections.
519 520
	 * Defaults to true
	 */
A
Alex Dima 已提交
521
	multiCursorMergeOverlapping?: boolean;
522 523 524 525 526
	/**
	 * Configure the editor's accessibility support.
	 * Defaults to 'auto'. It is best to leave this to 'auto'.
	 */
	accessibilitySupport?: 'auto' | 'off' | 'on';
527 528 529 530
	/**
	 * Suggest options.
	 */
	suggest?: ISuggestOptions;
531 532 533 534
	/**
	 *
	 */
	gotoLocation?: IGotoLocationOptions;
535 536 537 538
	/**
	 * Enable quick suggestions (shadow suggestions)
	 * Defaults to true.
	 */
A
Alex Dima 已提交
539
	quickSuggestions?: boolean | IQuickSuggestionsOptions;
540 541
	/**
	 * Quick suggestions show delay (in ms)
A
Alex Dima 已提交
542
	 * Defaults to 10 (ms)
543 544 545
	 */
	quickSuggestionsDelay?: number;
	/**
546
	 * Parameter hint options.
547
	 */
548
	parameterHints?: IEditorParameterHintOptions;
549
	/**
550
	 * Options for auto closing brackets.
551
	 * Defaults to language defined behavior.
552
	 */
J
Jackson Kearl 已提交
553
	autoClosingBrackets?: EditorAutoClosingStrategy;
554
	/**
555
	 * Options for auto closing quotes.
556
	 * Defaults to language defined behavior.
J
Jackson Kearl 已提交
557 558
	 */
	autoClosingQuotes?: EditorAutoClosingStrategy;
559 560 561 562
	/**
	 * Options for typing over closing quotes or brackets.
	 */
	autoClosingOvertype?: EditorAutoClosingOvertypeStrategy;
J
Jackson Kearl 已提交
563
	/**
564 565
	 * Options for auto surrounding.
	 * Defaults to always allowing auto surrounding.
566
	 */
567
	autoSurround?: EditorAutoSurroundStrategy;
568 569 570 571 572
	/**
	 * Enable auto indentation adjustment.
	 * Defaults to false.
	 */
	autoIndent?: boolean;
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
	/**
	 * Enable format on type.
	 * Defaults to false.
	 */
	formatOnType?: boolean;
	/**
	 * Enable format on paste.
	 * Defaults to false.
	 */
	formatOnPaste?: boolean;
	/**
	 * Controls if the editor should allow to move selections via drag and drop.
	 * Defaults to false.
	 */
	dragAndDrop?: boolean;
	/**
	 * Enable the suggestion box to pop-up on trigger characters.
	 * Defaults to true.
	 */
	suggestOnTriggerCharacters?: boolean;
	/**
	 * Accept suggestions on ENTER.
595
	 * Defaults to 'on'.
596
	 */
A
Alex Dima 已提交
597
	acceptSuggestionOnEnter?: 'on' | 'smart' | 'off';
598 599 600 601 602 603 604 605 606 607 608 609 610
	/**
	 * Accept suggestions on provider defined characters.
	 * Defaults to true.
	 */
	acceptSuggestionOnCommitCharacter?: boolean;
	/**
	 * Enable snippet suggestions. Default to 'true'.
	 */
	snippetSuggestions?: 'top' | 'bottom' | 'inline' | 'none';
	/**
	 * Copying without a selection copies the current line.
	 */
	emptySelectionClipboard?: boolean;
611
	/**
612
	 * Syntax highlighting is copied.
613
	 */
614
	copyWithSyntaxHighlighting?: boolean;
615 616 617
	/**
	 * The history mode for suggestions.
	 */
M
Martin Aeschlimann 已提交
618
	suggestSelection?: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix';
619 620 621 622 623 624 625 626 627 628
	/**
	 * The font size for the suggest widget.
	 * Defaults to the editor font size.
	 */
	suggestFontSize?: number;
	/**
	 * The line height for the suggest widget.
	 * Defaults to the editor line height.
	 */
	suggestLineHeight?: number;
629 630 631
	/**
	 * Enable tab completion.
	 */
A
Alex Dima 已提交
632
	tabCompletion?: 'on' | 'off' | 'onlySnippets';
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
	/**
	 * Enable selection highlight.
	 * Defaults to true.
	 */
	selectionHighlight?: boolean;
	/**
	 * Enable semantic occurrences highlight.
	 * Defaults to true.
	 */
	occurrencesHighlight?: boolean;
	/**
	 * Show code lens
	 * Defaults to true.
	 */
	codeLens?: boolean;
648 649 650 651
	/**
	 * Control the behavior and rendering of the code action lightbulb.
	 */
	lightbulb?: IEditorLightbulbOptions;
652 653 654 655
	/**
	 * Timeout for running code actions on save.
	 */
	codeActionsOnSaveTimeout?: number;
656 657
	/**
	 * Enable code folding
A
Alex Dima 已提交
658
	 * Defaults to true.
659 660
	 */
	folding?: boolean;
661 662 663 664 665
	/**
	 * Selects the folding strategy. 'auto' uses the strategies contributed for the current document, 'indentation' uses the indentation based folding strategy.
	 * Defaults to 'auto'.
	 */
	foldingStrategy?: 'auto' | 'indentation';
666
	/**
667 668
	 * Controls whether the fold actions in the gutter stay always visible or hide unless the mouse is over the gutter.
	 * Defaults to 'mouseover'.
669
	 */
670
	showFoldingControls?: 'always' | 'mouseover';
671 672 673 674 675 676 677 678 679
	/**
	 * Enable highlighting of matching brackets.
	 * Defaults to true.
	 */
	matchBrackets?: boolean;
	/**
	 * Enable rendering of whitespace.
	 * Defaults to none.
	 */
680
	renderWhitespace?: 'none' | 'boundary' | 'selection' | 'all';
681 682 683 684 685 686 687
	/**
	 * Enable rendering of control characters.
	 * Defaults to false.
	 */
	renderControlCharacters?: boolean;
	/**
	 * Enable rendering of indent guides.
688
	 * Defaults to true.
689 690
	 */
	renderIndentGuides?: boolean;
691
	/**
C
typo  
Coenraad Stijne 已提交
692
	 * Enable highlighting of the active indent guide.
693 694 695
	 * Defaults to true.
	 */
	highlightActiveIndentGuide?: boolean;
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
	/**
	 * Enable rendering of current line highlight.
	 * Defaults to all.
	 */
	renderLineHighlight?: 'none' | 'gutter' | 'line' | 'all';
	/**
	 * Inserting and deleting whitespace follows tab stops.
	 */
	useTabStops?: boolean;
	/**
	 * The font family
	 */
	fontFamily?: string;
	/**
	 * The font weight
	 */
712
	fontWeight?: string;
713 714 715 716 717 718 719 720
	/**
	 * The font size
	 */
	fontSize?: number;
	/**
	 * The line height
	 */
	lineHeight?: number;
721 722 723 724
	/**
	 * The letter spacing
	 */
	letterSpacing?: number;
725 726 727 728
	/**
	 * Controls fading out of unused variables.
	 */
	showUnused?: boolean;
A
Alex Dima 已提交
729
}
A
Alex Dima 已提交
730

731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
/**
 * Configuration options for the diff editor.
 */
export interface IDiffEditorOptions extends IEditorOptions {
	/**
	 * Allow the user to resize the diff editor split view.
	 * Defaults to true.
	 */
	enableSplitViewResizing?: boolean;
	/**
	 * Render the differences in two side-by-side editors.
	 * Defaults to true.
	 */
	renderSideBySide?: boolean;
	/**
	 * Compute the diff by ignoring leading/trailing whitespace
	 * Defaults to true.
	 */
	ignoreTrimWhitespace?: boolean;
	/**
	 * Render +/- indicators for added/deleted changes.
	 * Defaults to true.
	 */
	renderIndicators?: boolean;
	/**
	 * Original model should be editable?
	 * Defaults to false.
	 */
	originalEditable?: boolean;
}

A
Alex Dima 已提交
762 763
//#endregion

764
/**
765
 * An event describing that the configuration of the editor has changed.
766
 */
767 768
export class ConfigurationChangedEvent {
	private readonly _values: boolean[];
769 770 771
	/**
	 * @internal
	 */
772 773
	constructor(values: boolean[]) {
		this._values = values;
774 775
	}

776 777
	public hasChanged(id: EditorOption): boolean {
		return this._values[id];
778 779 780
	}
}

781 782 783 784 785
/**
 * @internal
 */
export class ValidatedEditorOptions {
	private readonly _values: any[] = [];
A
renames  
Alex Dima 已提交
786
	public _read<T>(option: EditorOption): T {
787 788
		return this._values[option];
	}
A
Alex Dima 已提交
789 790 791
	public get<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T> {
		return this._values[id];
	}
A
renames  
Alex Dima 已提交
792
	public _write<T>(option: EditorOption, value: T): void {
793 794 795 796
		this._values[option] = value;
	}
}

A
Alex Dima 已提交
797
export interface IComputedEditorOptions {
A
renames  
Alex Dima 已提交
798
	get<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;
A
Alex Dima 已提交
799 800
}

A
Alex Dima 已提交
801 802
//#region IEditorOption

A
Alex Dima 已提交
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
/**
 * @internal
 */
export interface IEnvironmentalOptions {
	readonly outerWidth: number;
	readonly outerHeight: number;
	readonly fontInfo: FontInfo;
	readonly extraEditorClassName: string;
	readonly isDominatedByLongLines: boolean;
	readonly lineNumbersDigitCount: number;
	readonly emptySelectionClipboard: boolean;
	readonly pixelRatio: number;
	readonly tabFocusMode: boolean;
	readonly accessibilitySupport: AccessibilitySupport;
}

A
Alex Dima 已提交
819 820 821 822
export interface IEditorOption<K1 extends EditorOption, V> {
	readonly id: K1;
	readonly name: string;
	readonly defaultValue: V;
823 824 825 826
	/**
	 * @internal
	 */
	readonly schema: IConfigurationPropertySchema | undefined;
A
Alex Dima 已提交
827 828 829 830 831 832 833 834 835 836
	/**
	 * @internal
	 */
	validate(input: any): V;
	/**
	 * @internal
	 */
	compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V;
}

A
Alex Dima 已提交
837
type PossibleKeyName0<V> = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions];
838
type PossibleKeyName<V> = NonNullable<PossibleKeyName0<V>>;
839

A
Alex Dima 已提交
840
abstract class BaseEditorOption<K1 extends EditorOption, K2 extends keyof IEditorOptions, V> implements IEditorOption<K1, V> {
A
Alex Dima 已提交
841 842 843 844 845

	public readonly id: K1;
	public readonly name: K2;
	public readonly defaultValue: V;
	public readonly deps: EditorOption[] | null;
846
	public readonly schema: IConfigurationPropertySchema | undefined = undefined;
A
Alex Dima 已提交
847 848 849 850 851 852 853 854 855 856 857 858 859

	constructor(id: K1, name: K2, defaultValue: V, deps: EditorOption[] | null = null) {
		this.id = id;
		this.name = name;
		this.defaultValue = defaultValue;
		this.deps = deps;
	}

	public abstract validate(input: any): V;

	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V {
		return value;
	}
860 861
}

862 863 864
/**
 * @internal
 */
A
Alex Dima 已提交
865
abstract class ComputedEditorOption<K1 extends EditorOption, V> implements IEditorOption<K1, V> {
A
Alex Dima 已提交
866

867
	public readonly id: K1;
A
Alex Dima 已提交
868 869 870
	public readonly name: '_never_';
	public readonly defaultValue: V;
	public readonly deps: EditorOption[] | null;
871
	public readonly schema: IConfigurationPropertySchema | undefined = undefined;
A
Alex Dima 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891

	constructor(id: K1, deps: EditorOption[] | null = null) {
		this.id = id;
		this.name = '_never_';
		this.defaultValue = <any>undefined;
		this.deps = deps;
	}

	public validate(input: any): V {
		return this.defaultValue;
	}

	public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V;
}

class SimpleEditorOption<K1 extends EditorOption, V> implements IEditorOption<K1, V> {

	public readonly id: K1;
	public readonly name: PossibleKeyName<V>;
	public readonly defaultValue: V;
892
	public readonly schema: IConfigurationPropertySchema | undefined;
A
Alex Dima 已提交
893
	public readonly deps: EditorOption[] | null;
894

895
	constructor(id: K1, name: PossibleKeyName<V>, defaultValue: V, schema?: IConfigurationPropertySchema, deps: EditorOption[] | null = null) {
896 897 898
		this.id = id;
		this.name = name;
		this.defaultValue = defaultValue;
899
		this.schema = schema;
A
Alex Dima 已提交
900 901 902 903 904 905
		this.deps = deps;
	}

	public validate(input: any): V {
		if (typeof input === 'undefined') {
			return this.defaultValue;
A
Alex Dima 已提交
906
		}
A
Alex Dima 已提交
907 908 909 910 911
		return input as any;
	}

	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V {
		return value;
912
	}
A
Alex Dima 已提交
913
}
914

A
Alex Dima 已提交
915 916 917 918 919 920 921 922 923 924 925
class EditorBooleanOption<K1 extends EditorOption> extends SimpleEditorOption<K1, boolean> {

	public static boolean(value: any, defaultValue: boolean): boolean {
		if (typeof value === 'undefined') {
			return defaultValue;
		}
		if (value === 'false') {
			// treat the string 'false' as false
			return false;
		}
		return Boolean(value);
A
Alex Dima 已提交
926 927
	}

928 929 930 931 932 933 934 935
	constructor(id: K1, name: PossibleKeyName<boolean>, defaultValue: boolean, schema: IConfigurationPropertySchema | undefined = undefined, deps: EditorOption[] | null = null) {
		if (typeof schema !== 'undefined') {
			schema.type = 'boolean';
			schema.default = defaultValue;
		}
		super(id, name, defaultValue, schema, deps);
	}

A
Alex Dima 已提交
936
	public validate(input: any): boolean {
A
Alex Dima 已提交
937
		return EditorBooleanOption.boolean(input, this.defaultValue);
938
	}
A
Alex Dima 已提交
939
}
940

A
Alex Dima 已提交
941
class EditorIntOption<K1 extends EditorOption> extends SimpleEditorOption<K1, number> {
A
Alex Dima 已提交
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957

	public static clampedInt(value: any, defaultValue: number, minimum: number, maximum: number): number {
		let r: number;
		if (typeof value === 'undefined') {
			r = defaultValue;
		} else {
			r = parseInt(value, 10);
			if (isNaN(r)) {
				r = defaultValue;
			}
		}
		r = Math.max(minimum, r);
		r = Math.min(maximum, r);
		return r | 0;
	}

A
Alex Dima 已提交
958 959
	public readonly minimum: number;
	public readonly maximum: number;
A
Alex Dima 已提交
960 961
	constructor(id: K1, name: PossibleKeyName<number>, defaultValue: number, minimum: number, maximum: number) {
		super(id, name, defaultValue);
A
Alex Dima 已提交
962 963 964
		this.minimum = minimum;
		this.maximum = maximum;
	}
A
Alex Dima 已提交
965
	public validate(input: any): number {
A
Alex Dima 已提交
966
		return EditorIntOption.clampedInt(input, this.defaultValue, this.minimum, this.maximum);
A
Alex Dima 已提交
967 968
	}
}
969

A
Alex Dima 已提交
970
class EditorFloatOption<K1 extends EditorOption> extends SimpleEditorOption<K1, number> {
A
Alex Dima 已提交
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992

	public static clamp(n: number, min: number, max: number): number {
		if (n < min) {
			return min;
		}
		if (n > max) {
			return max;
		}
		return n;
	}

	public static float(value: any, defaultValue: number): number {
		if (typeof value === 'number') {
			return value;
		}
		if (typeof value === 'undefined') {
			return defaultValue;
		}
		const r = parseFloat(value);
		return (isNaN(r) ? defaultValue : r);
	}

A
Alex Dima 已提交
993
	public readonly validationFn: (value: number) => number;
A
Alex Dima 已提交
994 995
	constructor(id: K1, name: PossibleKeyName<number>, defaultValue: number, validationFn: (value: number) => number) {
		super(id, name, defaultValue);
A
Alex Dima 已提交
996 997
		this.validationFn = validationFn;
	}
A
Alex Dima 已提交
998
	public validate(input: any): number {
A
Alex Dima 已提交
999
		return this.validationFn(EditorFloatOption.float(input, this.defaultValue));
A
Alex Dima 已提交
1000
	}
1001 1002
}

A
Alex Dima 已提交
1003
class EditorStringOption<K1 extends EditorOption> extends SimpleEditorOption<K1, string> {
A
Alex Dima 已提交
1004 1005 1006 1007 1008 1009 1010 1011

	public static string(value: any, defaultValue: string): string {
		if (typeof value !== 'string') {
			return defaultValue;
		}
		return value;
	}

A
Alex Dima 已提交
1012
	public validate(input: any): string {
A
Alex Dima 已提交
1013
		return EditorStringOption.string(input, this.defaultValue);
A
Alex Dima 已提交
1014 1015
	}
}
1016

A
Alex Dima 已提交
1017
class EditorStringEnumOption<K1 extends EditorOption, V extends string> extends SimpleEditorOption<K1, V> {
A
Alex Dima 已提交
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028

	public static stringSet<T>(value: T | undefined, defaultValue: T, allowedValues: ReadonlyArray<T>): T {
		if (typeof value !== 'string') {
			return defaultValue;
		}
		if (allowedValues.indexOf(value) === -1) {
			return defaultValue;
		}
		return value;
	}

A
Alex Dima 已提交
1029 1030 1031
	public readonly allowedValues: ReadonlyArray<V>;
	constructor(id: K1, name: PossibleKeyName<V>, defaultValue: V, allowedValues: ReadonlyArray<V>) {
		super(id, name, defaultValue);
A
Alex Dima 已提交
1032 1033
		this.allowedValues = allowedValues;
	}
A
Alex Dima 已提交
1034
	public validate(input: any): V {
A
Alex Dima 已提交
1035
		return EditorStringEnumOption.stringSet<V>(input, this.defaultValue, this.allowedValues);
A
Alex Dima 已提交
1036 1037 1038
	}
}

A
Alex Dima 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
class EditorEnumOption<K1 extends EditorOption, T extends string, V> extends BaseEditorOption<K1, PossibleKeyName<T>, V> {
	public readonly allowedValues: T[];
	public readonly convert: (value: T) => V;
	constructor(id: K1, name: PossibleKeyName<T>, defaultValue: V, allowedValues: T[], convert: (value: T) => V, deps: EditorOption[] = []) {
		super(id, name, defaultValue, deps);
		this.allowedValues = allowedValues;
		this.convert = convert;
	}
	public validate(input: any): V {
		if (typeof input !== 'string') {
A
Alex Dima 已提交
1049 1050
			return this.defaultValue;
		}
A
Alex Dima 已提交
1051 1052 1053 1054
		if (this.allowedValues.indexOf(<T>input) === -1) {
			return this.defaultValue;
		}
		return this.convert(<any>input);
A
Alex Dima 已提交
1055 1056
	}
}
A
Alex Dima 已提交
1057

A
Alex Dima 已提交
1058
//#endregion
A
Alex Dima 已提交
1059 1060 1061

//#region accessibilitySupport

A
Alex Dima 已提交
1062 1063 1064 1065 1066 1067 1068 1069
class EditorAccessibilitySupportOption<K1 extends EditorOption, K2 extends PossibleKeyName<'auto' | 'off' | 'on'>> extends BaseEditorOption<K1, K2, AccessibilitySupport> {
	public validate(input: any): AccessibilitySupport {
		switch (input) {
			case 'auto': return AccessibilitySupport.Unknown;
			case 'off': return AccessibilitySupport.Disabled;
			case 'on': return AccessibilitySupport.Enabled;
		}
		return this.defaultValue;
A
Alex Dima 已提交
1070
	}
A
Alex Dima 已提交
1071 1072
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: AccessibilitySupport): AccessibilitySupport {
		if (value === AccessibilitySupport.Unknown) {
A
Alex Dima 已提交
1073 1074 1075
			// The editor reads the `accessibilitySupport` from the environment
			return env.accessibilitySupport;
		}
A
Alex Dima 已提交
1076
		return value;
A
Alex Dima 已提交
1077 1078 1079 1080 1081 1082 1083
	}
}

//#endregion

//#region ariaLabel

A
Alex Dima 已提交
1084 1085
class EditorAriaLabel<K1 extends EditorOption> extends SimpleEditorOption<K1, string> {
	public validate(input: any): string {
A
Alex Dima 已提交
1086
		return EditorStringOption.string(input, this.defaultValue);
A
Alex Dima 已提交
1087 1088
	}
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string {
A
renames  
Alex Dima 已提交
1089
		const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
A
Alex Dima 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098
		if (accessibilitySupport === AccessibilitySupport.Disabled) {
			return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options.");
		}
		return value;
	}
}

//#endregion

A
Alex Dima 已提交
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
//#region cursorBlinking

/**
 * The kind of animation in which the editor's cursor should be rendered.
 */
export const enum TextEditorCursorBlinkingStyle {
	/**
	 * Hidden
	 */
	Hidden = 0,
	/**
	 * Blinking
	 */
	Blink = 1,
	/**
	 * Blinking with smooth fading
	 */
	Smooth = 2,
	/**
	 * Blinking with prolonged filled state and smooth fading
	 */
	Phase = 3,
	/**
	 * Expand collapse animation on the y axis
	 */
	Expand = 4,
	/**
	 * No-Blinking
	 */
	Solid = 5
}

function _cursorBlinkingStyleFromString(cursorBlinkingStyle: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid'): TextEditorCursorBlinkingStyle {
	switch (cursorBlinkingStyle) {
		case 'blink': return TextEditorCursorBlinkingStyle.Blink;
		case 'smooth': return TextEditorCursorBlinkingStyle.Smooth;
		case 'phase': return TextEditorCursorBlinkingStyle.Phase;
		case 'expand': return TextEditorCursorBlinkingStyle.Expand;
		case 'solid': return TextEditorCursorBlinkingStyle.Solid;
	}
}

//#endregion

//#region cursorStyle

/**
 * The style in which the editor's cursor should be rendered.
 */
export enum TextEditorCursorStyle {
	/**
	 * As a vertical line (sitting between two characters).
	 */
	Line = 1,
	/**
	 * As a block (sitting on top of a character).
	 */
	Block = 2,
	/**
	 * As a horizontal line (sitting under a character).
	 */
	Underline = 3,
	/**
	 * As a thin vertical line (sitting between two characters).
	 */
	LineThin = 4,
	/**
	 * As an outlined block (sitting on top of a character).
	 */
	BlockOutline = 5,
	/**
	 * As a thin horizontal line (sitting under a character).
	 */
	UnderlineThin = 6
}

/**
 * @internal
 */
export function cursorStyleToString(cursorStyle: TextEditorCursorStyle): 'line' | 'block' | 'underline' | 'line-thin' | 'block-outline' | 'underline-thin' {
	switch (cursorStyle) {
		case TextEditorCursorStyle.Line: return 'line';
		case TextEditorCursorStyle.Block: return 'block';
		case TextEditorCursorStyle.Underline: return 'underline';
		case TextEditorCursorStyle.LineThin: return 'line-thin';
		case TextEditorCursorStyle.BlockOutline: return 'block-outline';
		case TextEditorCursorStyle.UnderlineThin: return 'underline-thin';
	}
}

function _cursorStyleFromString(cursorStyle: 'line' | 'block' | 'underline' | 'line-thin' | 'block-outline' | 'underline-thin'): TextEditorCursorStyle {
	switch (cursorStyle) {
		case 'line': return TextEditorCursorStyle.Line;
		case 'block': return TextEditorCursorStyle.Block;
		case 'underline': return TextEditorCursorStyle.Underline;
		case 'line-thin': return TextEditorCursorStyle.LineThin;
		case 'block-outline': return TextEditorCursorStyle.BlockOutline;
		case 'underline-thin': return TextEditorCursorStyle.UnderlineThin;
	}
}

//#endregion

A
Alex Dima 已提交
1202 1203
//#region disableMonospaceOptimizations

A
Alex Dima 已提交
1204 1205
class EditorDisableMonospaceOptimizations<K1 extends EditorOption> extends SimpleEditorOption<K1, boolean> {
	public validate(input: any): boolean {
A
Alex Dima 已提交
1206
		return EditorBooleanOption.boolean(input, this.defaultValue);
A
Alex Dima 已提交
1207 1208
	}
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean {
A
Alex Dima 已提交
1209
		return (value || options.get(EditorOption.fontLigatures));
A
Alex Dima 已提交
1210 1211 1212 1213 1214 1215 1216
	}
}

//#endregion

//#region editorClassName

A
Alex Dima 已提交
1217 1218
class EditorClassName<K1 extends EditorOption> extends ComputedEditorOption<K1, string> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: string): string {
A
Alex Dima 已提交
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
		let className = 'monaco-editor';
		if (options.get(EditorOption.extraEditorClassName)) {
			className += ' ' + options.get(EditorOption.extraEditorClassName);
		}
		if (env.extraEditorClassName) {
			className += ' ' + env.extraEditorClassName;
		}
		if (options.get(EditorOption.fontLigatures)) {
			className += ' enable-ligatures';
		}
		if (options.get(EditorOption.mouseStyle) === 'default') {
			className += ' mouse-default';
		} else if (options.get(EditorOption.mouseStyle) === 'copy') {
			className += ' mouse-copy';
		}
		return className;
	}
}

//#endregion

A
Alex Dima 已提交
1240
//#region emptySelectionClipboard
1241

A
Alex Dima 已提交
1242 1243 1244
class EditorEmptySelectionClipboard<K1 extends EditorOption> extends EditorBooleanOption<K1> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean {
		return value && env.emptySelectionClipboard;
1245 1246 1247 1248 1249
	}
}

//#endregion

A
Alex Dima 已提交
1250
//#region find
A
Alex Dima 已提交
1251

A
Alex Dima 已提交
1252
export type EditorFindOptions = Readonly<Required<IEditorFindOptions>>;
A
Alex Dima 已提交
1253

A
Alex Dima 已提交
1254 1255
class EditorFind<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorFindOptions>> extends BaseEditorOption<K1, K2, EditorFindOptions> {
	public validate(_input: any): EditorFindOptions {
A
Alex Dima 已提交
1256 1257 1258 1259 1260
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as IEditorFindOptions;
		return {
A
Alex Dima 已提交
1261 1262 1263 1264
			seedSearchStringFromSelection: EditorBooleanOption.boolean(input.seedSearchStringFromSelection, this.defaultValue.seedSearchStringFromSelection),
			autoFindInSelection: EditorBooleanOption.boolean(input.autoFindInSelection, this.defaultValue.autoFindInSelection),
			globalFindClipboard: EditorBooleanOption.boolean(input.globalFindClipboard, this.defaultValue.globalFindClipboard),
			addExtraSpaceOnTop: EditorBooleanOption.boolean(input.addExtraSpaceOnTop, this.defaultValue.addExtraSpaceOnTop)
A
Alex Dima 已提交
1265
		};
A
Alex Dima 已提交
1266 1267 1268 1269 1270
	}
}

//#endregion

A
Alex Dima 已提交
1271
//#region fontInfo
A
Alex Dima 已提交
1272

A
Alex Dima 已提交
1273 1274 1275
class EditorFontInfo<K1 extends EditorOption> extends ComputedEditorOption<K1, FontInfo> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: FontInfo): FontInfo {
		return env.fontInfo;
A
Alex Dima 已提交
1276 1277 1278 1279 1280
	}
}

//#endregion

A
Alex Dima 已提交
1281 1282
//#region fontSize

A
Alex Dima 已提交
1283 1284
class EditorFontSize<K1 extends EditorOption> extends SimpleEditorOption<K1, number> {
	public validate(input: any): number {
A
Alex Dima 已提交
1285
		let r = EditorFloatOption.float(input, this.defaultValue);
A
Alex Dima 已提交
1286 1287 1288
		if (r === 0) {
			return EDITOR_FONT_DEFAULTS.fontSize;
		}
A
Alex Dima 已提交
1289
		return EditorFloatOption.clamp(r, 8, 100);
A
Alex Dima 已提交
1290 1291
	}
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number {
A
Alex Dima 已提交
1292 1293 1294
		// The final fontSize respects the editor zoom level.
		// So take the result from env.fontInfo
		return env.fontInfo.fontSize;
A
Alex Dima 已提交
1295 1296 1297 1298 1299
	}
}

//#endregion

A
Alex Dima 已提交
1300
//#region gotoLocation
A
Alex Dima 已提交
1301

A
Alex Dima 已提交
1302
export type GoToLocationOptions = Readonly<Required<IGotoLocationOptions>>;
A
Alex Dima 已提交
1303

A
Alex Dima 已提交
1304 1305
class EditorGoToLocation<K1 extends EditorOption, K2 extends PossibleKeyName<IGotoLocationOptions>> extends BaseEditorOption<K1, K2, GoToLocationOptions> {
	public validate(_input: any): GoToLocationOptions {
A
Alex Dima 已提交
1306
		if (typeof _input !== 'object') {
A
Alex Dima 已提交
1307 1308
			return this.defaultValue;
		}
A
Alex Dima 已提交
1309
		const input = _input as IGotoLocationOptions;
A
Alex Dima 已提交
1310
		return {
A
Alex Dima 已提交
1311
			multiple: EditorStringEnumOption.stringSet<'peek' | 'gotoAndPeek' | 'goto'>(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto'])
A
Alex Dima 已提交
1312 1313 1314 1315 1316 1317
		};
	}
}

//#endregion

A
Alex Dima 已提交
1318
//#region hover
A
Alex Dima 已提交
1319

A
Alex Dima 已提交
1320
export type EditorHoverOptions = Readonly<Required<IEditorHoverOptions>>;
A
Alex Dima 已提交
1321

A
Alex Dima 已提交
1322 1323
class EditorHover<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorHoverOptions>> extends BaseEditorOption<K1, K2, EditorHoverOptions> {
	public validate(_input: any): EditorHoverOptions {
A
Alex Dima 已提交
1324
		if (typeof _input !== 'object') {
A
Alex Dima 已提交
1325 1326
			return this.defaultValue;
		}
A
Alex Dima 已提交
1327
		const input = _input as IEditorHoverOptions;
A
Alex Dima 已提交
1328
		return {
A
Alex Dima 已提交
1329
			enabled: EditorBooleanOption.boolean(input.enabled, this.defaultValue.enabled),
A
Alex Dima 已提交
1330
			delay: EditorIntOption.clampedInt(input.delay, this.defaultValue.delay, 0, 10000),
A
Alex Dima 已提交
1331
			sticky: EditorBooleanOption.boolean(input.sticky, this.defaultValue.sticky)
A
Alex Dima 已提交
1332 1333 1334 1335 1336 1337
		};
	}
}

//#endregion

A
Alex Dima 已提交
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
//#region layoutInfo

/**
 * A description for the overview ruler position.
 */
export interface OverviewRulerPosition {
	/**
	 * Width of the overview ruler
	 */
	readonly width: number;
	/**
	 * Height of the overview ruler
	 */
	readonly height: number;
	/**
	 * Top position for the overview ruler
	 */
	readonly top: number;
	/**
	 * Right position for the overview ruler
	 */
	readonly right: number;
}

A
Alex Dima 已提交
1362 1363 1364 1365 1366 1367 1368 1369
export const enum RenderMinimap {
	None = 0,
	Small = 1,
	Large = 2,
	SmallBlocks = 3,
	LargeBlocks = 4,
}

A
Alex Dima 已提交
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
/**
 * The internal layout details of the editor.
 */
export interface EditorLayoutInfo {

	/**
	 * Full editor width.
	 */
	readonly width: number;
	/**
	 * Full editor height.
	 */
	readonly height: number;

	/**
	 * Left position for the glyph margin.
	 */
	readonly glyphMarginLeft: number;
	/**
	 * The width of the glyph margin.
	 */
	readonly glyphMarginWidth: number;
	/**
	 * The height of the glyph margin.
	 */
	readonly glyphMarginHeight: number;

	/**
	 * Left position for the line numbers.
	 */
	readonly lineNumbersLeft: number;
	/**
	 * The width of the line numbers.
	 */
	readonly lineNumbersWidth: number;
	/**
	 * The height of the line numbers.
	 */
	readonly lineNumbersHeight: number;

	/**
	 * Left position for the line decorations.
	 */
	readonly decorationsLeft: number;
	/**
	 * The width of the line decorations.
	 */
	readonly decorationsWidth: number;
	/**
	 * The height of the line decorations.
	 */
	readonly decorationsHeight: number;

	/**
	 * Left position for the content (actual text)
	 */
	readonly contentLeft: number;
	/**
	 * The width of the content (actual text)
	 */
	readonly contentWidth: number;
	/**
	 * The height of the content (actual height)
	 */
	readonly contentHeight: number;

	/**
	 * The position for the minimap
	 */
	readonly minimapLeft: number;
	/**
	 * The width of the minimap
	 */
	readonly minimapWidth: number;

	/**
	 * Minimap render type
	 */
	readonly renderMinimap: RenderMinimap;

	/**
	 * The number of columns (of typical characters) fitting on a viewport line.
	 */
	readonly viewportColumn: number;

	/**
	 * The width of the vertical scrollbar.
	 */
	readonly verticalScrollbarWidth: number;
	/**
	 * The height of the horizontal scrollbar.
	 */
	readonly horizontalScrollbarHeight: number;

	/**
	 * The position of the overview ruler.
	 */
	readonly overviewRuler: OverviewRulerPosition;
}

A
Alex Dima 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
/**
 * @internal
 */
export interface EditorLayoutInfoComputerEnv {
	outerWidth: number;
	outerHeight: number;
	lineHeight: number;
	lineNumbersDigitCount: number;
	typicalHalfwidthCharacterWidth: number;
	maxDigitWidth: number;
	pixelRatio: number;
}

A
Alex Dima 已提交
1483 1484 1485
/**
 * @internal
 */
A
Alex Dima 已提交
1486 1487
export class EditorLayoutInfoComputer<K1 extends EditorOption> extends ComputedEditorOption<K1, EditorLayoutInfo> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: EditorLayoutInfo): EditorLayoutInfo {
A
Alex Dima 已提交
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
		return EditorLayoutInfoComputer.computeLayout(options, {
			outerWidth: env.outerWidth,
			outerHeight: env.outerHeight,
			lineHeight: env.fontInfo.lineHeight,
			lineNumbersDigitCount: env.lineNumbersDigitCount,
			typicalHalfwidthCharacterWidth: env.fontInfo.typicalHalfwidthCharacterWidth,
			maxDigitWidth: env.fontInfo.maxDigitWidth,
			pixelRatio: env.pixelRatio
		});
	}

	public static computeLayout(options: IComputedEditorOptions, env: EditorLayoutInfoComputerEnv): EditorLayoutInfo {
		const outerWidth = env.outerWidth | 0;
		const outerHeight = env.outerHeight | 0;
		const lineHeight = env.lineHeight | 0;
		const lineNumbersDigitCount = env.lineNumbersDigitCount | 0;
		const typicalHalfwidthCharacterWidth = env.typicalHalfwidthCharacterWidth;
		const maxDigitWidth = env.maxDigitWidth;
		const pixelRatio = env.pixelRatio;

		const showGlyphMargin = options.get(EditorOption.glyphMargin);
		const showLineNumbers = (options.get(EditorOption.lineNumbers).renderType !== RenderLineNumbersType.Off);
		const lineNumbersMinChars = options.get(EditorOption.lineNumbersMinChars) | 0;
A
renames  
Alex Dima 已提交
1511
		const minimap = options.get(EditorOption.minimap);
A
Alex Dima 已提交
1512 1513 1514 1515 1516
		const minimapEnabled = minimap.enabled;
		const minimapSide = minimap.side;
		const minimapRenderCharacters = minimap.renderCharacters;
		const minimapMaxColumn = minimap.maxColumn | 0;

A
renames  
Alex Dima 已提交
1517
		const scrollbar = options.get(EditorOption.scrollbar);
A
Alex Dima 已提交
1518 1519 1520 1521 1522 1523 1524
		const verticalScrollbarWidth = scrollbar.verticalScrollbarSize | 0;
		const verticalScrollbarHasArrows = scrollbar.verticalHasArrows;
		const scrollbarArrowSize = scrollbar.arrowSize | 0;
		const horizontalScrollbarHeight = scrollbar.horizontalScrollbarSize | 0;

		const rawLineDecorationsWidth = options.get(EditorOption.lineDecorationsWidth);
		const folding = options.get(EditorOption.folding);
A
Alex Dima 已提交
1525 1526 1527 1528

		let lineDecorationsWidth: number;
		if (typeof rawLineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(rawLineDecorationsWidth)) {
			const multiple = parseFloat(rawLineDecorationsWidth.substr(0, rawLineDecorationsWidth.length - 2));
A
Alex Dima 已提交
1529
			lineDecorationsWidth = EditorIntOption.clampedInt(multiple * typicalHalfwidthCharacterWidth, 0, 0, 1000);
A
Alex Dima 已提交
1530
		} else {
A
Alex Dima 已提交
1531
			lineDecorationsWidth = EditorIntOption.clampedInt(rawLineDecorationsWidth, 0, 0, 1000);
A
Alex Dima 已提交
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
		}
		if (folding) {
			lineDecorationsWidth += 16;
		}

		let lineNumbersWidth = 0;
		if (showLineNumbers) {
			const digitCount = Math.max(lineNumbersDigitCount, lineNumbersMinChars);
			lineNumbersWidth = Math.round(digitCount * maxDigitWidth);
		}

		let glyphMarginWidth = 0;
		if (showGlyphMargin) {
			glyphMarginWidth = lineHeight;
		}

		let glyphMarginLeft = 0;
		let lineNumbersLeft = glyphMarginLeft + glyphMarginWidth;
		let decorationsLeft = lineNumbersLeft + lineNumbersWidth;
		let contentLeft = decorationsLeft + lineDecorationsWidth;

		const remainingWidth = outerWidth - glyphMarginWidth - lineNumbersWidth - lineDecorationsWidth;

		let renderMinimap: RenderMinimap;
		let minimapLeft: number;
		let minimapWidth: number;
		let contentWidth: number;
A
Alex Dima 已提交
1559
		if (!minimapEnabled) {
A
Alex Dima 已提交
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
			minimapLeft = 0;
			minimapWidth = 0;
			renderMinimap = RenderMinimap.None;
			contentWidth = remainingWidth;
		} else {
			let minimapCharWidth: number;
			if (pixelRatio >= 2) {
				renderMinimap = minimapRenderCharacters ? RenderMinimap.Large : RenderMinimap.LargeBlocks;
				minimapCharWidth = 2 / pixelRatio;
			} else {
				renderMinimap = minimapRenderCharacters ? RenderMinimap.Small : RenderMinimap.SmallBlocks;
				minimapCharWidth = 1 / pixelRatio;
			}

			// Given:
			// (leaving 2px for the cursor to have space after the last character)
			// viewportColumn = (contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth
			// minimapWidth = viewportColumn * minimapCharWidth
			// contentWidth = remainingWidth - minimapWidth
			// What are good values for contentWidth and minimapWidth ?

			// minimapWidth = ((contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth) * minimapCharWidth
			// typicalHalfwidthCharacterWidth * minimapWidth = (contentWidth - verticalScrollbarWidth - 2) * minimapCharWidth
			// typicalHalfwidthCharacterWidth * minimapWidth = (remainingWidth - minimapWidth - verticalScrollbarWidth - 2) * minimapCharWidth
			// (typicalHalfwidthCharacterWidth + minimapCharWidth) * minimapWidth = (remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth
			// minimapWidth = ((remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth) / (typicalHalfwidthCharacterWidth + minimapCharWidth)

			minimapWidth = Math.max(0, Math.floor(((remainingWidth - verticalScrollbarWidth - 2) * minimapCharWidth) / (typicalHalfwidthCharacterWidth + minimapCharWidth)));
			let minimapColumns = minimapWidth / minimapCharWidth;
			if (minimapColumns > minimapMaxColumn) {
				minimapWidth = Math.floor(minimapMaxColumn * minimapCharWidth);
			}
			contentWidth = remainingWidth - minimapWidth;

			if (minimapSide === 'left') {
				minimapLeft = 0;
				glyphMarginLeft += minimapWidth;
				lineNumbersLeft += minimapWidth;
				decorationsLeft += minimapWidth;
				contentLeft += minimapWidth;
			} else {
				minimapLeft = outerWidth - minimapWidth - verticalScrollbarWidth;
			}
		}

		// (leaving 2px for the cursor to have space after the last character)
		const viewportColumn = Math.max(1, Math.floor((contentWidth - verticalScrollbarWidth - 2) / typicalHalfwidthCharacterWidth));

		const verticalArrowSize = (verticalScrollbarHasArrows ? scrollbarArrowSize : 0);

		return {
			width: outerWidth,
			height: outerHeight,

			glyphMarginLeft: glyphMarginLeft,
			glyphMarginWidth: glyphMarginWidth,
			glyphMarginHeight: outerHeight,

			lineNumbersLeft: lineNumbersLeft,
			lineNumbersWidth: lineNumbersWidth,
			lineNumbersHeight: outerHeight,

			decorationsLeft: decorationsLeft,
			decorationsWidth: lineDecorationsWidth,
			decorationsHeight: outerHeight,

			contentLeft: contentLeft,
			contentWidth: contentWidth,
			contentHeight: outerHeight,

			renderMinimap: renderMinimap,
			minimapLeft: minimapLeft,
			minimapWidth: minimapWidth,

			viewportColumn: viewportColumn,

			verticalScrollbarWidth: verticalScrollbarWidth,
			horizontalScrollbarHeight: horizontalScrollbarHeight,

			overviewRuler: {
				top: verticalArrowSize,
				width: verticalScrollbarWidth,
				height: (outerHeight - 2 * verticalArrowSize),
				right: 0
			}
		};
	}
}

//#endregion

A
Alex Dima 已提交
1651 1652
//#region lightbulb

A
Alex Dima 已提交
1653
export type EditorLightbulbOptions = Readonly<Required<IEditorLightbulbOptions>>;
A
Alex Dima 已提交
1654

A
Alex Dima 已提交
1655 1656
class EditorLightbulb<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorLightbulbOptions>> extends BaseEditorOption<K1, K2, EditorLightbulbOptions> {
	public validate(_input: any): EditorLightbulbOptions {
A
Alex Dima 已提交
1657 1658 1659 1660 1661
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as IEditorLightbulbOptions;
		return {
A
Alex Dima 已提交
1662
			enabled: EditorBooleanOption.boolean(input.enabled, this.defaultValue.enabled)
A
Alex Dima 已提交
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
		};
	}
}

//#endregion

//#region lineHeight

class EditorLineHeight<K1 extends EditorOption, K2 extends PossibleKeyName<number>> extends EditorIntOption<K1> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number {
		// The lineHeight is computed from the fontSize if it is 0.
		// Moreover, the final lineHeight respects the editor zoom level.
		// So take the result from env.fontInfo
		return env.fontInfo.lineHeight;
	}
}

//#endregion

//#region minimap

A
Alex Dima 已提交
1684
export type EditorMinimapOptions = Readonly<Required<IEditorMinimapOptions>>;
A
Alex Dima 已提交
1685

A
Alex Dima 已提交
1686 1687
class EditorMinimap<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorMinimapOptions>> extends BaseEditorOption<K1, K2, EditorMinimapOptions> {
	public validate(_input: any): EditorMinimapOptions {
A
Alex Dima 已提交
1688 1689 1690 1691 1692
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as IEditorMinimapOptions;
		return {
A
Alex Dima 已提交
1693
			enabled: EditorBooleanOption.boolean(input.enabled, this.defaultValue.enabled),
A
Alex Dima 已提交
1694 1695
			side: EditorStringEnumOption.stringSet<'right' | 'left'>(input.side, this.defaultValue.side, ['right', 'left']),
			showSlider: EditorStringEnumOption.stringSet<'always' | 'mouseover'>(input.showSlider, this.defaultValue.showSlider, ['always', 'mouseover']),
A
Alex Dima 已提交
1696
			renderCharacters: EditorBooleanOption.boolean(input.renderCharacters, this.defaultValue.renderCharacters),
A
Alex Dima 已提交
1697
			maxColumn: EditorIntOption.clampedInt(input.maxColumn, this.defaultValue.maxColumn, 1, 10000),
A
Alex Dima 已提交
1698 1699 1700 1701 1702 1703
		};
	}
}

//#endregion

A
Alex Dima 已提交
1704
//#region multiCursorModifier
A
Alex Dima 已提交
1705

A
Alex Dima 已提交
1706 1707 1708 1709 1710
function _multiCursorModifierFromString(multiCursorModifier: 'ctrlCmd' | 'alt'): 'altKey' | 'metaKey' | 'ctrlKey' {
	if (multiCursorModifier === 'ctrlCmd') {
		return (platform.isMacintosh ? 'metaKey' : 'ctrlKey');
	}
	return 'altKey';
A
Alex Dima 已提交
1711 1712
}

A
Alex Dima 已提交
1713 1714 1715 1716 1717 1718
//#endregion

//#region parameterHints

export type InternalParameterHintOptions = Readonly<Required<IEditorParameterHintOptions>>;

A
Alex Dima 已提交
1719 1720 1721 1722 1723 1724 1725
class EditorParameterHints<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorParameterHintOptions>> extends BaseEditorOption<K1, K2, InternalParameterHintOptions> {
	public validate(_input: any): InternalParameterHintOptions {
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as IEditorParameterHintOptions;
		return {
A
Alex Dima 已提交
1726 1727
			enabled: EditorBooleanOption.boolean(input.enabled, this.defaultValue.enabled),
			cycle: EditorBooleanOption.boolean(input.cycle, this.defaultValue.cycle)
A
Alex Dima 已提交
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759
		};
	}
}

//#endregion

//#region pixelRatio

class EditorPixelRatio<K1 extends EditorOption> extends ComputedEditorOption<K1, number> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: number): number {
		return env.pixelRatio;
	}
}

//#endregion

//#region quickSuggestions

export type ValidQuickSuggestionsOptions = boolean | Readonly<Required<IQuickSuggestionsOptions>>;

class EditorQuickSuggestions<K1 extends EditorOption, K2 extends PossibleKeyName<boolean | IQuickSuggestionsOptions>> extends BaseEditorOption<K1, K2, ValidQuickSuggestionsOptions> {
	public readonly defaultValue: Readonly<Required<IQuickSuggestionsOptions>>;
	constructor(id: K1, name: K2, defaultValue: Readonly<Required<IQuickSuggestionsOptions>>) {
		super(id, name, defaultValue);
	}
	public validate(_input: any): ValidQuickSuggestionsOptions {
		if (typeof _input === 'boolean') {
			return _input;
		}
		if (typeof _input === 'object') {
			const input = _input as IQuickSuggestionsOptions;
			return {
A
Alex Dima 已提交
1760 1761 1762
				other: EditorBooleanOption.boolean(input.other, this.defaultValue.other),
				comments: EditorBooleanOption.boolean(input.comments, this.defaultValue.comments),
				strings: EditorBooleanOption.boolean(input.strings, this.defaultValue.strings),
A
Alex Dima 已提交
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
			};
		}
		return this.defaultValue;
	}
}

//#endregion

//#region renderLineNumbers

export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string);

export const enum RenderLineNumbersType {
	Off = 0,
	On = 1,
	Relative = 2,
	Interval = 3,
	Custom = 4
}

export interface InternalEditorRenderLineNumbersOptions {
	readonly renderType: RenderLineNumbersType;
	readonly renderFn: ((lineNumber: number) => string) | null;
}

class EditorRenderLineNumbersOption<K1 extends EditorOption, K2 extends PossibleKeyName<LineNumbersType>> extends BaseEditorOption<K1, K2, InternalEditorRenderLineNumbersOptions> {
	public validate(lineNumbers: any): InternalEditorRenderLineNumbersOptions {
		let renderType: RenderLineNumbersType = this.defaultValue.renderType;
		let renderFn: ((lineNumber: number) => string) | null = this.defaultValue.renderFn;

		if (typeof lineNumbers !== 'undefined') {
			if (typeof lineNumbers === 'function') {
				renderType = RenderLineNumbersType.Custom;
				renderFn = lineNumbers;
			} else if (lineNumbers === 'interval') {
				renderType = RenderLineNumbersType.Interval;
			} else if (lineNumbers === 'relative') {
				renderType = RenderLineNumbersType.Relative;
			} else if (lineNumbers === 'on') {
				renderType = RenderLineNumbersType.On;
			} else {
				renderType = RenderLineNumbersType.Off;
			}
		}

		return {
			renderType,
			renderFn
		};
	}
}

//#endregion

//#region rulers

class EditorRulers<K1 extends EditorOption> extends SimpleEditorOption<K1, number[]> {
	public validate(input: any): number[] {
		if (Array.isArray(input)) {
			let rulers: number[] = [];
			for (let value of input) {
A
Alex Dima 已提交
1824
				rulers.push(EditorIntOption.clampedInt(value, 0, 0, 10000));
A
Alex Dima 已提交
1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850
			}
			rulers.sort();
			return rulers;
		}
		return this.defaultValue;
	}
}

//#endregion

//#region scrollbar

export interface InternalEditorScrollbarOptions {
	readonly arrowSize: number;
	readonly vertical: ScrollbarVisibility;
	readonly horizontal: ScrollbarVisibility;
	readonly useShadows: boolean;
	readonly verticalHasArrows: boolean;
	readonly horizontalHasArrows: boolean;
	readonly handleMouseWheel: boolean;
	readonly horizontalScrollbarSize: number;
	readonly horizontalSliderSize: number;
	readonly verticalScrollbarSize: number;
	readonly verticalSliderSize: number;
}

A
Alex Dima 已提交
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861
function _scrollbarVisibilityFromString(visibility: string | undefined, defaultValue: ScrollbarVisibility): ScrollbarVisibility {
	if (typeof visibility !== 'string') {
		return defaultValue;
	}
	switch (visibility) {
		case 'hidden': return ScrollbarVisibility.Hidden;
		case 'visible': return ScrollbarVisibility.Visible;
		default: return ScrollbarVisibility.Auto;
	}
}

A
Alex Dima 已提交
1862 1863 1864 1865 1866 1867
class EditorScrollbar<K1 extends EditorOption, K2 extends PossibleKeyName<IEditorScrollbarOptions>> extends BaseEditorOption<K1, K2, InternalEditorScrollbarOptions> {
	public validate(_input: any): InternalEditorScrollbarOptions {
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as IEditorScrollbarOptions;
A
Alex Dima 已提交
1868 1869
		const horizontalScrollbarSize = EditorIntOption.clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000);
		const verticalScrollbarSize = EditorIntOption.clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000);
A
Alex Dima 已提交
1870
		return {
A
Alex Dima 已提交
1871
			arrowSize: EditorIntOption.clampedInt(input.arrowSize, this.defaultValue.arrowSize, 0, 1000),
A
Alex Dima 已提交
1872 1873
			vertical: _scrollbarVisibilityFromString(input.vertical, this.defaultValue.vertical),
			horizontal: _scrollbarVisibilityFromString(input.horizontal, this.defaultValue.horizontal),
A
Alex Dima 已提交
1874 1875 1876 1877
			useShadows: EditorBooleanOption.boolean(input.useShadows, this.defaultValue.useShadows),
			verticalHasArrows: EditorBooleanOption.boolean(input.verticalHasArrows, this.defaultValue.verticalHasArrows),
			horizontalHasArrows: EditorBooleanOption.boolean(input.horizontalHasArrows, this.defaultValue.horizontalHasArrows),
			handleMouseWheel: EditorBooleanOption.boolean(input.handleMouseWheel, this.defaultValue.handleMouseWheel),
A
Alex Dima 已提交
1878
			horizontalScrollbarSize: horizontalScrollbarSize,
A
Alex Dima 已提交
1879
			horizontalSliderSize: EditorIntOption.clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000),
A
Alex Dima 已提交
1880
			verticalScrollbarSize: verticalScrollbarSize,
A
Alex Dima 已提交
1881
			verticalSliderSize: EditorIntOption.clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000),
A
Alex Dima 已提交
1882 1883 1884 1885 1886 1887 1888 1889
		};
	}
}

//#endregion

//#region suggest

A
Alex Dima 已提交
1890
export type InternalSuggestOptions = Readonly<Required<ISuggestOptions>>;
A
Alex Dima 已提交
1891 1892 1893 1894 1895 1896 1897 1898

class EditorSuggest<K1 extends EditorOption, K2 extends PossibleKeyName<ISuggestOptions>> extends BaseEditorOption<K1, K2, InternalSuggestOptions> {
	public validate(_input: any): InternalSuggestOptions {
		if (typeof _input !== 'object') {
			return this.defaultValue;
		}
		const input = _input as ISuggestOptions;
		return {
A
Alex Dima 已提交
1899 1900 1901 1902 1903
			filterGraceful: EditorBooleanOption.boolean(input.filterGraceful, this.defaultValue.filterGraceful),
			snippetsPreventQuickSuggestions: EditorBooleanOption.boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful),
			localityBonus: EditorBooleanOption.boolean(input.localityBonus, this.defaultValue.localityBonus),
			shareSuggestSelections: EditorBooleanOption.boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections),
			showIcons: EditorBooleanOption.boolean(input.showIcons, this.defaultValue.showIcons),
A
Alex Dima 已提交
1904
			maxVisibleSuggestions: EditorIntOption.clampedInt(input.maxVisibleSuggestions, this.defaultValue.maxVisibleSuggestions, 1, 15),
A
Alex Dima 已提交
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
			filteredTypes: isObject(input.filteredTypes) ? input.filteredTypes : Object.create(null)
		};
	}
}

//#endregion

//#region tabFocusMode

class EditorTabFocusMode<K1 extends EditorOption> extends ComputedEditorOption<K1, boolean> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: boolean): boolean {
		const readOnly = options.get(EditorOption.readOnly);
		return (readOnly ? true : env.tabFocusMode);
	}
}

//#endregion

//#region wrappingIndent

/**
 * Describes how to indent wrapped lines.
 */
export const enum WrappingIndent {
	/**
	 * No indentation => wrapped lines begin at column 1.
	 */
	None = 0,
	/**
	 * Same => wrapped lines get the same indentation as the parent.
	 */
	Same = 1,
	/**
	 * Indent => wrapped lines get +1 indentation toward the parent.
	 */
	Indent = 2,
	/**
	 * DeepIndent => wrapped lines get +2 indentation toward the parent.
	 */
	DeepIndent = 3
}

function _wrappingIndentFromString(wrappingIndent: 'none' | 'same' | 'indent' | 'deepIndent'): WrappingIndent {
	switch (wrappingIndent) {
		case 'none': return WrappingIndent.None;
		case 'same': return WrappingIndent.Same;
		case 'indent': return WrappingIndent.Indent;
		case 'deepIndent': return WrappingIndent.DeepIndent;
	}
}

//#endregion

A
Alex Dima 已提交
1958 1959 1960 1961 1962 1963 1964 1965 1966
//#region wrappingInfo

export interface EditorWrappingInfo {
	readonly isDominatedByLongLines: boolean;
	readonly isWordWrapMinified: boolean;
	readonly isViewportWrapping: boolean;
	readonly wrappingColumn: number;
}

A
Alex Dima 已提交
1967 1968
class EditorWrappingInfoComputer<K1 extends EditorOption> extends ComputedEditorOption<K1, EditorWrappingInfo> {
	public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: EditorWrappingInfo): EditorWrappingInfo {
A
renames  
Alex Dima 已提交
1969 1970 1971 1972 1973
		const wordWrap = options.get(EditorOption.wordWrap);
		const wordWrapColumn = options.get(EditorOption.wordWrapColumn);
		const wordWrapMinified = options.get(EditorOption.wordWrapMinified);
		const layoutInfo = options.get(EditorOption.layoutInfo);
		const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
A
Alex Dima 已提交
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031

		let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null;
		{
			if (accessibilitySupport === AccessibilitySupport.Enabled) {
				// See https://github.com/Microsoft/vscode/issues/27766
				// Never enable wrapping when a screen reader is attached
				// because arrow down etc. will not move the cursor in the way
				// a screen reader expects.
				bareWrappingInfo = {
					isWordWrapMinified: false,
					isViewportWrapping: false,
					wrappingColumn: -1
				};
			} else if (wordWrapMinified && env.isDominatedByLongLines) {
				// Force viewport width wrapping if model is dominated by long lines
				bareWrappingInfo = {
					isWordWrapMinified: true,
					isViewportWrapping: true,
					wrappingColumn: Math.max(1, layoutInfo.viewportColumn)
				};
			} else if (wordWrap === 'on') {
				bareWrappingInfo = {
					isWordWrapMinified: false,
					isViewportWrapping: true,
					wrappingColumn: Math.max(1, layoutInfo.viewportColumn)
				};
			} else if (wordWrap === 'bounded') {
				bareWrappingInfo = {
					isWordWrapMinified: false,
					isViewportWrapping: true,
					wrappingColumn: Math.min(Math.max(1, layoutInfo.viewportColumn), wordWrapColumn)
				};
			} else if (wordWrap === 'wordWrapColumn') {
				bareWrappingInfo = {
					isWordWrapMinified: false,
					isViewportWrapping: false,
					wrappingColumn: wordWrapColumn
				};
			} else {
				bareWrappingInfo = {
					isWordWrapMinified: false,
					isViewportWrapping: false,
					wrappingColumn: -1
				};
			}
		}

		return {
			isDominatedByLongLines: env.isDominatedByLongLines,
			isWordWrapMinified: bareWrappingInfo.isWordWrapMinified,
			isViewportWrapping: bareWrappingInfo.isViewportWrapping,
			wrappingColumn: bareWrappingInfo.wrappingColumn,
		};
	}
}

//#endregion

A
Alex Dima 已提交
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062
const DEFAULT_WINDOWS_FONT_FAMILY = 'Consolas, \'Courier New\', monospace';
const DEFAULT_MAC_FONT_FAMILY = 'Menlo, Monaco, \'Courier New\', monospace';
const DEFAULT_LINUX_FONT_FAMILY = '\'Droid Sans Mono\', \'monospace\', monospace, \'Droid Sans Fallback\'';

/**
 * @internal
 */
export const EDITOR_FONT_DEFAULTS = {
	fontFamily: (
		platform.isMacintosh ? DEFAULT_MAC_FONT_FAMILY : (platform.isLinux ? DEFAULT_LINUX_FONT_FAMILY : DEFAULT_WINDOWS_FONT_FAMILY)
	),
	fontWeight: 'normal',
	fontSize: (
		platform.isMacintosh ? 12 : 14
	),
	lineHeight: 0,
	letterSpacing: 0,
};

/**
 * @internal
 */
export const EDITOR_MODEL_DEFAULTS = {
	tabSize: 4,
	indentSize: 4,
	insertSpaces: true,
	detectIndentation: true,
	trimAutoWhitespace: true,
	largeFileOptimizations: true
};

A
Alex Dima 已提交
2063 2064 2065 2066 2067
/**
 * @internal
 */
export const editorOptionsRegistry: IEditorOption<EditorOption, any>[] = [];

2068
function register<K1 extends EditorOption, V>(option: IEditorOption<K1, V>): IEditorOption<K1, V> {
A
Alex Dima 已提交
2069 2070 2071 2072
	editorOptionsRegistry[option.id] = option;
	return option;
}

A
renames  
Alex Dima 已提交
2073
export const enum EditorOption {
A
Alex Dima 已提交
2074 2075
	acceptSuggestionOnCommitCharacter,
	acceptSuggestionOnEnter,
A
Alex Dima 已提交
2076
	accessibilitySupport,
A
Alex Dima 已提交
2077 2078 2079 2080 2081 2082
	autoClosingBrackets,
	autoClosingOvertype,
	autoClosingQuotes,
	autoIndent,
	automaticLayout,
	autoSurround,
A
Alex Dima 已提交
2083 2084 2085
	codeLens,
	colorDecorators,
	contextmenu,
A
Alex Dima 已提交
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095
	copyWithSyntaxHighlighting,
	cursorBlinking,
	cursorSmoothCaretAnimation,
	cursorStyle,
	cursorSurroundingLines,
	cursorWidth,
	disableLayerHinting,
	dragAndDrop,
	emptySelectionClipboard,
	extraEditorClassName,
A
Alex Dima 已提交
2096
	fastScrollSensitivity,
A
Alex Dima 已提交
2097
	find,
A
Alex Dima 已提交
2098
	fixedOverflowWidgets,
A
Alex Dima 已提交
2099
	folding,
A
Alex Dima 已提交
2100
	foldingStrategy,
2101 2102
	fontFamily,
	fontInfo,
A
Alex Dima 已提交
2103
	fontLigatures,
2104 2105
	fontSize,
	fontWeight,
A
Alex Dima 已提交
2106 2107
	formatOnPaste,
	formatOnType,
A
Alex Dima 已提交
2108
	glyphMargin,
A
Alex Dima 已提交
2109
	gotoLocation,
A
Alex Dima 已提交
2110 2111
	hideCursorInOverviewRuler,
	highlightActiveIndentGuide,
A
Alex Dima 已提交
2112
	hover,
A
Alex Dima 已提交
2113
	inDiffEditor,
2114
	letterSpacing,
A
Alex Dima 已提交
2115
	lightbulb,
A
Alex Dima 已提交
2116
	lineDecorationsWidth,
A
Alex Dima 已提交
2117
	lineHeight,
A
Alex Dima 已提交
2118
	lineNumbers,
A
Alex Dima 已提交
2119
	lineNumbersMinChars,
A
Alex Dima 已提交
2120 2121
	links,
	matchBrackets,
A
Alex Dima 已提交
2122
	minimap,
A
Alex Dima 已提交
2123
	mouseStyle,
A
Alex Dima 已提交
2124
	mouseWheelScrollSensitivity,
A
Alex Dima 已提交
2125 2126 2127
	mouseWheelZoom,
	multiCursorMergeOverlapping,
	multiCursorModifier,
A
Alex Dima 已提交
2128
	occurrencesHighlight,
A
Alex Dima 已提交
2129 2130
	overviewRulerBorder,
	overviewRulerLanes,
A
Alex Dima 已提交
2131 2132
	parameterHints,
	quickSuggestions,
A
Alex Dima 已提交
2133
	quickSuggestionsDelay,
2134
	readOnly,
A
Alex Dima 已提交
2135 2136
	renderControlCharacters,
	renderIndentGuides,
A
Alex Dima 已提交
2137
	renderFinalNewline,
A
Alex Dima 已提交
2138 2139 2140 2141 2142
	renderLineHighlight,
	renderWhitespace,
	revealHorizontalRightPadding,
	roundedSelection,
	rulers,
A
Alex Dima 已提交
2143
	scrollbar,
A
Alex Dima 已提交
2144 2145
	scrollBeyondLastColumn,
	scrollBeyondLastLine,
A
Alex Dima 已提交
2146
	selectionClipboard,
A
Alex Dima 已提交
2147
	selectionHighlight,
A
Alex Dima 已提交
2148
	selectOnLineNumbers,
A
Alex Dima 已提交
2149
	showFoldingControls,
A
Alex Dima 已提交
2150
	showUnused,
A
Alex Dima 已提交
2151
	snippetSuggestions,
A
Alex Dima 已提交
2152 2153
	smoothScrolling,
	stopRenderingLineAfter,
A
Alex Dima 已提交
2154
	suggest,
A
Alex Dima 已提交
2155 2156
	suggestFontSize,
	suggestLineHeight,
A
Alex Dima 已提交
2157
	suggestOnTriggerCharacters,
A
Alex Dima 已提交
2158 2159
	suggestSelection,
	tabCompletion,
A
Alex Dima 已提交
2160 2161
	useTabStops,
	wordSeparators,
A
Alex Dima 已提交
2162 2163 2164 2165 2166 2167 2168 2169
	wordWrap,
	wordWrapBreakAfterCharacters,
	wordWrapBreakBeforeCharacters,
	wordWrapBreakObtrusiveCharacters,
	wordWrapColumn,
	wordWrapMinified,
	wrappingIndent,

A
Alex Dima 已提交
2170
	// Leave these at the end (because they have dependencies!)
A
Alex Dima 已提交
2171 2172 2173
	ariaLabel,
	disableMonospaceOptimizations,
	editorClassName,
A
Alex Dima 已提交
2174
	pixelRatio,
A
Alex Dima 已提交
2175
	tabFocusMode,
A
Alex Dima 已提交
2176 2177
	layoutInfo,
	wrappingInfo,
2178 2179
}

A
renames  
Alex Dima 已提交
2180
export const EditorOptions = {
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231
	acceptSuggestionOnCommitCharacter: register(new EditorBooleanOption(
		EditorOption.acceptSuggestionOnCommitCharacter, 'acceptSuggestionOnCommitCharacter', true,
		{ markdownDescription: nls.localize('acceptSuggestionOnCommitCharacter', "Controls whether suggestions should be accepted on commit characters. For example, in JavaScript, the semi-colon (`;`) can be a commit character that accepts a suggestion and types that character.") }
	)),
	acceptSuggestionOnEnter: register(new EditorStringEnumOption(EditorOption.acceptSuggestionOnEnter, 'acceptSuggestionOnEnter', 'on' as 'on' | 'smart' | 'off', ['on', 'smart', 'off'] as const)),
	accessibilitySupport: register(new EditorAccessibilitySupportOption(EditorOption.accessibilitySupport, 'accessibilitySupport', AccessibilitySupport.Unknown)),
	autoClosingBrackets: register(new EditorStringEnumOption(EditorOption.autoClosingBrackets, 'autoClosingBrackets', 'languageDefined' as 'always' | 'languageDefined' | 'beforeWhitespace' | 'never', ['always', 'languageDefined', 'beforeWhitespace', 'never'] as const)),
	autoClosingOvertype: register(new EditorStringEnumOption(EditorOption.autoClosingOvertype, 'autoClosingOvertype', 'auto' as 'always' | 'auto' | 'never', ['always', 'auto', 'never'] as const)),
	autoClosingQuotes: register(new EditorStringEnumOption(EditorOption.autoClosingQuotes, 'autoClosingQuotes', 'languageDefined' as 'always' | 'languageDefined' | 'beforeWhitespace' | 'never', ['always', 'languageDefined', 'beforeWhitespace', 'never'] as const)),
	autoIndent: register(new EditorBooleanOption(
		EditorOption.autoIndent, 'autoIndent', true,
		{ description: nls.localize('autoIndent', "Controls whether the editor should automatically adjust the indentation when users type, paste or move lines. Extensions with indentation rules of the language must be available.") }
	)),
	automaticLayout: register(new EditorBooleanOption(
		EditorOption.automaticLayout, 'automaticLayout', false,
	)),
	autoSurround: register(new EditorStringEnumOption(EditorOption.autoSurround, 'autoSurround', 'languageDefined' as 'languageDefined' | 'quotes' | 'brackets' | 'never', ['languageDefined', 'quotes', 'brackets', 'never'] as const)),
	codeLens: register(new EditorBooleanOption(
		EditorOption.codeLens, 'codeLens', true,
		{ description: nls.localize('codeLens', "Controls whether the editor shows CodeLens.") }
	)),
	colorDecorators: register(new EditorBooleanOption(
		EditorOption.colorDecorators, 'colorDecorators', true,
		{ description: nls.localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") }
	)),
	contextmenu: register(new EditorBooleanOption(
		EditorOption.contextmenu, 'contextmenu', true,
	)),
	copyWithSyntaxHighlighting: register(new EditorBooleanOption(
		EditorOption.copyWithSyntaxHighlighting, 'copyWithSyntaxHighlighting', true,
		{ description: nls.localize('copyWithSyntaxHighlighting', "Controls whether syntax highlighting should be copied into the clipboard.") }
	)),
	cursorBlinking: register(new EditorEnumOption(EditorOption.cursorBlinking, 'cursorBlinking', TextEditorCursorBlinkingStyle.Blink, ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString)),
	cursorSmoothCaretAnimation: register(new EditorBooleanOption(
		EditorOption.cursorSmoothCaretAnimation, 'cursorSmoothCaretAnimation', false,
		{ description: nls.localize('cursorSmoothCaretAnimation', "Controls whether the smooth caret animation should be enabled.") }
	)),
	cursorStyle: register(new EditorEnumOption(EditorOption.cursorStyle, 'cursorStyle', TextEditorCursorStyle.Line, ['line', 'block', 'underline', 'line-thin', 'block-outline', 'underline-thin'], _cursorStyleFromString)),
	cursorSurroundingLines: register(new EditorIntOption(EditorOption.cursorSurroundingLines, 'cursorSurroundingLines', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)),
	cursorWidth: register(new EditorIntOption(EditorOption.cursorWidth, 'cursorWidth', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)),
	disableLayerHinting: register(new EditorBooleanOption(
		EditorOption.disableLayerHinting, 'disableLayerHinting', false,
	)),
	dragAndDrop: register(new EditorBooleanOption(
		EditorOption.dragAndDrop, 'dragAndDrop', true,
		{ description: nls.localize('dragAndDrop', "Controls whether the editor should allow moving selections via drag and drop.") }
	)),
	emptySelectionClipboard: register(new EditorEmptySelectionClipboard(EditorOption.emptySelectionClipboard, 'emptySelectionClipboard', true)),
	extraEditorClassName: register(new EditorStringOption(EditorOption.extraEditorClassName, 'extraEditorClassName', '')),
	fastScrollSensitivity: register(new EditorFloatOption(EditorOption.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))),
	find: register(new EditorFind(EditorOption.find, 'find', {
A
Alex Dima 已提交
2232 2233 2234 2235 2236
		seedSearchStringFromSelection: true,
		autoFindInSelection: false,
		globalFindClipboard: false,
		addExtraSpaceOnTop: true
	})),
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
	fixedOverflowWidgets: register(new EditorBooleanOption(
		EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false,
	)),
	folding: register(new EditorBooleanOption(
		EditorOption.folding, 'folding', true,
		{ description: nls.localize('folding', "Controls whether the editor has code folding enabled.") }
	)),
	foldingStrategy: register(new EditorStringEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto' as 'auto' | 'indentation', ['auto', 'indentation'] as const)),
	fontFamily: register(new EditorStringOption(EditorOption.fontFamily, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily)),
	fontInfo: register(new EditorFontInfo(EditorOption.fontInfo)),
	fontLigatures: register(new EditorBooleanOption(
		EditorOption.fontLigatures, 'fontLigatures', false,
		{ description: nls.localize('fontLigatures', "Enables/Disables font ligatures.") }
	)),
	fontSize: register(new EditorFontSize(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize)),
	fontWeight: register(new EditorStringOption(EditorOption.fontWeight, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight)),
	formatOnPaste: register(new EditorBooleanOption(
		EditorOption.formatOnPaste, 'formatOnPaste', false,
		{ description: nls.localize('formatOnPaste', "Controls whether 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.") }
	)),
	formatOnType: register(new EditorBooleanOption(
		EditorOption.formatOnType, 'formatOnType', false,
		{ description: nls.localize('formatOnType', "Controls whether the editor should automatically format the line after typing.") }
	)),
	glyphMargin: register(new EditorBooleanOption(
		EditorOption.glyphMargin, 'glyphMargin', true,
		{ description: nls.localize('glyphMargin', "Controls whether the editor should render the vertical glyph margin. Glyph margin is mostly used for debugging.") }
	)),
	gotoLocation: register(new EditorGoToLocation(EditorOption.gotoLocation, 'gotoLocation', {
A
Alex Dima 已提交
2266 2267
		multiple: 'peek'
	})),
2268 2269 2270 2271 2272 2273 2274 2275 2276
	hideCursorInOverviewRuler: register(new EditorBooleanOption(
		EditorOption.hideCursorInOverviewRuler, 'hideCursorInOverviewRuler', false,
		{ description: nls.localize('hideCursorInOverviewRuler', "Controls whether the cursor should be hidden in the overview ruler.") }
	)),
	highlightActiveIndentGuide: register(new EditorBooleanOption(
		EditorOption.highlightActiveIndentGuide, 'highlightActiveIndentGuide', true,
		{ description: nls.localize('highlightActiveIndentGuide', "Controls whether the editor should highlight the active indent guide.") }
	)),
	hover: register(new EditorHover(EditorOption.hover, 'hover', {
A
Alex Dima 已提交
2277 2278 2279 2280
		enabled: true,
		delay: 300,
		sticky: true
	})),
2281 2282 2283 2284 2285
	inDiffEditor: register(new EditorBooleanOption(
		EditorOption.inDiffEditor, 'inDiffEditor', false,
	)),
	letterSpacing: register(new EditorFloatOption(EditorOption.letterSpacing, 'letterSpacing', EDITOR_FONT_DEFAULTS.letterSpacing, x => EditorFloatOption.clamp(x, -5, 20))),
	lightbulb: register(new EditorLightbulb(EditorOption.lightbulb, 'lightbulb', {
A
Alex Dima 已提交
2286 2287
		enabled: true
	})),
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
	lineDecorationsWidth: register(new SimpleEditorOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10 as number | string)),
	lineHeight: register(new EditorLineHeight(EditorOption.lineHeight, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight, 0, 150)),
	lineNumbers: register(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })),
	lineNumbersMinChars: register(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)),
	links: register(new EditorBooleanOption(
		EditorOption.links, 'links', true,
		{ description: nls.localize('links', "Controls whether the editor should detect links and make them clickable.") }
	)),
	matchBrackets: register(new EditorBooleanOption(
		EditorOption.matchBrackets, 'matchBrackets', true,
		{ description: nls.localize('matchBrackets', "Highlight matching brackets when one of them is selected.") }
	)),
	minimap: register(new EditorMinimap(EditorOption.minimap, 'minimap', {
A
Alex Dima 已提交
2301 2302 2303 2304 2305 2306
		enabled: true,
		side: 'right',
		showSlider: 'mouseover',
		renderCharacters: true,
		maxColumn: 120,
	})),
2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
	mouseStyle: register(new EditorStringEnumOption(EditorOption.mouseStyle, 'mouseStyle', 'text' as 'text' | 'default' | 'copy', ['text', 'default', 'copy'] as const)),
	mouseWheelScrollSensitivity: register(new EditorFloatOption(EditorOption.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))),
	mouseWheelZoom: register(new EditorBooleanOption(
		EditorOption.mouseWheelZoom, 'mouseWheelZoom', false,
		{ markdownDescription: nls.localize('mouseWheelZoom', "Zoom the font of the editor when using mouse wheel and holding `Ctrl`.") }
	)),
	multiCursorMergeOverlapping: register(new EditorBooleanOption(
		EditorOption.multiCursorMergeOverlapping, 'multiCursorMergeOverlapping', true,
		{ description: nls.localize('multiCursorMergeOverlapping', "Merge multiple cursors when they are overlapping.") }
	)),
	multiCursorModifier: register(new EditorEnumOption(EditorOption.multiCursorModifier, 'multiCursorModifier', 'altKey', ['ctrlCmd', 'alt'], _multiCursorModifierFromString)),
	occurrencesHighlight: register(new EditorBooleanOption(
		EditorOption.occurrencesHighlight, 'occurrencesHighlight', true,
		{ description: nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }
	)),
	overviewRulerBorder: register(new EditorBooleanOption(
		EditorOption.overviewRulerBorder, 'overviewRulerBorder', true,
		{ description: nls.localize('overviewRulerBorder', "Controls whether a border should be drawn around the overview ruler.") }
	)),
	overviewRulerLanes: register(new EditorIntOption(EditorOption.overviewRulerLanes, 'overviewRulerLanes', 2, 0, 3)),
	parameterHints: register(new EditorParameterHints(EditorOption.parameterHints, 'parameterHints', {
A
Alex Dima 已提交
2328 2329 2330
		enabled: true,
		cycle: false
	})),
2331
	quickSuggestions: register(new EditorQuickSuggestions(EditorOption.quickSuggestions, 'quickSuggestions', {
A
Alex Dima 已提交
2332 2333 2334 2335
		other: true,
		comments: false,
		strings: false
	})),
2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360
	quickSuggestionsDelay: register(new EditorIntOption(EditorOption.quickSuggestionsDelay, 'quickSuggestionsDelay', 10, 0, Constants.MAX_SAFE_SMALL_INTEGER)),
	readOnly: register(new EditorBooleanOption(
		EditorOption.readOnly, 'readOnly', false,
	)),
	renderControlCharacters: register(new EditorBooleanOption(
		EditorOption.renderControlCharacters, 'renderControlCharacters', false,
		{ description: nls.localize('renderControlCharacters', "Controls whether the editor should render control characters.") }
	)),
	renderIndentGuides: register(new EditorBooleanOption(
		EditorOption.renderIndentGuides, 'renderIndentGuides', true,
		{ description: nls.localize('renderIndentGuides', "Controls whether the editor should render indent guides.") }
	)),
	renderFinalNewline: register(new EditorBooleanOption(
		EditorOption.renderFinalNewline, 'renderFinalNewline', true,
		{ description: nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }
	)),
	renderLineHighlight: register(new EditorStringEnumOption(EditorOption.renderLineHighlight, 'renderLineHighlight', 'line' as 'none' | 'gutter' | 'line' | 'all', ['none', 'gutter', 'line', 'all'] as const)),
	renderWhitespace: register(new EditorStringEnumOption(EditorOption.renderWhitespace, 'renderWhitespace', 'none' as 'none' | 'boundary' | 'selection' | 'all', ['none', 'boundary', 'selection', 'all'] as const)),
	revealHorizontalRightPadding: register(new EditorIntOption(EditorOption.revealHorizontalRightPadding, 'revealHorizontalRightPadding', 30, 0, 1000)),
	roundedSelection: register(new EditorBooleanOption(
		EditorOption.roundedSelection, 'roundedSelection', true,
		{ description: nls.localize('roundedSelection', "Controls whether selections should have rounded corners.") }
	)),
	rulers: register(new EditorRulers(EditorOption.rulers, 'rulers', [])),
	scrollbar: register(new EditorScrollbar(EditorOption.scrollbar, 'scrollbar', {
A
Alex Dima 已提交
2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372
		vertical: ScrollbarVisibility.Auto,
		horizontal: ScrollbarVisibility.Auto,
		arrowSize: 11,
		useShadows: true,
		verticalHasArrows: false,
		horizontalHasArrows: false,
		horizontalScrollbarSize: 10,
		horizontalSliderSize: 10,
		verticalScrollbarSize: 14,
		verticalSliderSize: 14,
		handleMouseWheel: true,
	})),
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403
	scrollBeyondLastColumn: register(new EditorIntOption(EditorOption.scrollBeyondLastColumn, 'scrollBeyondLastColumn', 5, 0, Constants.MAX_SAFE_SMALL_INTEGER)),
	scrollBeyondLastLine: register(new EditorBooleanOption(
		EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true,
		{ description: nls.localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") }
	)),
	selectionClipboard: register(new EditorBooleanOption(
		EditorOption.selectionClipboard, 'selectionClipboard', true,
		{
			description: nls.localize('selectionClipboard', "Controls whether the Linux primary clipboard should be supported."),
			included: platform.isLinux
		}
	)),
	selectionHighlight: register(new EditorBooleanOption(
		EditorOption.selectionHighlight, 'selectionHighlight', true,
		{ description: nls.localize('selectionHighlight', "Controls whether the editor should highlight matches similar to the selection.") }
	)),
	selectOnLineNumbers: register(new EditorBooleanOption(
		EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true,
	)),
	showFoldingControls: register(new EditorStringEnumOption(EditorOption.showFoldingControls, 'showFoldingControls', 'mouseover' as 'always' | 'mouseover', ['always', 'mouseover'] as const)),
	showUnused: register(new EditorBooleanOption(
		EditorOption.showUnused, 'showUnused', true,
		{ description: nls.localize('showUnused', "Controls fading out of unused code.") }
	)),
	snippetSuggestions: register(new EditorStringEnumOption(EditorOption.snippetSuggestions, 'snippetSuggestions', 'inline' as 'top' | 'bottom' | 'inline' | 'none', ['top', 'bottom', 'inline', 'none'] as const)),
	smoothScrolling: register(new EditorBooleanOption(
		EditorOption.smoothScrolling, 'smoothScrolling', false,
		{ description: nls.localize('smoothScrolling', "Controls whether the editor will scroll using an animation.") }
	)),
	stopRenderingLineAfter: register(new EditorIntOption(EditorOption.stopRenderingLineAfter, 'stopRenderingLineAfter', 10000, -1, Constants.MAX_SAFE_SMALL_INTEGER)),
	suggest: register(new EditorSuggest(EditorOption.suggest, 'suggest', {
A
Alex Dima 已提交
2404 2405 2406 2407 2408 2409 2410 2411
		filterGraceful: true,
		snippetsPreventQuickSuggestions: true,
		localityBonus: false,
		shareSuggestSelections: false,
		showIcons: true,
		maxVisibleSuggestions: 12,
		filteredTypes: Object.create(null)
	})),
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433
	suggestFontSize: register(new EditorIntOption(EditorOption.suggestFontSize, 'suggestFontSize', 0, 0, 1000)),
	suggestLineHeight: register(new EditorIntOption(EditorOption.suggestLineHeight, 'suggestLineHeight', 0, 0, 1000)),
	suggestOnTriggerCharacters: register(new EditorBooleanOption(
		EditorOption.suggestOnTriggerCharacters, 'suggestOnTriggerCharacters', true,
		{ description: nls.localize('suggestOnTriggerCharacters', "Controls whether suggestions should automatically show up when typing trigger characters.") }
	)),
	suggestSelection: register(new EditorStringEnumOption(EditorOption.suggestSelection, 'suggestSelection', 'recentlyUsed' as 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix', ['first', 'recentlyUsed', 'recentlyUsedByPrefix'] as const)),
	tabCompletion: register(new EditorStringEnumOption(EditorOption.tabCompletion, 'tabCompletion', 'off' as 'on' | 'off' | 'onlySnippets', ['on', 'off', 'onlySnippets'] as const)),
	useTabStops: register(new EditorBooleanOption(
		EditorOption.useTabStops, 'useTabStops', true,
		{ description: nls.localize('useTabStops', "Inserting and deleting whitespace follows tab stops.") }
	)),
	wordSeparators: register(new EditorStringOption(EditorOption.wordSeparators, 'wordSeparators', USUAL_WORD_SEPARATORS)),
	wordWrap: register(new EditorStringEnumOption(EditorOption.wordWrap, 'wordWrap', 'off' as 'off' | 'on' | 'wordWrapColumn' | 'bounded', ['off', 'on', 'wordWrapColumn', 'bounded'] as const)),
	wordWrapBreakAfterCharacters: register(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')),
	wordWrapBreakBeforeCharacters: register(new EditorStringOption(EditorOption.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')),
	wordWrapBreakObtrusiveCharacters: register(new EditorStringOption(EditorOption.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')),
	wordWrapColumn: register(new EditorIntOption(EditorOption.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)),
	wordWrapMinified: register(new EditorBooleanOption(
		EditorOption.wordWrapMinified, 'wordWrapMinified', true,
	)),
	wrappingIndent: register(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', WrappingIndent.Same, ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)),
A
Alex Dima 已提交
2434

A
Alex Dima 已提交
2435
	// Leave these at the end (because they have dependencies!)
2436 2437 2438 2439 2440 2441 2442 2443
	ariaLabel: register(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), undefined, [EditorOption.accessibilitySupport])),
	disableMonospaceOptimizations: register(new EditorDisableMonospaceOptimizations(EditorOption.disableMonospaceOptimizations, 'disableMonospaceOptimizations', false, undefined, [EditorOption.fontLigatures])),
	editorClassName: register(new EditorClassName(EditorOption.editorClassName, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])),
	pixelRatio: register(new EditorPixelRatio(EditorOption.pixelRatio)),
	tabFocusMode: register(new EditorTabFocusMode(EditorOption.tabFocusMode, [EditorOption.readOnly])),

	layoutInfo: register(new EditorLayoutInfoComputer(EditorOption.layoutInfo, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers])),
	wrappingInfo: register(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])),
2444
};
A
Alex Dima 已提交
2445

A
Alex Dima 已提交
2446 2447 2448
type EditorOptionsType = typeof EditorOptions;
type FindEditorOptionsKeyById<T extends EditorOption> = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType];
type ComputedEditorOptionValue<T extends IEditorOption<any, any>> = T extends IEditorOption<any, infer R> ? R : never;
2449
export type FindComputedEditorOptionValueById<T extends EditorOption> = NonNullable<ComputedEditorOptionValue<EditorOptionsType[FindEditorOptionsKeyById<T>]>>;