From 46f6387119a600b0dde862ce2a7c7da958acc1e1 Mon Sep 17 00:00:00 2001 From: jeanp413 Date: Sun, 11 Aug 2019 15:22:25 -0500 Subject: [PATCH 001/109] Fix explorer edit item. Fixes #78153 --- .../contrib/files/browser/fileActions.ts | 7 ++-- .../files/browser/views/explorerView.ts | 35 +++++++++++++------ .../files/browser/views/explorerViewer.ts | 35 ++++++------------- .../contrib/files/common/explorerService.ts | 4 +++ .../workbench/contrib/files/common/files.ts | 1 + 5 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index cb9ac033e43..721c4279503 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -858,7 +858,7 @@ async function openExplorerAndCreate(accessor: ServicesAccessor, isFolder: boole folder.addChild(newStat); - const onSuccess = async (value: string) => { + const onSuccess = (value: string): Promise => { const createPromise = isFolder ? fileService.createFolder(resources.joinPath(folder.resource, value)) : textFileService.create(resources.joinPath(folder.resource, value)); return createPromise.then(created => { refreshIfSeparator(value, explorerService); @@ -877,7 +877,10 @@ async function openExplorerAndCreate(accessor: ServicesAccessor, isFolder: boole if (success) { onSuccess(value); } else { - explorerService.select(folder.resource).then(undefined, onUnexpectedError); + // Fixes #78153 + setTimeout(() => { + explorerService.select(folder.resource).then(undefined, onUnexpectedError); + }, 0); } } }); diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index f5a52355075..a1d60f3d6c0 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -6,7 +6,7 @@ import * as nls from 'vs/nls'; import { URI } from 'vs/base/common/uri'; import * as perf from 'vs/base/common/performance'; -import { Action, IAction, WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions'; +import { IAction, WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions'; import { memoize } from 'vs/base/common/decorators'; import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, IExplorerService, ExplorerResourceCut, ExplorerResourceMoveableToTrash } from 'vs/workbench/contrib/files/common/files'; import { NewFolderAction, NewFileAction, FileCopiedContext, RefreshExplorerView, CollapseExplorerView } from 'vs/workbench/contrib/files/browser/fileActions'; @@ -68,6 +68,7 @@ export class ExplorerView extends ViewletPanel { private shouldRefresh = true; private dragHandler!: DelayedDragHandler; private autoReveal = false; + private actions: IAction[] | undefined; constructor( options: IViewletPanelOptions, @@ -170,7 +171,12 @@ export class ExplorerView extends ViewletPanel { })); this._register(this.explorerService.onDidChangeRoots(() => this.setTreeInput())); - this._register(this.explorerService.onDidChangeItem(e => this.refresh(e.recursive, e.item))); + this._register(this.explorerService.onDidChangeItem(e => { + if (this.explorerService.isEditable(undefined)) { + this.tree.domFocus(); + } + this.refresh(e.recursive, e.item); + })); this._register(this.explorerService.onDidChangeEditable(async e => { const isEditing = !!this.explorerService.getEditableData(e); @@ -218,14 +224,16 @@ export class ExplorerView extends ViewletPanel { } getActions(): IAction[] { - const actions: Action[] = []; - - actions.push(this.instantiationService.createInstance(NewFileAction)); - actions.push(this.instantiationService.createInstance(NewFolderAction)); - actions.push(this.instantiationService.createInstance(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL)); - actions.push(this.instantiationService.createInstance(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL)); - - return actions; + if (!this.actions) { + this.actions = [ + this.instantiationService.createInstance(NewFileAction), + this.instantiationService.createInstance(NewFolderAction), + this.instantiationService.createInstance(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL), + this.instantiationService.createInstance(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL) + ]; + this.actions.forEach(a => this._register(a)); + } + return this.actions; } focus(): void { @@ -334,6 +342,13 @@ export class ExplorerView extends ViewletPanel { this._register(this.tree.onContextMenu(e => this.onContextMenu(e))); + this._register(this.tree.onDidScroll(e => { + let editable = this.explorerService.getEditable(); + if (editable && this.tree.getRelativeTop(editable.stat) === null) { + editable.data.onFinish('', false); + } + })); + // save view state on shutdown this._register(this.storageService.onWillSaveState(() => { this.storageService.store(ExplorerView.TREE_VIEW_STATE_STORAGE_KEY, JSON.stringify(this.tree.getViewState()), StorageScope.WORKSPACE); diff --git a/src/vs/workbench/contrib/files/browser/views/explorerViewer.ts b/src/vs/workbench/contrib/files/browser/views/explorerViewer.ts index a069bee3bf9..34030a89f5e 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerViewer.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerViewer.ts @@ -218,29 +218,21 @@ export class FilesRenderer implements ITreeRenderer 0 && !stat.isDirectory ? lastDot : value.length }); - let isFinishableDisposeEvent = false; - setTimeout(() => { - // Check if disposed - if (!inputBox.inputElement) { - return; - } - inputBox.focus(); - inputBox.select({ start: 0, end: lastDot > 0 && !stat.isDirectory ? lastDot : value.length }); - isFinishableDisposeEvent = true; - }, 0); - - const done = once(async (success: boolean) => { + const done = once((success: boolean, finishEditing: boolean) => { label.element.style.display = 'none'; const value = inputBox.value; dispose(toDispose); label.element.remove(); - // Timeout: once done rendering only then re-render #70902 - setTimeout(() => editableData.onFinish(value, success), 0); + if (finishEditing) { + editableData.onFinish(value, success); + } }); const blurDisposable = DOM.addDisposableListener(inputBox.inputElement, DOM.EventType.BLUR, () => { - done(inputBox.isInputValid()); + done(inputBox.isInputValid(), true); }); const toDispose = [ @@ -248,10 +240,10 @@ export class FilesRenderer implements ITreeRenderer { if (e.equals(KeyCode.Enter)) { if (inputBox.validate()) { - done(true); + done(true, true); } } else if (e.equals(KeyCode.Escape)) { - done(false); + done(false, true); } }), blurDisposable, @@ -260,13 +252,8 @@ export class FilesRenderer implements ITreeRenderer { - if (isFinishableDisposeEvent) { - done(false); - } - else { - dispose(toDispose); - label.element.remove(); - } + blurDisposable.dispose(); + done(false, false); }); } diff --git a/src/vs/workbench/contrib/files/common/explorerService.ts b/src/vs/workbench/contrib/files/common/explorerService.ts index 9d0f177a77a..e02ee801337 100644 --- a/src/vs/workbench/contrib/files/common/explorerService.ts +++ b/src/vs/workbench/contrib/files/common/explorerService.ts @@ -140,6 +140,10 @@ export class ExplorerService implements IExplorerService { return !!this.cutItems && this.cutItems.indexOf(item) >= 0; } + getEditable(): { stat: ExplorerItem, data: IEditableData } | undefined { + return this.editable; + } + getEditableData(stat: ExplorerItem): IEditableData | undefined { return this.editable && this.editable.stat === stat ? this.editable.data : undefined; } diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts index e60fda6cf31..0407af6c945 100644 --- a/src/vs/workbench/contrib/files/common/files.ts +++ b/src/vs/workbench/contrib/files/common/files.ts @@ -51,6 +51,7 @@ export interface IExplorerService { readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>; setEditable(stat: ExplorerItem, data: IEditableData | null): void; + getEditable(): { stat: ExplorerItem, data: IEditableData } | undefined; getEditableData(stat: ExplorerItem): IEditableData | undefined; // If undefined is passed checks if any element is currently being edited. isEditable(stat: ExplorerItem | undefined): boolean; From 8e86e739b8639df7fd8392ce7f9077f9b8af08e4 Mon Sep 17 00:00:00 2001 From: jeanp413 Date: Tue, 20 Aug 2019 20:46:32 -0500 Subject: [PATCH 002/109] Don't call explorerService.select --- src/vs/workbench/contrib/files/browser/fileActions.ts | 5 ----- src/vs/workbench/contrib/files/browser/views/explorerView.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/files/browser/fileActions.ts b/src/vs/workbench/contrib/files/browser/fileActions.ts index 98dabdb26d9..cb3afb6e658 100644 --- a/src/vs/workbench/contrib/files/browser/fileActions.ts +++ b/src/vs/workbench/contrib/files/browser/fileActions.ts @@ -943,11 +943,6 @@ async function openExplorerAndCreate(accessor: ServicesAccessor, isFolder: boole explorerService.setEditable(newStat, null); if (success) { onSuccess(value); - } else { - // Fixes #78153 - setTimeout(() => { - explorerService.select(folder.resource).then(undefined, onUnexpectedError); - }, 0); } } }); diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index d3ce45df70d..1db99b9724a 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -345,7 +345,7 @@ export class ExplorerView extends ViewletPanel { this._register(this.tree.onDidScroll(e => { let editable = this.explorerService.getEditable(); - if (editable && this.tree.getRelativeTop(editable.stat) === null) { + if (e.scrollTopChanged && editable && this.tree.getRelativeTop(editable.stat) === null) { editable.data.onFinish('', false); } })); From 2a720880c3bf5dd365c153a00a8042c89eea3775 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 30 Aug 2019 17:20:36 +0200 Subject: [PATCH 003/109] Introduce a new way to manage editor options --- .../viewParts/lineNumbers/lineNumbers.ts | 4 +- .../common/config/commonEditorConfig.ts | 82 ++++++++++- src/vs/editor/common/config/editorOptions.ts | 138 +++++++++++++++++- src/vs/editor/common/editorCommon.ts | 1 + .../common/standalone/standaloneEnums.ts | 4 + .../standalone/browser/standaloneEditor.ts | 4 +- src/vs/monaco.d.ts | 29 +++- 7 files changed, 246 insertions(+), 16 deletions(-) diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index 3e9b2d6c68b..c80286daf0d 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -6,7 +6,7 @@ import 'vs/css!./lineNumbers'; import * as platform from 'vs/base/common/platform'; import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; -import { RenderLineNumbersType } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { editorActiveLineNumber, editorLineNumbers } from 'vs/editor/common/view/editorColorRegistry'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -45,7 +45,7 @@ export class LineNumbersOverlay extends DynamicViewOverlay { this._lineHeight = config.lineHeight; this._renderLineNumbers = config.viewInfo.renderLineNumbers; this._renderCustomLineNumbers = config.viewInfo.renderCustomLineNumbers; - this._renderFinalNewline = config.viewInfo.renderFinalNewline; + this._renderFinalNewline = this._context.configuration.options.get(EditorOptionId.RenderFinalNewline, EditorOption.RenderFinalNewline); this._lineNumbersLeft = config.layoutInfo.lineNumbersLeft; this._lineNumbersWidth = config.layoutInfo.lineNumbersWidth; } diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 1fd0db269f4..6ae96a3430c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -63,6 +63,58 @@ export interface IEnvConfiguration { const hasOwnProperty = Object.hasOwnProperty; +export class EditorConfiguration2 { + public static readOptions(options: editorOptions.IEditorOptions): editorOptions.RawEditorOptions { + // console.log(`parseOptions`, options); + const result = new editorOptions.RawEditorOptions(); + for (const editorOption of editorOptions.editorOptionsRegistry) { + result._write(editorOption.id, editorOption.read(options)); + } + return result; + } + + public static mixOptions(a: editorOptions.RawEditorOptions, b: editorOptions.IEditorOptions): editorOptions.RawEditorOptions { + // console.log(`mixOptions`, a, b); + const result = new editorOptions.RawEditorOptions(); + for (const editorOption of editorOptions.editorOptionsRegistry) { + result._write(editorOption.id, editorOption.mix(a._read(editorOption.id), editorOption.read(b))); + } + return result; + } + + public static validateOptions(options: editorOptions.RawEditorOptions): editorOptions.ValidatedEditorOptions { + // console.log(`validateOptions`, options); + const result = new editorOptions.ValidatedEditorOptions(); + for (const editorOption of editorOptions.editorOptionsRegistry) { + result._write(editorOption.id, editorOption.validate(options._read(editorOption.id))); + } + return result; + } + + public static computeOptions(options: editorOptions.ValidatedEditorOptions, env: editorOptions.IEnvironmentalOptions): editorOptions.ComputedEditorOptions { + // console.log(`computeOptions`, options, env); + const result = new editorOptions.ComputedEditorOptions(); + for (const editorOption of editorOptions.editorOptionsRegistry) { + result._write(editorOption.id, editorOption.compute(options._read(editorOption.id))); + } + return result; + } + + public static checkEquals(a: editorOptions.ComputedEditorOptions, b: editorOptions.ComputedEditorOptions): editorOptions.ChangedEditorOptions | null { + // console.log(`equals`, a, b); + const result = new editorOptions.ChangedEditorOptions(); + let somethingChanged = false; + for (const editorOption of editorOptions.editorOptionsRegistry) { + const equals = editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); + result._write(editorOption.id, equals); + if (!equals) { + somethingChanged = true; + } + } + return (somethingChanged ? result : null); + } +} + export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { public readonly isSimpleWidget: boolean; @@ -75,6 +127,10 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed private _onDidChange = this._register(new Emitter()); public readonly onDidChange: Event = this._onDidChange.event; + private _rawOptions2: editorOptions.RawEditorOptions; + private _validatedOptions2: editorOptions.ValidatedEditorOptions; + public options!: editorOptions.ComputedEditorOptions; + constructor(isSimpleWidget: boolean, options: editorOptions.IEditorOptions) { super(); @@ -89,6 +145,10 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._rawOptions.parameterHints = objects.mixin({}, this._rawOptions.parameterHints || {}); this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); + + this._rawOptions2 = EditorConfiguration2.readOptions(options); + this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); + this._isDominatedByLongLines = false; this._lineNumbersDigitCount = 1; @@ -105,16 +165,20 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed protected _recomputeOptions(): void { const oldOptions = this.editor; - const newOptions = this._computeInternalOptions(); + const oldOptions2 = this.options; + const [newOptions, newOptions2] = this._computeInternalOptions(); - if (oldOptions && oldOptions.equals(newOptions)) { + const changeEvent = (oldOptions2 ? EditorConfiguration2.checkEquals(oldOptions2, newOptions2) : null); + + if (oldOptions && oldOptions.equals(newOptions) && oldOptions2 && changeEvent === null) { return; } this.editor = newOptions; + this.options = newOptions2; if (oldOptions) { - this._onDidChange.fire(oldOptions.createChangeEvent(newOptions)); + this._onDidChange.fire(oldOptions.createChangeEvent(newOptions, changeEvent)); } } @@ -122,7 +186,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return this._rawOptions; } - private _computeInternalOptions(): editorOptions.InternalEditorOptions { + private _computeInternalOptions(): [editorOptions.InternalEditorOptions, editorOptions.ComputedEditorOptions] { const opts = this._validatedOptions; const partialEnv = this._getEnvConfiguration(); const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, partialEnv.zoomLevel, this.isSimpleWidget); @@ -138,7 +202,9 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; - return editorOptions.InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); + const r = editorOptions.InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); + const r2 = EditorConfiguration2.computeOptions(this._validatedOptions2, env); + return [r, r2]; } private static _primitiveArrayEquals(a: any[], b: any[]): boolean { @@ -189,7 +255,11 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return; } this._rawOptions = objects.mixin(this._rawOptions, newOptions || {}); + this._rawOptions2 = EditorConfiguration2.mixOptions(this._rawOptions2, newOptions); + this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); + this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); + this._recomputeOptions(); } @@ -275,7 +345,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.renderFinalNewline': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.renderFinalNewline, + 'default': editorOptions.EditorOption.RenderFinalNewline.defaultValue, 'description': nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }, 'editor.rulers': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 43c568a191f..6c0c01f4524 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -997,7 +997,6 @@ export interface InternalEditorViewOptions { readonly renderLineNumbers: RenderLineNumbersType; readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; - readonly renderFinalNewline: boolean; readonly selectOnLineNumbers: boolean; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; @@ -1230,8 +1229,14 @@ export class InternalEditorOptions { /** * @internal */ - public createChangeEvent(newOpts: InternalEditorOptions): IConfigurationChangedEvent { + public createChangeEvent(newOpts: InternalEditorOptions, changeEvent: ChangedEditorOptions | null): IConfigurationChangedEvent { return { + hasChanged: (id: EditorOptionId) => { + if (!changeEvent) { + return false; + } + return changeEvent.get(id); + }, canUseLayerHinting: (this.canUseLayerHinting !== newOpts.canUseLayerHinting), pixelRatio: (this.pixelRatio !== newOpts.pixelRatio), editorClassName: (this.editorClassName !== newOpts.editorClassName), @@ -1312,7 +1317,6 @@ export class InternalEditorOptions { && a.renderLineNumbers === b.renderLineNumbers && a.renderCustomLineNumbers === b.renderCustomLineNumbers && a.cursorSurroundingLines === b.cursorSurroundingLines - && a.renderFinalNewline === b.renderFinalNewline && a.selectOnLineNumbers === b.selectOnLineNumbers && a.glyphMargin === b.glyphMargin && a.revealHorizontalRightPadding === b.revealHorizontalRightPadding @@ -1638,6 +1642,7 @@ export interface EditorLayoutInfo { * An event describing that the configuration of the editor has changed. */ export interface IConfigurationChangedEvent { + hasChanged(id: EditorOptionId): boolean; readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; readonly editorClassName: boolean; @@ -2076,7 +2081,6 @@ export class EditorOptionsValidator { cursorSurroundingLines: _clampedInt(opts.cursorSurroundingLines, defaults.cursorWidth, 0, Number.MAX_VALUE), renderLineNumbers: renderLineNumbers, renderCustomLineNumbers: renderCustomLineNumbers, - renderFinalNewline: _boolean(opts.renderFinalNewline, defaults.renderFinalNewline), selectOnLineNumbers: _boolean(opts.selectOnLineNumbers, defaults.selectOnLineNumbers), glyphMargin: _boolean(opts.glyphMargin, defaults.glyphMargin), revealHorizontalRightPadding: _clampedInt(opts.revealHorizontalRightPadding, defaults.revealHorizontalRightPadding, 0, 1000), @@ -2198,7 +2202,6 @@ export class InternalEditorOptionsFactory { renderLineNumbers: opts.viewInfo.renderLineNumbers, renderCustomLineNumbers: opts.viewInfo.renderCustomLineNumbers, cursorSurroundingLines: opts.viewInfo.cursorSurroundingLines, - renderFinalNewline: opts.viewInfo.renderFinalNewline, selectOnLineNumbers: opts.viewInfo.selectOnLineNumbers, glyphMargin: opts.viewInfo.glyphMargin, revealHorizontalRightPadding: opts.viewInfo.revealHorizontalRightPadding, @@ -2665,7 +2668,6 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { renderLineNumbers: RenderLineNumbersType.On, renderCustomLineNumbers: null, cursorSurroundingLines: 0, - renderFinalNewline: true, selectOnLineNumbers: true, glyphMargin: true, revealHorizontalRightPadding: 30, @@ -2770,3 +2772,127 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { codeActionsOnSaveTimeout: 750 }, }; + +export interface IRawEditorOptionsBag { + [key: string]: any; +} + +/** + * @internal + */ +export class RawEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOptionId): T | undefined { + return this._values[id]; + } + public _write(id: EditorOptionId, value: T | undefined): void { + this._values[id] = value; + } +} + +/** + * @internal + */ +export class ValidatedEditorOptions { + private readonly _values: any[] = []; + public _read(option: EditorOptionId): T { + return this._values[option]; + } + public _write(option: EditorOptionId, value: T): void { + this._values[option] = value; + } +} + +export interface IComputedEditorOptions { + get(id: EditorOptionId, option: IEditorOption): T3; +} + +/** + * @internal + */ +export class ComputedEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOptionId): T { + return this._values[id]; + } + public get(id: EditorOptionId, option: IEditorOption): T3 { + return this._values[id]; + } + public _write(id: EditorOptionId, value: T): void { + this._values[id] = value; + } +} + +/** + * @internal + */ +export class ChangedEditorOptions { + private readonly _values: boolean[] = []; + public get(id: EditorOptionId): boolean { + return this._values[id]; + } + public _write(id: EditorOptionId, value: boolean): void { + this._values[id] = value; + } +} + +interface IEditorOption { + readonly id: EditorOptionId; + readonly name: string; + readonly defaultValue: T1; + read(options: IRawEditorOptionsBag): T1 | undefined; + mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; + validate(input: T1 | undefined): T2; + compute(value: T2): T3; + equals(a: T3, b: T3): boolean; +} + +class BooleanEditorOption implements IEditorOption { + public readonly id: EditorOptionId; + public readonly name: string; + public readonly defaultValue: boolean; + + constructor(id: EditorOptionId, name: string, defaultValue: boolean) { + this.id = id; + this.name = name; + this.defaultValue = defaultValue; + } + + public read(options: IRawEditorOptionsBag): boolean | undefined { + return options[this.name]; + } + + public mix(a: boolean | undefined, b: boolean | undefined): boolean | undefined { + return (typeof b !== 'undefined' ? b : a); + } + + public validate(input: boolean | undefined): boolean { + return _boolean(input, this.defaultValue); + } + + public compute(value: boolean): boolean { + return value; + } + + public equals(a: boolean, b: boolean): boolean { + return (a === b); + } +} + +/** + * @internal + */ +export const editorOptionsRegistry: IEditorOption[] = []; + +function registerEditorOption(option: IEditorOption): IEditorOption { + editorOptionsRegistry[option.id] = option; + return option; +} + +export const enum EditorOptionId { + RenderFinalNewline, +} + +export const EditorOption = { + RenderFinalNewline: registerEditorOption(new BooleanEditorOption(EditorOptionId.RenderFinalNewline, 'renderFinalNewline', true)) +}; diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index bde26ab9802..6c954159234 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -152,6 +152,7 @@ export interface IConfiguration extends IDisposable { onDidChange(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable; readonly editor: editorOptions.InternalEditorOptions; + readonly options: editorOptions.IComputedEditorOptions; setMaxLineNumber(maxLineNumber: number): void; updateOptions(newOptions: editorOptions.IEditorOptions): void; diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index a705c132478..ef807a30068 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -430,6 +430,10 @@ export enum RenderLineNumbersType { Custom = 4 } +export enum EditorOptionId { + RenderFinalNewline = 0 +} + /** * A positioning preference for rendering content widgets. */ diff --git a/src/vs/editor/standalone/browser/standaloneEditor.ts b/src/vs/editor/standalone/browser/standaloneEditor.ts index 280e00cbdf7..c3936c2a1b7 100644 --- a/src/vs/editor/standalone/browser/standaloneEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneEditor.ts @@ -369,6 +369,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { RenderMinimap: standaloneEnums.RenderMinimap, ScrollType: standaloneEnums.ScrollType, RenderLineNumbersType: standaloneEnums.RenderLineNumbersType, + EditorOptionId: standaloneEnums.EditorOptionId, // classes InternalEditorOptions: editorOptions.InternalEditorOptions, @@ -378,7 +379,8 @@ export function createMonacoEditorAPI(): typeof monaco.editor { FindMatch: FindMatch, // vars - EditorType: editorCommon.EditorType + EditorType: editorCommon.EditorType, + EditorOption: editorOptions.EditorOption, }; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 6e0b1286ef0..970d6f079d6 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3312,7 +3312,6 @@ declare namespace monaco.editor { readonly renderLineNumbers: RenderLineNumbersType; readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; - readonly renderFinalNewline: boolean; readonly selectOnLineNumbers: boolean; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; @@ -3525,6 +3524,7 @@ declare namespace monaco.editor { * An event describing that the configuration of the editor has changed. */ export interface IConfigurationChangedEvent { + hasChanged(id: EditorOptionId): boolean; readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; readonly editorClassName: boolean; @@ -3551,6 +3551,33 @@ declare namespace monaco.editor { readonly contribInfo: boolean; } + export interface IRawEditorOptionsBag { + [key: string]: any; + } + + export interface IComputedEditorOptions { + get(id: EditorOptionId, option: IEditorOption): T3; + } + + interface IEditorOption { + readonly id: EditorOptionId; + readonly name: string; + readonly defaultValue: T1; + read(options: IRawEditorOptionsBag): T1 | undefined; + mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; + validate(input: T1 | undefined): T2; + compute(value: T2): T3; + equals(a: T3, b: T3): boolean; + } + + export enum EditorOptionId { + RenderFinalNewline = 0 + } + + export const EditorOption: { + RenderFinalNewline: IEditorOption; + }; + /** * A view zone is a full horizontal rectangle that 'pushes' text down. * The editor reserves space for view zones when rendering. From 75ffa8befa51ec59a233c7c030226737bd4af53d Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 2 Sep 2019 12:06:47 +0200 Subject: [PATCH 004/109] - Add a typed way to read options - Move more options to the new format --- .../editor/browser/controller/mouseHandler.ts | 3 +- src/vs/editor/browser/editorBrowser.ts | 2 ++ .../viewParts/lineNumbers/lineNumbers.ts | 2 +- .../editor/browser/widget/codeEditorWidget.ts | 4 +++ .../common/config/commonEditorConfig.ts | 8 +++-- src/vs/editor/common/config/editorOptions.ts | 31 ++++++------------- src/vs/editor/common/editorCommon.ts | 3 +- .../common/standalone/standaloneEnums.ts | 4 ++- src/vs/monaco.d.ts | 19 ++++++------ .../codeEditor/browser/selectionClipboard.ts | 8 ++--- 10 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index 418e8ebee98..ccd54250d89 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -21,6 +21,7 @@ import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; /** * Merges mouse events when mouse move events are throttled @@ -216,7 +217,7 @@ export class MouseHandler extends ViewEventHandler { const targetIsContent = (t.type === editorBrowser.MouseTargetType.CONTENT_TEXT || t.type === editorBrowser.MouseTargetType.CONTENT_EMPTY); const targetIsGutter = (t.type === editorBrowser.MouseTargetType.GUTTER_GLYPH_MARGIN || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_DECORATIONS); const targetIsLineNumbers = (t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS); - const selectOnLineNumbers = this._context.configuration.editor.viewInfo.selectOnLineNumbers; + const selectOnLineNumbers = this._context.configuration.getOption(EditorOptionId.selectOnLineNumbers); const targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE); const targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET); diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index a5e31344d3c..d1efe4ddd52 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -536,6 +536,8 @@ export interface ICodeEditor extends editorCommon.IEditor { */ getConfiguration(): editorOptions.InternalEditorOptions; + getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue; + /** * Returns the 'raw' editor's configuration (without any validation or defaults). * @internal diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index c80286daf0d..2067c4d3878 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -45,7 +45,7 @@ export class LineNumbersOverlay extends DynamicViewOverlay { this._lineHeight = config.lineHeight; this._renderLineNumbers = config.viewInfo.renderLineNumbers; this._renderCustomLineNumbers = config.viewInfo.renderCustomLineNumbers; - this._renderFinalNewline = this._context.configuration.options.get(EditorOptionId.RenderFinalNewline, EditorOption.RenderFinalNewline); + this._renderFinalNewline = this._context.configuration.getOption(EditorOptionId.renderFinalNewline); this._lineNumbersLeft = config.layoutInfo.lineNumbersLeft; this._lineNumbersWidth = config.layoutInfo.lineNumbersWidth; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 0ac879ee78a..3860def914f 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -370,6 +370,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE return this._configuration.editor; } + public getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue { + return this._configuration.getOption(id); + } + public getRawConfiguration(): editorOptions.IEditorOptions { return this._configuration.getRawOptions(); } diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 6ae96a3430c..10fff300995 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -156,6 +156,10 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions())); } + public getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue { + return this.options._read(id); + } + public observeReferenceElement(dimension?: editorCommon.IDimension): void { } @@ -345,7 +349,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.renderFinalNewline': { 'type': 'boolean', - 'default': editorOptions.EditorOption.RenderFinalNewline.defaultValue, + 'default': editorOptions.EditorOption.renderFinalNewline.defaultValue, 'description': nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }, 'editor.rulers': { @@ -1137,7 +1141,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.selectionClipboard': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.selectionClipboard, + 'default': editorOptions.EditorOption.selectionClipboard.defaultValue, 'description': nls.localize('selectionClipboard', "Controls whether the Linux primary clipboard should be supported."), 'included': platform.isLinux }, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 6c0c01f4524..45bef3115da 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -997,7 +997,6 @@ export interface InternalEditorViewOptions { readonly renderLineNumbers: RenderLineNumbersType; readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; - readonly selectOnLineNumbers: boolean; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; readonly roundedSelection: boolean; @@ -1025,7 +1024,6 @@ export interface InternalEditorViewOptions { } export interface EditorContribOptions { - readonly selectionClipboard: boolean; readonly hover: InternalEditorHoverOptions; readonly links: boolean; readonly contextmenu: boolean; @@ -1317,7 +1315,6 @@ export class InternalEditorOptions { && a.renderLineNumbers === b.renderLineNumbers && a.renderCustomLineNumbers === b.renderCustomLineNumbers && a.cursorSurroundingLines === b.cursorSurroundingLines - && a.selectOnLineNumbers === b.selectOnLineNumbers && a.glyphMargin === b.glyphMargin && a.revealHorizontalRightPadding === b.revealHorizontalRightPadding && a.roundedSelection === b.roundedSelection @@ -1464,8 +1461,7 @@ export class InternalEditorOptions { */ private static _equalsContribOptions(a: EditorContribOptions, b: EditorContribOptions): boolean { return ( - a.selectionClipboard === b.selectionClipboard - && this._equalsHoverOptions(a.hover, b.hover) + this._equalsHoverOptions(a.hover, b.hover) && a.links === b.links && a.contextmenu === b.contextmenu && InternalEditorOptions._equalsQuickSuggestions(a.quickSuggestions, b.quickSuggestions) @@ -2081,7 +2077,6 @@ export class EditorOptionsValidator { cursorSurroundingLines: _clampedInt(opts.cursorSurroundingLines, defaults.cursorWidth, 0, Number.MAX_VALUE), renderLineNumbers: renderLineNumbers, renderCustomLineNumbers: renderCustomLineNumbers, - selectOnLineNumbers: _boolean(opts.selectOnLineNumbers, defaults.selectOnLineNumbers), glyphMargin: _boolean(opts.glyphMargin, defaults.glyphMargin), revealHorizontalRightPadding: _clampedInt(opts.revealHorizontalRightPadding, defaults.revealHorizontalRightPadding, 0, 1000), roundedSelection: _boolean(opts.roundedSelection, defaults.roundedSelection), @@ -2122,7 +2117,6 @@ export class EditorOptionsValidator { } const find = this._sanitizeFindOpts(opts.find, defaults.find); return { - selectionClipboard: _boolean(opts.selectionClipboard, defaults.selectionClipboard), hover: this._sanitizeHoverOpts(opts.hover, defaults.hover), links: _boolean(opts.links, defaults.links), contextmenu: _boolean(opts.contextmenu, defaults.contextmenu), @@ -2202,7 +2196,6 @@ export class InternalEditorOptionsFactory { renderLineNumbers: opts.viewInfo.renderLineNumbers, renderCustomLineNumbers: opts.viewInfo.renderCustomLineNumbers, cursorSurroundingLines: opts.viewInfo.cursorSurroundingLines, - selectOnLineNumbers: opts.viewInfo.selectOnLineNumbers, glyphMargin: opts.viewInfo.glyphMargin, revealHorizontalRightPadding: opts.viewInfo.revealHorizontalRightPadding, roundedSelection: opts.viewInfo.roundedSelection, @@ -2236,7 +2229,6 @@ export class InternalEditorOptionsFactory { }, contribInfo: { - selectionClipboard: opts.contribInfo.selectionClipboard, hover: opts.contribInfo.hover, links: opts.contribInfo.links, contextmenu: opts.contribInfo.contextmenu, @@ -2668,7 +2660,6 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { renderLineNumbers: RenderLineNumbersType.On, renderCustomLineNumbers: null, cursorSurroundingLines: 0, - selectOnLineNumbers: true, glyphMargin: true, revealHorizontalRightPadding: 30, roundedSelection: true, @@ -2716,7 +2707,6 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { }, contribInfo: { - selectionClipboard: true, hover: { enabled: true, delay: 300, @@ -2803,10 +2793,6 @@ export class ValidatedEditorOptions { } } -export interface IComputedEditorOptions { - get(id: EditorOptionId, option: IEditorOption): T3; -} - /** * @internal */ @@ -2815,9 +2801,6 @@ export class ComputedEditorOptions { public _read(id: EditorOptionId): T { return this._values[id]; } - public get(id: EditorOptionId, option: IEditorOption): T3 { - return this._values[id]; - } public _write(id: EditorOptionId, value: T): void { this._values[id] = value; } @@ -2836,7 +2819,7 @@ export class ChangedEditorOptions { } } -interface IEditorOption { +export interface IEditorOption { readonly id: EditorOptionId; readonly name: string; readonly defaultValue: T1; @@ -2890,9 +2873,15 @@ function registerEditorOption(option: IEditorOption): IE } export const enum EditorOptionId { - RenderFinalNewline, + renderFinalNewline, + selectionClipboard, + selectOnLineNumbers, } export const EditorOption = { - RenderFinalNewline: registerEditorOption(new BooleanEditorOption(EditorOptionId.RenderFinalNewline, 'renderFinalNewline', true)) + renderFinalNewline: registerEditorOption(new BooleanEditorOption(EditorOptionId.renderFinalNewline, 'renderFinalNewline', true)), + selectionClipboard: registerEditorOption(new BooleanEditorOption(EditorOptionId.selectionClipboard, 'selectionClipboard', true)), + selectOnLineNumbers: registerEditorOption(new BooleanEditorOption(EditorOptionId.selectOnLineNumbers, 'selectOnLineNumbers', true)), }; + +export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 6c954159234..f070525b99b 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -152,7 +152,8 @@ export interface IConfiguration extends IDisposable { onDidChange(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable; readonly editor: editorOptions.InternalEditorOptions; - readonly options: editorOptions.IComputedEditorOptions; + + getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue; setMaxLineNumber(maxLineNumber: number): void; updateOptions(newOptions: editorOptions.IEditorOptions): void; diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index ef807a30068..1af333dd0a4 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -431,7 +431,9 @@ export enum RenderLineNumbersType { } export enum EditorOptionId { - RenderFinalNewline = 0 + renderFinalNewline = 0, + selectionClipboard = 1, + selectOnLineNumbers = 2 } /** diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 970d6f079d6..87d85008895 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3312,7 +3312,6 @@ declare namespace monaco.editor { readonly renderLineNumbers: RenderLineNumbersType; readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; - readonly selectOnLineNumbers: boolean; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; readonly roundedSelection: boolean; @@ -3340,7 +3339,6 @@ declare namespace monaco.editor { } export interface EditorContribOptions { - readonly selectionClipboard: boolean; readonly hover: InternalEditorHoverOptions; readonly links: boolean; readonly contextmenu: boolean; @@ -3555,11 +3553,7 @@ declare namespace monaco.editor { [key: string]: any; } - export interface IComputedEditorOptions { - get(id: EditorOptionId, option: IEditorOption): T3; - } - - interface IEditorOption { + export interface IEditorOption { readonly id: EditorOptionId; readonly name: string; readonly defaultValue: T1; @@ -3571,13 +3565,19 @@ declare namespace monaco.editor { } export enum EditorOptionId { - RenderFinalNewline = 0 + renderFinalNewline = 0, + selectionClipboard = 1, + selectOnLineNumbers = 2 } export const EditorOption: { - RenderFinalNewline: IEditorOption; + renderFinalNewline: IEditorOption; + selectionClipboard: IEditorOption; + selectOnLineNumbers: IEditorOption; }; + export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; + /** * A view zone is a full horizontal rectangle that 'pushes' text down. * The editor reserves space for view zones when rendering. @@ -4027,6 +4027,7 @@ declare namespace monaco.editor { * Returns the current editor's configuration */ getConfiguration(): InternalEditorOptions; + getOption>(id: EditorOptionId): ComputedEditorOptionValue; /** * Get value of the current model attached to this editor. * @see `ITextModel.getValue` diff --git a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts index 4c3a8ba75ff..18aa8e4965e 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts @@ -9,7 +9,7 @@ import * as process from 'vs/base/common/process'; import * as platform from 'vs/base/common/platform'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; @@ -24,11 +24,11 @@ export class SelectionClipboard extends Disposable implements IEditorContributio super(); if (platform.isLinux) { - let isEnabled = editor.getConfiguration().contribInfo.selectionClipboard; + let isEnabled = editor.getOption(EditorOptionId.selectionClipboard); this._register(editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.contribInfo) { - isEnabled = editor.getConfiguration().contribInfo.selectionClipboard; + if (e.hasChanged(EditorOptionId.selectionClipboard)) { + isEnabled = editor.getOption(EditorOptionId.selectionClipboard); } })); From 363b9769412fea0d9aef07fa1801371c14d72741 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 2 Sep 2019 23:05:00 +0200 Subject: [PATCH 005/109] Convert more editor options --- .../lib/tslint/noUnexternalizedStringsRule.js | 3 + .../lib/tslint/noUnexternalizedStringsRule.ts | 3 + build/monaco/api.js | 5 +- build/monaco/api.ts | 5 +- build/monaco/monaco.d.ts.recipe | 1 + .../editor/browser/controller/mouseHandler.ts | 2 +- .../editor/browser/controller/mouseTarget.ts | 8 +- .../browser/controller/textAreaHandler.ts | 31 +- src/vs/editor/browser/editorBrowser.ts | 2 + src/vs/editor/browser/view/viewImpl.ts | 6 +- src/vs/editor/browser/view/viewLayer.ts | 6 +- src/vs/editor/browser/view/viewOverlays.ts | 22 +- .../contentWidgets/contentWidgets.ts | 16 +- .../currentLineHighlight.ts | 13 +- .../currentLineMarginHighlight.ts | 11 +- .../editorScrollbar/editorScrollbar.ts | 57 +- .../viewParts/glyphMargin/glyphMargin.ts | 16 +- .../viewParts/indentGuides/indentGuides.ts | 11 +- .../viewParts/lineNumbers/lineNumbers.ts | 13 +- .../browser/viewParts/lines/viewLines.ts | 15 +- .../linesDecorations/linesDecorations.ts | 17 +- .../editor/browser/viewParts/margin/margin.ts | 21 +- .../browser/viewParts/minimap/minimap.ts | 8 +- .../overlayWidgets/overlayWidgets.ts | 29 +- .../overviewRuler/decorationsOverviewRuler.ts | 10 +- .../editor/browser/viewParts/rulers/rulers.ts | 6 +- .../scrollDecoration/scrollDecoration.ts | 18 +- .../browser/viewParts/viewZones/viewZones.ts | 16 +- .../editor/browser/widget/codeEditorWidget.ts | 19 +- .../editor/browser/widget/diffEditorWidget.ts | 6 +- src/vs/editor/browser/widget/diffReview.ts | 15 +- .../common/config/commonEditorConfig.ts | 55 +- src/vs/editor/common/config/editorOptions.ts | 2471 ++++++++--------- .../editor/common/controller/cursorCommon.ts | 10 +- src/vs/editor/common/editorCommon.ts | 3 +- .../common/standalone/standaloneEnums.ts | 36 +- src/vs/editor/common/view/viewEvents.ts | 14 +- src/vs/editor/common/viewLayout/viewLayout.ts | 27 +- .../editor/common/viewModel/viewModelImpl.ts | 23 +- src/vs/editor/contrib/find/findWidget.ts | 16 +- src/vs/editor/contrib/folding/folding.ts | 10 +- .../accessibilityHelp/accessibilityHelp.ts | 4 +- .../standalone/browser/standaloneEditor.ts | 2 + .../common/config/commonEditorConfig.test.ts | 8 +- .../viewLayout/editorLayoutProvider.test.ts | 4 +- .../viewModel/splitLinesCollection.test.ts | 45 +- src/vs/monaco.d.ts | 278 +- .../workbench/api/browser/mainThreadEditor.ts | 6 +- .../browser/parts/editor/editorStatus.ts | 4 +- .../codeEditor/browser/toggleWordWrap.ts | 45 +- .../browser/commentsEditorContribution.ts | 6 +- .../preferences/browser/preferencesWidgets.ts | 4 +- .../quickopen/browser/gotoLineHandler.ts | 7 +- 53 files changed, 1881 insertions(+), 1608 deletions(-) diff --git a/build/lib/tslint/noUnexternalizedStringsRule.js b/build/lib/tslint/noUnexternalizedStringsRule.js index 18a90c0f9c1..a1183ce68e7 100644 --- a/build/lib/tslint/noUnexternalizedStringsRule.js +++ b/build/lib/tslint/noUnexternalizedStringsRule.js @@ -11,6 +11,9 @@ const Lint = require("tslint"); */ class Rule extends Lint.Rules.AbstractRule { apply(sourceFile) { + if (/\.d.ts$/.test(sourceFile.fileName)) { + return []; + } return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions())); } } diff --git a/build/lib/tslint/noUnexternalizedStringsRule.ts b/build/lib/tslint/noUnexternalizedStringsRule.ts index e8c0e98ec15..d896e4fabe2 100644 --- a/build/lib/tslint/noUnexternalizedStringsRule.ts +++ b/build/lib/tslint/noUnexternalizedStringsRule.ts @@ -11,6 +11,9 @@ import * as Lint from 'tslint'; */ export class Rule extends Lint.Rules.AbstractRule { public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + if (/\.d.ts$/.test(sourceFile.fileName)) { + return []; + } return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions())); } } diff --git a/build/monaco/api.js b/build/monaco/api.js index 5cd0be82039..93fea1558b9 100644 --- a/build/monaco/api.js +++ b/build/monaco/api.js @@ -148,8 +148,9 @@ function getMassagedTopLevelDeclarationText(sourceFile, declaration, importName, } }); } - result = result.replace(/export default/g, 'export'); - result = result.replace(/export declare/g, 'export'); + result = result.replace(/export default /g, 'export '); + result = result.replace(/export declare /g, 'export '); + result = result.replace(/declare /g, ''); if (declaration.kind === ts.SyntaxKind.EnumDeclaration) { result = result.replace(/const enum/, 'enum'); enums.push(result); diff --git a/build/monaco/api.ts b/build/monaco/api.ts index ef9c9a584dc..1cd4e49b733 100644 --- a/build/monaco/api.ts +++ b/build/monaco/api.ts @@ -178,8 +178,9 @@ function getMassagedTopLevelDeclarationText(sourceFile: ts.SourceFile, declarati } }); } - result = result.replace(/export default/g, 'export'); - result = result.replace(/export declare/g, 'export'); + result = result.replace(/export default /g, 'export '); + result = result.replace(/export declare /g, 'export '); + result = result.replace(/declare /g, ''); if (declaration.kind === ts.SyntaxKind.EnumDeclaration) { result = result.replace(/const enum/, 'enum'); diff --git a/build/monaco/monaco.d.ts.recipe b/build/monaco/monaco.d.ts.recipe index afba093b25c..4a80dae41aa 100644 --- a/build/monaco/monaco.d.ts.recipe +++ b/build/monaco/monaco.d.ts.recipe @@ -62,6 +62,7 @@ export interface ICommandHandler { #includeAll(vs/editor/common/editorCommon;editorOptions.=>): IScrollEvent #includeAll(vs/editor/common/model/textModelEvents): #includeAll(vs/editor/common/controller/cursorEvents): +#include(vs/platform/accessibility/common/accessibility): AccessibilitySupport #includeAll(vs/editor/common/config/editorOptions): #includeAll(vs/editor/browser/editorBrowser;editorCommon.=>;editorOptions.=>): #include(vs/editor/common/config/fontInfo): FontInfo, BareFontInfo diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index ccd54250d89..ce65849c418 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -217,7 +217,7 @@ export class MouseHandler extends ViewEventHandler { const targetIsContent = (t.type === editorBrowser.MouseTargetType.CONTENT_TEXT || t.type === editorBrowser.MouseTargetType.CONTENT_EMPTY); const targetIsGutter = (t.type === editorBrowser.MouseTargetType.GUTTER_GLYPH_MARGIN || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_DECORATIONS); const targetIsLineNumbers = (t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS); - const selectOnLineNumbers = this._context.configuration.getOption(EditorOptionId.selectOnLineNumbers); + const selectOnLineNumbers = this._context.configuration.options.get(EditorOptionId.selectOnLineNumbers); const targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE); const targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET); diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index f510e0f6f82..58948e740aa 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -10,7 +10,7 @@ import { ClientCoordinates, EditorMouseEvent, EditorPagePosition, PageCoordinate import { PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart'; import { ViewLine } from 'vs/editor/browser/viewParts/lines/viewLine'; import { IViewCursorRenderData } from 'vs/editor/browser/viewParts/viewCursors/viewCursor'; -import { EditorLayoutInfo } from 'vs/editor/common/config/editorOptions'; +import { EditorLayoutInfo, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range as EditorRange } from 'vs/editor/common/core/range'; import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; @@ -239,7 +239,8 @@ export class HitTestContext { constructor(context: ViewContext, viewHelper: IPointerHandlerHelper, lastViewCursorsRenderData: IViewCursorRenderData[]) { this.model = context.model; - this.layoutInfo = context.configuration.editor.layoutInfo; + const options = context.configuration.options; + this.layoutInfo = options.get(EditorOptionId.layoutInfo); this.viewDomNode = viewHelper.viewDomNode; this.lineHeight = context.configuration.editor.lineHeight; this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; @@ -713,7 +714,8 @@ export class MouseTargetFactory { } public getMouseColumn(editorPos: EditorPagePosition, pos: PageCoordinates): number { - const layoutInfo = this._context.configuration.editor.layoutInfo; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + pos.x - editorPos.x - layoutInfo.contentLeft; return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index c1a41a4981f..bfefbfff922 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -16,7 +16,7 @@ import { ViewController } from 'vs/editor/browser/view/viewController'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers'; import { Margin } from 'vs/editor/browser/viewParts/margin/margin'; -import { RenderLineNumbersType } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; import { BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { WordCharacterClass, getMapForWordSeparators } from 'vs/editor/common/controller/wordCharacterClassifier'; import { Position } from 'vs/editor/common/core/position'; @@ -119,11 +119,13 @@ export class TextAreaHandler extends ViewPart { this._viewHelper = viewHelper; const conf = this._context.configuration.editor; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._accessibilitySupport = conf.accessibilitySupport; - this._contentLeft = conf.layoutInfo.contentLeft; - this._contentWidth = conf.layoutInfo.contentWidth; - this._contentHeight = conf.layoutInfo.contentHeight; + this._contentLeft = layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; + this._contentHeight = layoutInfo.contentHeight; this._scrollLeft = 0; this._scrollTop = 0; this._fontInfo = conf.fontInfo; @@ -143,7 +145,7 @@ export class TextAreaHandler extends ViewPart { this.textArea.setAttribute('autocapitalize', 'off'); this.textArea.setAttribute('autocomplete', 'off'); this.textArea.setAttribute('spellcheck', 'false'); - this.textArea.setAttribute('aria-label', conf.viewInfo.ariaLabel); + this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); this.textArea.setAttribute('role', 'textbox'); this.textArea.setAttribute('aria-multiline', 'true'); this.textArea.setAttribute('aria-haspopup', 'false'); @@ -371,22 +373,24 @@ export class TextAreaHandler extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const conf = this._context.configuration.editor; + const options = this._context.configuration.options; if (e.fontInfo) { this._fontInfo = conf.fontInfo; } if (e.viewInfo) { - this.textArea.setAttribute('aria-label', conf.viewInfo.ariaLabel); + this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); } - if (e.layoutInfo) { - this._contentLeft = conf.layoutInfo.contentLeft; - this._contentWidth = conf.layoutInfo.contentWidth; - this._contentHeight = conf.layoutInfo.contentHeight; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; + this._contentHeight = layoutInfo.contentHeight; } if (e.lineHeight) { this._lineHeight = conf.lineHeight; } - if (e.accessibilitySupport) { + if (e.hasChanged(EditorOptionId.accessibilitySupport)) { this._accessibilitySupport = conf.accessibilitySupport; this._textAreaInput.writeScreenReaderContent('strategy changed'); } @@ -544,10 +548,13 @@ export class TextAreaHandler extends ViewPart { tac.setWidth(1); tac.setHeight(1); + const options = this._context.configuration.options; + if (this._context.configuration.editor.viewInfo.glyphMargin) { tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME); } else { - if (this._context.configuration.editor.viewInfo.renderLineNumbers !== RenderLineNumbersType.Off) { + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + if (renderLineNumbers.renderType !== RenderLineNumbersType.Off) { tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME); } else { tac.setClassName('monaco-editor-background textAreaCover'); diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index d1efe4ddd52..de7dcc54683 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -536,6 +536,8 @@ export interface ICodeEditor extends editorCommon.IEditor { */ getConfiguration(): editorOptions.InternalEditorOptions; + getOptions(): editorOptions.IComputedEditorOptions; + getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue; /** diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 45c711cecef..67fca037793 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -48,6 +48,7 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData' import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IThemeService, getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IContentWidgetData { widget: editorBrowser.IContentWidget; @@ -281,7 +282,8 @@ export class View extends ViewEventHandler { } private _setLayout(): void { - const layoutInfo = this._context.configuration.editor.layoutInfo; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.domNode.setWidth(layoutInfo.width); this.domNode.setHeight(layoutInfo.height); @@ -304,7 +306,7 @@ export class View extends ViewEventHandler { if (e.editorClassName) { this.domNode.setClassName(this.getEditorClassName()); } - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { this._setLayout(); } return false; diff --git a/src/vs/editor/browser/view/viewLayer.ts b/src/vs/editor/browser/view/viewLayer.ts index ecdd665be73..c5624ce9c83 100644 --- a/src/vs/editor/browser/view/viewLayer.ts +++ b/src/vs/editor/browser/view/viewLayer.ts @@ -7,6 +7,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; /** * Represents a visible line @@ -269,7 +270,10 @@ export class VisibleLinesCollection { // ---- begin view event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - return e.layoutInfo; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + return true; + } + return false; } public onFlushed(e: viewEvents.ViewFlushedEvent): boolean { diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index bc75a6b4cef..5182408db5a 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -14,6 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class ViewOverlays extends ViewPart implements IVisibleLinesHost { @@ -215,8 +216,9 @@ export class ContentViewOverlays extends ViewOverlays { constructor(context: ViewContext) { super(context); - - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentWidth = layoutInfo.contentWidth; this.domNode.setHeight(0); } @@ -224,8 +226,10 @@ export class ContentViewOverlays extends ViewOverlays { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.layoutInfo) { - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentWidth = layoutInfo.contentWidth; } return super.onConfigurationChanged(e); } @@ -249,7 +253,9 @@ export class MarginViewOverlays extends ViewOverlays { constructor(context: ViewContext) { super(context); - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; this.domNode.setClassName('margin-view-overlays'); this.domNode.setWidth(1); @@ -263,8 +269,10 @@ export class MarginViewOverlays extends ViewOverlays { Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); shouldRender = true; } - if (e.layoutInfo) { - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; shouldRender = true; } return super.onConfigurationChanged(e) || shouldRender; diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index cae3be1ed16..9c7998b7427 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -14,6 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; class Coordinate { _coordinateBrand: void; @@ -207,9 +208,12 @@ class Widget { this.allowEditorOverflow = this._actual.allowEditorOverflow || false; this.suppressMouseDown = this._actual.suppressMouseDown || false; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._fixedOverflowWidgets = this._context.configuration.editor.viewInfo.fixedOverflowWidgets; - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; + this._contentLeft = layoutInfo.contentLeft; this._lineHeight = this._context.configuration.editor.lineHeight; this._position = null; @@ -233,9 +237,11 @@ class Widget { if (e.lineHeight) { this._lineHeight = this._context.configuration.editor.lineHeight; } - if (e.layoutInfo) { - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; this._maxWidth = this._getMaxWidth(); } } diff --git a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts index d707bbad7c5..65343ec07eb 100644 --- a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts @@ -10,6 +10,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class CurrentLineHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; @@ -23,13 +24,17 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; this._selectionIsEmpty = true; this._primaryCursorLineNumber = 1; this._scrollWidth = 0; - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; + + this._contentWidth = layoutInfo.contentWidth; this._context.addEventHandler(this); } @@ -48,8 +53,10 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { if (e.viewInfo) { this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; } - if (e.layoutInfo) { - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentWidth = layoutInfo.contentWidth; } return true; } diff --git a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts index 55145073655..1389ed0e1b0 100644 --- a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts @@ -10,6 +10,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; @@ -22,12 +23,14 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; this._selectionIsEmpty = true; this._primaryCursorLineNumber = 1; - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + this._contentLeft = layoutInfo.contentLeft; this._context.addEventHandler(this); } @@ -46,8 +49,10 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { if (e.viewInfo) { this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; } - if (e.layoutInfo) { - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; } return true; } diff --git a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts index d9b8c4dfd8f..24185fbc1c5 100644 --- a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts +++ b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts @@ -14,6 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class EditorScrollbar extends ViewPart { @@ -28,8 +29,11 @@ export class EditorScrollbar extends ViewPart { ) { super(context); - const editor = this._context.configuration.editor; - const configScrollbarOpts = editor.viewInfo.scrollbar; + + const options = this._context.configuration.options; + const scrollbar = options.get(EditorOptionId.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); const scrollbarOptions: ScrollableElementCreationOptions = { listenOnDomNode: viewDomNode.domNode, @@ -37,18 +41,18 @@ export class EditorScrollbar extends ViewPart { useShadows: false, lazyRender: true, - vertical: configScrollbarOpts.vertical, - horizontal: configScrollbarOpts.horizontal, - verticalHasArrows: configScrollbarOpts.verticalHasArrows, - horizontalHasArrows: configScrollbarOpts.horizontalHasArrows, - verticalScrollbarSize: configScrollbarOpts.verticalScrollbarSize, - verticalSliderSize: configScrollbarOpts.verticalSliderSize, - horizontalScrollbarSize: configScrollbarOpts.horizontalScrollbarSize, - horizontalSliderSize: configScrollbarOpts.horizontalSliderSize, - handleMouseWheel: configScrollbarOpts.handleMouseWheel, - arrowSize: configScrollbarOpts.arrowSize, - mouseWheelScrollSensitivity: configScrollbarOpts.mouseWheelScrollSensitivity, - fastScrollSensitivity: configScrollbarOpts.fastScrollSensitivity, + vertical: scrollbar.vertical, + horizontal: scrollbar.horizontal, + verticalHasArrows: scrollbar.verticalHasArrows, + horizontalHasArrows: scrollbar.horizontalHasArrows, + verticalScrollbarSize: scrollbar.verticalScrollbarSize, + verticalSliderSize: scrollbar.verticalSliderSize, + horizontalScrollbarSize: scrollbar.horizontalScrollbarSize, + horizontalSliderSize: scrollbar.horizontalSliderSize, + handleMouseWheel: scrollbar.handleMouseWheel, + arrowSize: scrollbar.arrowSize, + mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, + fastScrollSensitivity: fastScrollSensitivity, }; this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.scrollable)); @@ -96,11 +100,13 @@ export class EditorScrollbar extends ViewPart { } private _setLayout(): void { - const layoutInfo = this._context.configuration.editor.layoutInfo; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.scrollbarDomNode.setLeft(layoutInfo.contentLeft); - const side = this._context.configuration.editor.viewInfo.minimap.side; + const minimap = options.get(EditorOptionId.minimap); + const side = minimap.side; if (side === 'right') { this.scrollbarDomNode.setWidth(layoutInfo.contentWidth + layoutInfo.minimapWidth); } else { @@ -124,16 +130,23 @@ export class EditorScrollbar extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.viewInfo) { - const editor = this._context.configuration.editor; + if ( + e.hasChanged(EditorOptionId.scrollbar) + || e.hasChanged(EditorOptionId.mouseWheelScrollSensitivity) + || e.hasChanged(EditorOptionId.fastScrollSensitivity) + ) { + const options = this._context.configuration.options; + const scrollbar = options.get(EditorOptionId.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); const newOpts: ScrollableElementChangeOptions = { - handleMouseWheel: editor.viewInfo.scrollbar.handleMouseWheel, - mouseWheelScrollSensitivity: editor.viewInfo.scrollbar.mouseWheelScrollSensitivity, - fastScrollSensitivity: editor.viewInfo.scrollbar.fastScrollSensitivity + handleMouseWheel: scrollbar.handleMouseWheel, + mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, + fastScrollSensitivity: fastScrollSensitivity }; this.scrollbar.updateOptions(newOpts); } - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { this._setLayout(); } return true; diff --git a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts index 60c18790d0c..c063c668071 100644 --- a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts +++ b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts @@ -8,6 +8,7 @@ import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class DecorationToRender { _decorationToRenderBrand: void; @@ -84,10 +85,12 @@ export class GlyphMarginOverlay extends DedupOverlay { constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; - this._glyphMarginLeft = this._context.configuration.editor.layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = this._context.configuration.editor.layoutInfo.glyphMarginWidth; + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; this._renderResult = null; this._context.addEventHandler(this); } @@ -101,15 +104,18 @@ export class GlyphMarginOverlay extends DedupOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { + const options = this._context.configuration.options; + if (e.lineHeight) { this._lineHeight = this._context.configuration.editor.lineHeight; } if (e.viewInfo) { this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; } - if (e.layoutInfo) { - this._glyphMarginLeft = this._context.configuration.editor.layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = this._context.configuration.editor.layoutInfo.glyphMarginWidth; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; } return true; } diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index ea713746e0d..a8ba2a3936a 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -11,6 +11,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class IndentGuidesOverlay extends DynamicViewOverlay { @@ -27,11 +28,13 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { super(); this._context = context; this._primaryLineNumber = 0; + const options = this._context.configuration.options; this._lineHeight = this._context.configuration.editor.lineHeight; this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; - const wrappingColumn = this._context.configuration.editor.wrappingInfo.wrappingColumn; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); this._renderResult = null; @@ -48,6 +51,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { + const options = this._context.configuration.options; if (e.lineHeight) { this._lineHeight = this._context.configuration.editor.lineHeight; } @@ -58,8 +62,9 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; } - if (e.wrappingInfo || e.fontInfo) { - const wrappingColumn = this._context.configuration.editor.wrappingInfo.wrappingColumn; + if (e.hasChanged(EditorOptionId.wrappingInfo) || e.fontInfo) { + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } return true; diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index 2067c4d3878..d07bbdc92ae 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -41,13 +41,16 @@ export class LineNumbersOverlay extends DynamicViewOverlay { } private _readConfig(): void { + const options = this._context.configuration.options; const config = this._context.configuration.editor; this._lineHeight = config.lineHeight; - this._renderLineNumbers = config.viewInfo.renderLineNumbers; - this._renderCustomLineNumbers = config.viewInfo.renderCustomLineNumbers; - this._renderFinalNewline = this._context.configuration.getOption(EditorOptionId.renderFinalNewline); - this._lineNumbersLeft = config.layoutInfo.lineNumbersLeft; - this._lineNumbersWidth = config.layoutInfo.lineNumbersWidth; + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + this._renderLineNumbers = renderLineNumbers.renderType; + this._renderCustomLineNumbers = renderLineNumbers.renderFn; + this._renderFinalNewline = options.get(EditorOptionId.renderFinalNewline); + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._lineNumbersLeft = layoutInfo.lineNumbersLeft; + this._lineNumbersWidth = layoutInfo.lineNumbersWidth; } public dispose(): void { diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 580311d7691..2e64c0c8056 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -18,6 +18,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { Viewport } from 'vs/editor/common/viewModel/viewModel'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; class LastRenderedData { @@ -90,10 +91,12 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this.domNode = this._visibleLines.domNode; const conf = this._context.configuration; + const options = this._context.configuration.options; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); this._lineHeight = conf.editor.lineHeight; this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; - this._isViewportWrapping = conf.editor.wrappingInfo.isViewportWrapping; + this._isViewportWrapping = wrappingInfo.isViewportWrapping; this._revealHorizontalRightPadding = conf.editor.viewInfo.revealHorizontalRightPadding; this._scrollOff = conf.editor.viewInfo.cursorSurroundingLines; this._canUseLayerHinting = conf.editor.canUseLayerHinting; @@ -135,11 +138,12 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { this._visibleLines.onConfigurationChanged(e); - if (e.wrappingInfo) { + if (e.hasChanged(EditorOptionId.wrappingInfo)) { this._maxLineWidth = 0; } const conf = this._context.configuration; + const options = this._context.configuration.options; if (e.lineHeight) { this._lineHeight = conf.editor.lineHeight; @@ -147,8 +151,9 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, if (e.fontInfo) { this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; } - if (e.wrappingInfo) { - this._isViewportWrapping = conf.editor.wrappingInfo.isViewportWrapping; + if (e.hasChanged(EditorOptionId.wrappingInfo)) { + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + this._isViewportWrapping = wrappingInfo.isViewportWrapping; } if (e.viewInfo) { this._revealHorizontalRightPadding = conf.editor.viewInfo.revealHorizontalRightPadding; @@ -163,7 +168,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this._onOptionsMaybeChanged(); - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { this._maxLineWidth = 0; } diff --git a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts index fe764290bad..1d709f5b917 100644 --- a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts +++ b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts @@ -8,6 +8,7 @@ import { DecorationToRender, DedupOverlay } from 'vs/editor/browser/viewParts/gl import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class LinesDecorationsOverlay extends DedupOverlay { @@ -20,8 +21,10 @@ export class LinesDecorationsOverlay extends DedupOverlay { constructor(context: ViewContext) { super(); this._context = context; - this._decorationsLeft = this._context.configuration.editor.layoutInfo.decorationsLeft; - this._decorationsWidth = this._context.configuration.editor.layoutInfo.decorationsWidth; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._decorationsLeft = layoutInfo.decorationsLeft; + this._decorationsWidth = layoutInfo.decorationsWidth; this._renderResult = null; this._context.addEventHandler(this); } @@ -35,9 +38,11 @@ export class LinesDecorationsOverlay extends DedupOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.layoutInfo) { - this._decorationsLeft = this._context.configuration.editor.layoutInfo.decorationsLeft; - this._decorationsWidth = this._context.configuration.editor.layoutInfo.decorationsWidth; + const options = this._context.configuration.options; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._decorationsLeft = layoutInfo.decorationsLeft; + this._decorationsWidth = layoutInfo.decorationsWidth; } return true; } @@ -107,4 +112,4 @@ export class LinesDecorationsOverlay extends DedupOverlay { } return this._renderResult[lineNumber - startLineNumber]; } -} \ No newline at end of file +} diff --git a/src/vs/editor/browser/viewParts/margin/margin.ts b/src/vs/editor/browser/viewParts/margin/margin.ts index ab4f24c7bf3..f49a24845e7 100644 --- a/src/vs/editor/browser/viewParts/margin/margin.ts +++ b/src/vs/editor/browser/viewParts/margin/margin.ts @@ -8,6 +8,7 @@ import { ViewPart } from 'vs/editor/browser/view/viewPart'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class Margin extends ViewPart { @@ -23,10 +24,13 @@ export class Margin extends ViewPart { constructor(context: ViewContext) { super(context); + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; - this._glyphMarginLeft = this._context.configuration.editor.layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = this._context.configuration.editor.layoutInfo.glyphMarginWidth; + this._contentLeft = layoutInfo.contentLeft; + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; this._domNode = createFastDomNode(document.createElement('div')); this._domNode.setClassName(Margin.OUTER_CLASS_NAME); @@ -51,14 +55,17 @@ export class Margin extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { + const options = this._context.configuration.options; + if (e.canUseLayerHinting) { this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; } - if (e.layoutInfo) { - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; - this._glyphMarginLeft = this._context.configuration.editor.layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = this._context.configuration.editor.layoutInfo.glyphMarginWidth; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; } return true; diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index 1182f2ee8ab..747ef261830 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -13,7 +13,7 @@ import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ILine, RenderedLinesCollection } from 'vs/editor/browser/view/viewLayer'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; -import { RenderMinimap } from 'vs/editor/common/config/editorOptions'; +import { RenderMinimap, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { RGBA8 } from 'vs/editor/common/core/rgba'; import { IConfiguration, ScrollType } from 'vs/editor/common/editorCommon'; @@ -107,14 +107,16 @@ class MinimapOptions { public readonly canvasOuterHeight: number; constructor(configuration: IConfiguration) { + const options = configuration.options; const pixelRatio = configuration.editor.pixelRatio; - const layoutInfo = configuration.editor.layoutInfo; + const layoutInfo = options.get(EditorOptionId.layoutInfo); const viewInfo = configuration.editor.viewInfo; const fontInfo = configuration.editor.fontInfo; this.renderMinimap = layoutInfo.renderMinimap | 0; this.scrollBeyondLastLine = viewInfo.scrollBeyondLastLine; - this.showSlider = viewInfo.minimap.showSlider; + const minimapOpts = options.get(EditorOptionId.minimap); + this.showSlider = minimapOpts.showSlider; this.pixelRatio = pixelRatio; this.typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; this.lineHeight = configuration.editor.lineHeight; diff --git a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts index 87a35ca24f2..0fa9087323d 100644 --- a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts +++ b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts @@ -10,6 +10,7 @@ import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/v import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; interface IWidgetData { widget: IOverlayWidget; @@ -35,12 +36,15 @@ export class ViewOverlayWidgets extends ViewPart { constructor(context: ViewContext) { super(context); + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._widgets = {}; - this._verticalScrollbarWidth = this._context.configuration.editor.layoutInfo.verticalScrollbarWidth; - this._minimapWidth = this._context.configuration.editor.layoutInfo.minimapWidth; - this._horizontalScrollbarHeight = this._context.configuration.editor.layoutInfo.horizontalScrollbarHeight; - this._editorHeight = this._context.configuration.editor.layoutInfo.height; - this._editorWidth = this._context.configuration.editor.layoutInfo.width; + this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; + this._minimapWidth = layoutInfo.minimapWidth; + this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; + this._editorHeight = layoutInfo.height; + this._editorWidth = layoutInfo.width; this._domNode = createFastDomNode(document.createElement('div')); PartFingerprints.write(this._domNode, PartFingerprint.OverlayWidgets); @@ -59,12 +63,15 @@ export class ViewOverlayWidgets extends ViewPart { // ---- begin view event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.layoutInfo) { - this._verticalScrollbarWidth = this._context.configuration.editor.layoutInfo.verticalScrollbarWidth; - this._minimapWidth = this._context.configuration.editor.layoutInfo.minimapWidth; - this._horizontalScrollbarHeight = this._context.configuration.editor.layoutInfo.horizontalScrollbarHeight; - this._editorHeight = this._context.configuration.editor.layoutInfo.height; - this._editorWidth = this._context.configuration.editor.layoutInfo.width; + const options = this._context.configuration.options; + + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; + this._minimapWidth = layoutInfo.minimapWidth; + this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; + this._editorHeight = layoutInfo.height; + this._editorWidth = layoutInfo.width; return true; } return false; diff --git a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts index c186568ad8f..b620c0ed4ea 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts @@ -15,6 +15,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ITheme } from 'vs/platform/theme/common/themeService'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; class Settings { @@ -42,6 +43,7 @@ class Settings { public readonly w: number[]; constructor(config: IConfiguration, theme: ITheme) { + const options = config.options; this.lineHeight = config.editor.lineHeight; this.pixelRatio = config.editor.pixelRatio; this.overviewRulerLanes = config.editor.viewInfo.overviewRulerLanes; @@ -56,8 +58,9 @@ class Settings { this.themeType = theme.type; - const minimapEnabled = config.editor.viewInfo.minimap.enabled; - const minimapSide = config.editor.viewInfo.minimap.side; + const minimapOpts = options.get(EditorOptionId.minimap); + const minimapEnabled = minimapOpts.enabled; + const minimapSide = minimapOpts.side; const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : null); if (backgroundColor === null || minimapSide === 'left') { this.backgroundColor = null; @@ -65,7 +68,8 @@ class Settings { this.backgroundColor = Color.Format.CSS.formatHex(backgroundColor); } - const position = config.editor.layoutInfo.overviewRuler; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + const position = layoutInfo.overviewRuler; this.top = position.top; this.right = position.right; this.domWidth = position.width; diff --git a/src/vs/editor/browser/viewParts/rulers/rulers.ts b/src/vs/editor/browser/viewParts/rulers/rulers.ts index 7d4d402d24e..ceb396185fd 100644 --- a/src/vs/editor/browser/viewParts/rulers/rulers.ts +++ b/src/vs/editor/browser/viewParts/rulers/rulers.ts @@ -11,6 +11,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class Rulers extends ViewPart { @@ -37,7 +38,10 @@ export class Rulers extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.viewInfo || e.layoutInfo || e.fontInfo) { + if (e.viewInfo + || e.hasChanged(EditorOptionId.layoutInfo) + || e.fontInfo + ) { this._rulers = this._context.configuration.editor.viewInfo.rulers; this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; return true; diff --git a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts index 2ae336437e4..d3b4ae392cd 100644 --- a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts +++ b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts @@ -11,6 +11,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { scrollbarShadow } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export class ScrollDecorationViewPart extends ViewPart { @@ -27,7 +28,9 @@ export class ScrollDecorationViewPart extends ViewPart { this._width = 0; this._updateWidth(); this._shouldShow = false; - this._useShadows = this._context.configuration.editor.viewInfo.scrollbar.useShadows; + const options = this._context.configuration.options; + const scrollbar = options.get(EditorOptionId.scrollbar); + this._useShadows = scrollbar.useShadows; this._domNode = createFastDomNode(document.createElement('div')); this._domNode.setAttribute('role', 'presentation'); this._domNode.setAttribute('aria-hidden', 'true'); @@ -51,7 +54,8 @@ export class ScrollDecorationViewPart extends ViewPart { } private _updateWidth(): boolean { - const layoutInfo = this._context.configuration.editor.layoutInfo; + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); let newWidth = 0; if (layoutInfo.renderMinimap === 0 || (layoutInfo.minimapWidth > 0 && layoutInfo.minimapLeft === 0)) { newWidth = layoutInfo.width; @@ -69,10 +73,12 @@ export class ScrollDecorationViewPart extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { let shouldRender = false; - if (e.viewInfo) { - this._useShadows = this._context.configuration.editor.viewInfo.scrollbar.useShadows; + if (e.hasChanged(EditorOptionId.scrollbar)) { + const options = this._context.configuration.options; + const scrollbar = options.get(EditorOptionId.scrollbar); + this._useShadows = scrollbar.useShadows; } - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { shouldRender = this._updateWidth(); } return this._updateShouldShow() || shouldRender; @@ -99,4 +105,4 @@ registerThemingParticipant((theme, collector) => { if (shadow) { collector.addRule(`.monaco-editor .scroll-decoration { box-shadow: ${shadow} 0 6px 6px -6px inset; }`); } -}); \ No newline at end of file +}); diff --git a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts index 6c01df4e0b6..3e0f58f5475 100644 --- a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts +++ b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts @@ -12,6 +12,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { IViewWhitespaceViewportData } from 'vs/editor/common/viewModel/viewModel'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IMyViewZone { whitespaceId: string; @@ -40,9 +41,12 @@ export class ViewZones extends ViewPart { constructor(context: ViewContext) { super(context); + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._lineHeight = this._context.configuration.editor.lineHeight; - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; + this._contentLeft = layoutInfo.contentLeft; this.domNode = createFastDomNode(document.createElement('div')); this.domNode.setClassName('view-zones'); @@ -84,15 +88,17 @@ export class ViewZones extends ViewPart { } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { + const options = this._context.configuration.options; if (e.lineHeight) { this._lineHeight = this._context.configuration.editor.lineHeight; return this._recomputeWhitespacesProps(); } - if (e.layoutInfo) { - this._contentWidth = this._context.configuration.editor.layoutInfo.contentWidth; - this._contentLeft = this._context.configuration.editor.layoutInfo.contentLeft; + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._contentWidth = layoutInfo.contentWidth; + this._contentLeft = layoutInfo.contentLeft; } return true; diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 3860def914f..ca2133d8ab2 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -259,8 +259,10 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._register(this._configuration.onDidChange((e) => { this._onDidChangeConfiguration.fire(e); - if (e.layoutInfo) { - this._onDidLayoutChange.fire(this._configuration.editor.layoutInfo); + if (e.hasChanged(editorOptions.EditorOptionId.layoutInfo)) { + const options = this._configuration.options; + const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); + this._onDidLayoutChange.fire(layoutInfo); } if (this._configuration.editor.showUnused) { this._domElement.classList.add(SHOW_UNUSED_ENABLED_CLASS); @@ -370,8 +372,12 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE return this._configuration.editor; } + public getOptions(): editorOptions.IComputedEditorOptions { + return this._configuration.options; + } + public getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue { - return this._configuration.getOption(id); + return this._configuration.options.get(id); } public getRawConfiguration(): editorOptions.IEditorOptions { @@ -1124,7 +1130,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE } public getLayoutInfo(): editorOptions.EditorLayoutInfo { - return this._configuration.editor.layoutInfo; + const options = this._configuration.options; + const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); + return layoutInfo; } public createOverviewRuler(cssClassName: string): editorBrowser.IOverviewRuler | null { @@ -1272,7 +1280,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE } const position = this._modelData.model.validatePosition(rawPosition); - const layoutInfo = this._configuration.editor.layoutInfo; + const options = this._configuration.options; + const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); const top = CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, position.lineNumber, position.column) - this.getScrollTop(); const left = this._modelData.view.getOffsetForColumn(position.lineNumber, position.column) + layoutInfo.glyphMarginWidth + layoutInfo.lineNumbersWidth + layoutInfo.decorationsWidth - this.getScrollLeft(); diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index fa0e688d696..da9e1ddf553 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -1947,6 +1947,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { private readonly originalModel: ITextModel; private readonly modifiedEditorConfiguration: editorOptions.InternalEditorOptions; + private readonly modifiedEditorOptions: editorOptions.IComputedEditorOptions; private readonly modifiedEditorTabSize: number; private readonly renderIndicators: boolean; @@ -1954,6 +1955,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { super(lineChanges, originalForeignVZ, modifiedForeignVZ); this.originalModel = originalEditor.getModel()!; this.modifiedEditorConfiguration = modifiedEditor.getConfiguration(); + this.modifiedEditorOptions = modifiedEditor.getOptions(); this.modifiedEditorTabSize = modifiedEditor.getModel()!.getOptions().tabSize; this.renderIndicators = renderIndicators; } @@ -1993,7 +1995,9 @@ class InlineViewZonesComputer extends ViewZonesComputer { let sb = createStringBuilder(10000); let marginHTML: string[] = []; - let lineDecorationsWidth = this.modifiedEditorConfiguration.layoutInfo.decorationsWidth; + const layoutInfo = this.modifiedEditorOptions.get(editorOptions.EditorOptionId.layoutInfo); + const lineDecorationsWidth = layoutInfo.decorationsWidth; + let lineHeight = this.modifiedEditorConfiguration.lineHeight; const typicalHalfwidthCharacterWidth = this.modifiedEditorConfiguration.fontInfo.typicalHalfwidthCharacterWidth; let maxCharsPerLine = 0; diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index 037883dd530..f6ab9ce2f14 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -525,7 +525,9 @@ export class DiffReview extends Disposable { private _render(): void { const originalOpts = this._diffEditor.getOriginalEditor().getConfiguration(); + const originalOptions = this._diffEditor.getOriginalEditor().getOptions(); const modifiedOpts = this._diffEditor.getModifiedEditor().getConfiguration(); + const modifiedOptions = this._diffEditor.getModifiedEditor().getOptions(); const originalModel = this._diffEditor.getOriginalEditor().getModel(); const modifiedModel = this._diffEditor.getModifiedEditor().getModel(); @@ -620,7 +622,7 @@ export class DiffReview extends Disposable { let modLine = minModifiedLine; for (let i = 0, len = diffs.length; i < len; i++) { const diffEntry = diffs[i]; - DiffReview._renderSection(container, diffEntry, modLine, this._width, originalOpts, originalModel, originalModelOpts, modifiedOpts, modifiedModel, modifiedModelOpts); + DiffReview._renderSection(container, diffEntry, modLine, this._width, originalOpts, originalOptions, originalModel, originalModelOpts, modifiedOpts, modifiedOptions, modifiedModel, modifiedModelOpts); if (diffEntry.modifiedLineStart !== 0) { modLine = diffEntry.modifiedLineEnd; } @@ -633,8 +635,8 @@ export class DiffReview extends Disposable { private static _renderSection( dest: HTMLElement, diffEntry: DiffEntry, modLine: number, width: number, - originalOpts: editorOptions.InternalEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, - modifiedOpts: editorOptions.InternalEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions + originalOpts: editorOptions.InternalEditorOptions, originalOptions: editorOptions.IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, + modifiedOpts: editorOptions.InternalEditorOptions, modifiedOptions: editorOptions.IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions ): void { const type = diffEntry.getType(); @@ -665,8 +667,11 @@ export class DiffReview extends Disposable { originalLineEnd - originalLineStart ); - const originalLineNumbersWidth = originalOpts.layoutInfo.glyphMarginWidth + originalOpts.layoutInfo.lineNumbersWidth; - const modifiedLineNumbersWidth = 10 + modifiedOpts.layoutInfo.glyphMarginWidth + modifiedOpts.layoutInfo.lineNumbersWidth; + const originalLayoutInfo = originalOptions.get(editorOptions.EditorOptionId.layoutInfo); + const originalLineNumbersWidth = originalLayoutInfo.glyphMarginWidth + originalLayoutInfo.lineNumbersWidth; + + const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOptionId.layoutInfo); + const modifiedLineNumbersWidth = 10 + modifiedLayoutInfo.glyphMarginWidth + modifiedLayoutInfo.lineNumbersWidth; for (let i = 0; i <= cnt; i++) { const originalLine = (originalLineStart === 0 ? 0 : originalLineStart + i); diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 10fff300995..a5dc25319e2 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -95,7 +95,7 @@ export class EditorConfiguration2 { // console.log(`computeOptions`, options, env); const result = new editorOptions.ComputedEditorOptions(); for (const editorOption of editorOptions.editorOptionsRegistry) { - result._write(editorOption.id, editorOption.compute(options._read(editorOption.id))); + result._write(editorOption.id, editorOption.compute(env, result, options._read(editorOption.id))); } return result; } @@ -105,9 +105,9 @@ export class EditorConfiguration2 { const result = new editorOptions.ChangedEditorOptions(); let somethingChanged = false; for (const editorOption of editorOptions.editorOptionsRegistry) { - const equals = editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); - result._write(editorOption.id, equals); - if (!equals) { + const changed = !editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); + result._write(editorOption.id, changed); + if (changed) { somethingChanged = true; } } @@ -115,6 +115,25 @@ export class EditorConfiguration2 { } } +/** + * Compatibility with old options + */ +function migrateOptions(options: editorOptions.IEditorOptions): void { + let wordWrap = options.wordWrap; + if (wordWrap === true) { + options.wordWrap = 'on'; + } else if (wordWrap === false) { + options.wordWrap = 'off'; + } + + let lineNumbers = options.lineNumbers; + if (lineNumbers === true) { + options.lineNumbers = 'on'; + } else if (lineNumbers === false) { + options.lineNumbers = 'off'; + } +} + export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { public readonly isSimpleWidget: boolean; @@ -133,6 +152,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed constructor(isSimpleWidget: boolean, options: editorOptions.IEditorOptions) { super(); + migrateOptions(options); this.isSimpleWidget = isSimpleWidget; @@ -156,10 +176,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions())); } - public getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue { - return this.options._read(id); - } - public observeReferenceElement(dimension?: editorCommon.IDimension): void { } @@ -255,6 +271,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed if (typeof newOptions === 'undefined') { return; } + migrateOptions(newOptions); if (CommonEditorConfiguration._subsetEquals(this._rawOptions, newOptions)) { return; } @@ -417,29 +434,29 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.minimap.enabled': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.minimap.enabled, + 'default': editorOptions.EditorOption.minimap.defaultValue.enabled, 'description': nls.localize('minimap.enabled', "Controls whether the minimap is shown.") }, 'editor.minimap.side': { 'type': 'string', 'enum': ['left', 'right'], - 'default': EDITOR_DEFAULTS.viewInfo.minimap.side, + 'default': editorOptions.EditorOption.minimap.defaultValue.side, 'description': nls.localize('minimap.side', "Controls the side where to render the minimap.") }, 'editor.minimap.showSlider': { 'type': 'string', 'enum': ['always', 'mouseover'], - 'default': EDITOR_DEFAULTS.viewInfo.minimap.showSlider, + 'default': editorOptions.EditorOption.minimap.defaultValue.showSlider, 'description': nls.localize('minimap.showSlider', "Controls whether the minimap slider is automatically hidden.") }, 'editor.minimap.renderCharacters': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.minimap.renderCharacters, + 'default': editorOptions.EditorOption.minimap.defaultValue.renderCharacters, 'description': nls.localize('minimap.renderCharacters', "Render the actual characters on a line as opposed to color blocks.") }, 'editor.minimap.maxColumn': { 'type': 'number', - 'default': EDITOR_DEFAULTS.viewInfo.minimap.maxColumn, + 'default': editorOptions.EditorOption.minimap.defaultValue.maxColumn, 'description': nls.localize('minimap.maxColumn', "Limit the width of the minimap to render at most a certain number of columns.") }, 'editor.hover.enabled': { @@ -498,7 +515,7 @@ const editorConfiguration: IConfigurationNode = { ] }, "Lines will wrap at the minimum of viewport and `#editor.wordWrapColumn#`."), ], - 'default': EDITOR_DEFAULTS.wordWrap, + 'default': editorOptions.EditorOption.wordWrap.defaultValue, 'description': nls.localize({ key: 'wordWrap', comment: [ @@ -509,7 +526,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.wordWrapColumn': { 'type': 'integer', - 'default': EDITOR_DEFAULTS.wordWrapColumn, + 'default': editorOptions.EditorOption.wordWrapColumn.defaultValue, 'minimum': 1, 'markdownDescription': nls.localize({ key: 'wordWrapColumn', @@ -533,12 +550,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.mouseWheelScrollSensitivity': { 'type': 'number', - 'default': EDITOR_DEFAULTS.viewInfo.scrollbar.mouseWheelScrollSensitivity, + 'default': editorOptions.EditorOption.mouseWheelScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.") }, 'editor.fastScrollSensitivity': { 'type': 'number', - 'default': EDITOR_DEFAULTS.viewInfo.scrollbar.fastScrollSensitivity, + 'default': editorOptions.EditorOption.fastScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('fastScrollSensitivity', "Scrolling speed multiplier when pressing `Alt`.") }, 'editor.multiCursorModifier': { @@ -1035,7 +1052,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.folding': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.folding, + 'default': editorOptions.EditorOption.folding.defaultValue, 'description': nls.localize('folding', "Controls whether the editor has code folding enabled.") }, 'editor.foldingStrategy': { @@ -1088,7 +1105,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('accessibilitySupport.on', "The editor will be permanently optimized for usage with a Screen Reader."), nls.localize('accessibilitySupport.off', "The editor will never be optimized for usage with a Screen Reader."), ], - 'default': EDITOR_DEFAULTS.accessibilitySupport, + 'default': editorOptions.EditorOption.accessibilitySupport.defaultValue, 'description': nls.localize('accessibilitySupport', "Controls whether the editor should run in a mode where it is optimized for screen readers.") }, 'editor.showUnused': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 45bef3115da..dc915f4f80b 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; +import * as assert from 'vs/base/common/assert'; import * as arrays from 'vs/base/common/arrays'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; @@ -272,7 +273,7 @@ export interface IEditorOptions { * Otherwise, line numbers will not be rendered. * Defaults to true. */ - lineNumbers?: 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); + lineNumbers?: LineNumbersType; /** * Controls the minimal number of visible leading and trailing lines surrounding the cursor. * Defaults to 0. @@ -451,7 +452,7 @@ export interface IEditorOptions { * Control indentation of wrapped lines. Can be: 'none', 'same', 'indent' or 'deepIndent'. * Defaults to 'same' in vscode and to 'none' in monaco-editor. */ - wrappingIndent?: string; + wrappingIndent?: 'none' | 'same' | 'indent' | 'deepIndent'; /** * Configure word wrapping characters. A break will be introduced before these characters. * Defaults to '{([+'. @@ -727,6 +728,9 @@ export interface IEditorOptions { * Controls fading out of unused variables. */ showUnused?: boolean; + + layoutInfo?: undefined; + wrappingInfo?: undefined; } /** @@ -909,30 +913,6 @@ function _cursorStyleFromString(cursorStyle: string | undefined, defaultValue: T return TextEditorCursorStyle.Line; } -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; - readonly mouseWheelScrollSensitivity: number; - readonly fastScrollSensitivity: number; -} - -export interface InternalEditorMinimapOptions { - readonly enabled: boolean; - readonly side: 'right' | 'left'; - readonly showSlider: 'always' | 'mouseover'; - readonly renderCharacters: boolean; - readonly maxColumn: number; -} - export interface InternalEditorFindOptions { readonly seedSearchStringFromSelection: boolean; readonly autoFindInSelection: boolean; @@ -969,33 +949,10 @@ export interface InternalParameterHintOptions { readonly cycle: boolean; } -export interface EditorWrappingInfo { - readonly inDiffEditor: boolean; - readonly isDominatedByLongLines: boolean; - readonly isWordWrapMinified: boolean; - readonly isViewportWrapping: boolean; - readonly wrappingColumn: number; - readonly wrappingIndent: WrappingIndent; - readonly wordWrapBreakBeforeCharacters: string; - readonly wordWrapBreakAfterCharacters: string; - readonly wordWrapBreakObtrusiveCharacters: string; -} - -export const enum RenderLineNumbersType { - Off = 0, - On = 1, - Relative = 2, - Interval = 3, - Custom = 4 -} - export interface InternalEditorViewOptions { readonly extraEditorClassName: string; readonly disableMonospaceOptimizations: boolean; readonly rulers: number[]; - readonly ariaLabel: string; - readonly renderLineNumbers: RenderLineNumbersType; - readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; @@ -1018,8 +975,6 @@ export interface InternalEditorViewOptions { readonly renderIndentGuides: boolean; readonly highlightActiveIndentGuide: boolean; readonly renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; - readonly scrollbar: InternalEditorScrollbarOptions; - readonly minimap: InternalEditorMinimapOptions; readonly fixedOverflowWidgets: boolean; } @@ -1045,7 +1000,6 @@ export interface EditorContribOptions { readonly selectionHighlight: boolean; readonly occurrencesHighlight: boolean; readonly codeLens: boolean; - readonly folding: boolean; readonly foldingStrategy: 'auto' | 'indentation'; readonly showFoldingControls: 'always' | 'mouseover'; readonly matchBrackets: boolean; @@ -1062,21 +1016,12 @@ export interface EditorContribOptions { * @internal */ export interface IValidatedEditorOptions { - readonly inDiffEditor: boolean; readonly wordSeparators: string; - readonly lineNumbersMinChars: number; readonly lineDecorationsWidth: number | string; readonly readOnly: boolean; readonly mouseStyle: 'text' | 'default' | 'copy'; readonly disableLayerHinting: boolean; readonly automaticLayout: boolean; - readonly wordWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded'; - readonly wordWrapColumn: number; - readonly wordWrapMinified: boolean; - readonly wrappingIndent: WrappingIndent; - readonly wordWrapBreakBeforeCharacters: string; - readonly wordWrapBreakAfterCharacters: string; - readonly wordWrapBreakObtrusiveCharacters: string; readonly autoClosingBrackets: EditorAutoClosingStrategy; readonly autoClosingQuotes: EditorAutoClosingStrategy; readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy; @@ -1088,7 +1033,6 @@ export interface IValidatedEditorOptions { readonly useTabStops: boolean; readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; readonly multiCursorMergeOverlapping: boolean; - readonly accessibilitySupport: 'auto' | 'off' | 'on'; readonly showUnused: boolean; readonly viewInfo: InternalEditorViewOptions; @@ -1128,10 +1072,8 @@ export class InternalEditorOptions { readonly copyWithSyntaxHighlighting: boolean; // ---- grouped options - readonly layoutInfo: EditorLayoutInfo; readonly fontInfo: FontInfo; readonly viewInfo: InternalEditorViewOptions; - readonly wrappingInfo: EditorWrappingInfo; readonly contribInfo: EditorContribOptions; /** @@ -1143,7 +1085,6 @@ export class InternalEditorOptions { editorClassName: string; lineHeight: number; readOnly: boolean; - accessibilitySupport: AccessibilitySupport; multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; multiCursorMergeOverlapping: boolean; wordSeparators: string; @@ -1157,10 +1098,8 @@ export class InternalEditorOptions { dragAndDrop: boolean; emptySelectionClipboard: boolean; copyWithSyntaxHighlighting: boolean; - layoutInfo: EditorLayoutInfo; fontInfo: FontInfo; viewInfo: InternalEditorViewOptions; - wrappingInfo: EditorWrappingInfo; contribInfo: EditorContribOptions; showUnused: boolean; }) { @@ -1169,7 +1108,6 @@ export class InternalEditorOptions { this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight | 0; this.readOnly = source.readOnly; - this.accessibilitySupport = source.accessibilitySupport; this.multiCursorModifier = source.multiCursorModifier; this.multiCursorMergeOverlapping = source.multiCursorMergeOverlapping; this.wordSeparators = source.wordSeparators; @@ -1183,10 +1121,8 @@ export class InternalEditorOptions { this.dragAndDrop = source.dragAndDrop; this.emptySelectionClipboard = source.emptySelectionClipboard; this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; - this.layoutInfo = source.layoutInfo; this.fontInfo = source.fontInfo; this.viewInfo = source.viewInfo; - this.wrappingInfo = source.wrappingInfo; this.contribInfo = source.contribInfo; this.showUnused = source.showUnused; } @@ -1201,7 +1137,6 @@ export class InternalEditorOptions { && this.editorClassName === other.editorClassName && this.lineHeight === other.lineHeight && this.readOnly === other.readOnly - && this.accessibilitySupport === other.accessibilitySupport && this.multiCursorModifier === other.multiCursorModifier && this.multiCursorMergeOverlapping === other.multiCursorMergeOverlapping && this.wordSeparators === other.wordSeparators @@ -1216,10 +1151,8 @@ export class InternalEditorOptions { && this.showUnused === other.showUnused && this.emptySelectionClipboard === other.emptySelectionClipboard && this.copyWithSyntaxHighlighting === other.copyWithSyntaxHighlighting - && InternalEditorOptions._equalsLayoutInfo(this.layoutInfo, other.layoutInfo) && this.fontInfo.equals(other.fontInfo) && InternalEditorOptions._equalsViewOptions(this.viewInfo, other.viewInfo) - && InternalEditorOptions._equalsWrappingInfo(this.wrappingInfo, other.wrappingInfo) && InternalEditorOptions._equalsContribOptions(this.contribInfo, other.contribInfo) ); } @@ -1240,7 +1173,6 @@ export class InternalEditorOptions { editorClassName: (this.editorClassName !== newOpts.editorClassName), lineHeight: (this.lineHeight !== newOpts.lineHeight), readOnly: (this.readOnly !== newOpts.readOnly), - accessibilitySupport: (this.accessibilitySupport !== newOpts.accessibilitySupport), multiCursorModifier: (this.multiCursorModifier !== newOpts.multiCursorModifier), multiCursorMergeOverlapping: (this.multiCursorMergeOverlapping !== newOpts.multiCursorMergeOverlapping), wordSeparators: (this.wordSeparators !== newOpts.wordSeparators), @@ -1254,55 +1186,12 @@ export class InternalEditorOptions { dragAndDrop: (this.dragAndDrop !== newOpts.dragAndDrop), emptySelectionClipboard: (this.emptySelectionClipboard !== newOpts.emptySelectionClipboard), copyWithSyntaxHighlighting: (this.copyWithSyntaxHighlighting !== newOpts.copyWithSyntaxHighlighting), - layoutInfo: (!InternalEditorOptions._equalsLayoutInfo(this.layoutInfo, newOpts.layoutInfo)), fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)), viewInfo: (!InternalEditorOptions._equalsViewOptions(this.viewInfo, newOpts.viewInfo)), - wrappingInfo: (!InternalEditorOptions._equalsWrappingInfo(this.wrappingInfo, newOpts.wrappingInfo)), contribInfo: (!InternalEditorOptions._equalsContribOptions(this.contribInfo, newOpts.contribInfo)) }; } - /** - * @internal - */ - private static _equalsLayoutInfo(a: EditorLayoutInfo, b: EditorLayoutInfo): boolean { - return ( - a.width === b.width - && a.height === b.height - && a.glyphMarginLeft === b.glyphMarginLeft - && a.glyphMarginWidth === b.glyphMarginWidth - && a.glyphMarginHeight === b.glyphMarginHeight - && a.lineNumbersLeft === b.lineNumbersLeft - && a.lineNumbersWidth === b.lineNumbersWidth - && a.lineNumbersHeight === b.lineNumbersHeight - && a.decorationsLeft === b.decorationsLeft - && a.decorationsWidth === b.decorationsWidth - && a.decorationsHeight === b.decorationsHeight - && a.contentLeft === b.contentLeft - && a.contentWidth === b.contentWidth - && a.contentHeight === b.contentHeight - && a.renderMinimap === b.renderMinimap - && a.minimapLeft === b.minimapLeft - && a.minimapWidth === b.minimapWidth - && a.viewportColumn === b.viewportColumn - && a.verticalScrollbarWidth === b.verticalScrollbarWidth - && a.horizontalScrollbarHeight === b.horizontalScrollbarHeight - && this._equalsOverviewRuler(a.overviewRuler, b.overviewRuler) - ); - } - - /** - * @internal - */ - private static _equalsOverviewRuler(a: OverviewRulerPosition, b: OverviewRulerPosition): boolean { - return ( - a.width === b.width - && a.height === b.height - && a.top === b.top - && a.right === b.right - ); - } - /** * @internal */ @@ -1311,9 +1200,6 @@ export class InternalEditorOptions { a.extraEditorClassName === b.extraEditorClassName && a.disableMonospaceOptimizations === b.disableMonospaceOptimizations && arrays.equals(a.rulers, b.rulers) - && a.ariaLabel === b.ariaLabel - && a.renderLineNumbers === b.renderLineNumbers - && a.renderCustomLineNumbers === b.renderCustomLineNumbers && a.cursorSurroundingLines === b.cursorSurroundingLines && a.glyphMargin === b.glyphMargin && a.revealHorizontalRightPadding === b.revealHorizontalRightPadding @@ -1336,46 +1222,10 @@ export class InternalEditorOptions { && a.renderIndentGuides === b.renderIndentGuides && a.highlightActiveIndentGuide === b.highlightActiveIndentGuide && a.renderLineHighlight === b.renderLineHighlight - && this._equalsScrollbarOptions(a.scrollbar, b.scrollbar) - && this._equalsMinimapOptions(a.minimap, b.minimap) && a.fixedOverflowWidgets === b.fixedOverflowWidgets ); } - /** - * @internal - */ - private static _equalsScrollbarOptions(a: InternalEditorScrollbarOptions, b: InternalEditorScrollbarOptions): boolean { - return ( - a.arrowSize === b.arrowSize - && a.vertical === b.vertical - && a.horizontal === b.horizontal - && a.useShadows === b.useShadows - && a.verticalHasArrows === b.verticalHasArrows - && a.horizontalHasArrows === b.horizontalHasArrows - && a.handleMouseWheel === b.handleMouseWheel - && a.horizontalScrollbarSize === b.horizontalScrollbarSize - && a.horizontalSliderSize === b.horizontalSliderSize - && a.verticalScrollbarSize === b.verticalScrollbarSize - && a.verticalSliderSize === b.verticalSliderSize - && a.mouseWheelScrollSensitivity === b.mouseWheelScrollSensitivity - && a.fastScrollSensitivity === b.fastScrollSensitivity - ); - } - - /** - * @internal - */ - private static _equalsMinimapOptions(a: InternalEditorMinimapOptions, b: InternalEditorMinimapOptions): boolean { - return ( - a.enabled === b.enabled - && a.side === b.side - && a.showSlider === b.showSlider - && a.renderCharacters === b.renderCharacters - && a.maxColumn === b.maxColumn - ); - } - /** * @internal */ @@ -1439,23 +1289,6 @@ export class InternalEditorOptions { } } - /** - * @internal - */ - private static _equalsWrappingInfo(a: EditorWrappingInfo, b: EditorWrappingInfo): boolean { - return ( - a.inDiffEditor === b.inDiffEditor - && a.isDominatedByLongLines === b.isDominatedByLongLines - && a.isWordWrapMinified === b.isWordWrapMinified - && a.isViewportWrapping === b.isViewportWrapping - && a.wrappingColumn === b.wrappingColumn - && a.wrappingIndent === b.wrappingIndent - && a.wordWrapBreakBeforeCharacters === b.wordWrapBreakBeforeCharacters - && a.wordWrapBreakAfterCharacters === b.wordWrapBreakAfterCharacters - && a.wordWrapBreakObtrusiveCharacters === b.wordWrapBreakObtrusiveCharacters - ); - } - /** * @internal */ @@ -1482,7 +1315,6 @@ export class InternalEditorOptions { && a.selectionHighlight === b.selectionHighlight && a.occurrencesHighlight === b.occurrencesHighlight && a.codeLens === b.codeLens - && a.folding === b.folding && a.foldingStrategy === b.foldingStrategy && a.showFoldingControls === b.showFoldingControls && a.matchBrackets === b.matchBrackets @@ -1512,6 +1344,1012 @@ export class InternalEditorOptions { } } +/** + * An event describing that the configuration of the editor has changed. + */ +export interface IConfigurationChangedEvent { + hasChanged(id: EditorOptionId): boolean; + readonly canUseLayerHinting: boolean; + readonly pixelRatio: boolean; + readonly editorClassName: boolean; + readonly lineHeight: boolean; + readonly readOnly: boolean; + readonly multiCursorModifier: boolean; + readonly multiCursorMergeOverlapping: boolean; + readonly wordSeparators: boolean; + readonly autoClosingBrackets: boolean; + readonly autoClosingQuotes: boolean; + readonly autoClosingOvertype: boolean; + readonly autoSurround: boolean; + readonly autoIndent: boolean; + readonly useTabStops: boolean; + readonly tabFocusMode: boolean; + readonly dragAndDrop: boolean; + readonly emptySelectionClipboard: boolean; + readonly copyWithSyntaxHighlighting: boolean; + readonly fontInfo: boolean; + readonly viewInfo: boolean; + readonly contribInfo: boolean; +} + +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; +} + +function _boolean(value: any, defaultValue: T): boolean | T { + if (typeof value === 'undefined') { + return defaultValue; + } + if (value === 'false') { + // treat the string 'false' as false + return false; + } + return Boolean(value); +} + +function _booleanMap(value: { [key: string]: boolean } | undefined, defaultValue: { [key: string]: boolean }): { [key: string]: boolean } { + if (!value) { + return defaultValue; + } + + const out = Object.create(null); + for (const k of Object.keys(value)) { + const v = value[k]; + if (typeof v === 'boolean') { + out[k] = v; + } + } + return out; +} + +function _string(value: any, defaultValue: string): string { + if (typeof value !== 'string') { + return defaultValue; + } + return value; +} + +function _stringSet(value: T | undefined, defaultValue: T, allowedValues: T[]): T { + if (typeof value !== 'string') { + return defaultValue; + } + if (allowedValues.indexOf(value) === -1) { + return defaultValue; + } + return value; +} + +function _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; +} + +function _float(value: any, defaultValue: number): number { + let r = parseFloat(value); + if (isNaN(r)) { + r = defaultValue; + } + return r; +} + +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; + } +} + +function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string | undefined, defaultValue: TextEditorCursorBlinkingStyle): TextEditorCursorBlinkingStyle { + if (typeof cursorBlinkingStyle !== 'string') { + return defaultValue; + } + switch (cursorBlinkingStyle) { + case 'blink': + return TextEditorCursorBlinkingStyle.Blink; + case 'smooth': + return TextEditorCursorBlinkingStyle.Smooth; + case 'phase': + return TextEditorCursorBlinkingStyle.Phase; + case 'expand': + return TextEditorCursorBlinkingStyle.Expand; + case 'visible': // maintain compatibility + case 'solid': + return TextEditorCursorBlinkingStyle.Solid; + } + return TextEditorCursorBlinkingStyle.Blink; +} + +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; + } +} + +/** + * @internal + */ +export class EditorOptionsValidator { + + /** + * Validate raw editor options. + * i.e. since they can be defined by the user, they might be invalid. + */ + public static validate(opts: IEditorOptions, defaults: IValidatedEditorOptions): IValidatedEditorOptions { + const viewInfo = this._sanitizeViewInfo(opts, defaults.viewInfo); + const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo); + + let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey' | undefined = undefined; + if (typeof opts.multiCursorModifier === 'string') { + if (opts.multiCursorModifier === 'ctrlCmd') { + configuredMulticursorModifier = platform.isMacintosh ? 'metaKey' : 'ctrlKey'; + } else { + configuredMulticursorModifier = 'altKey'; + } + } + const multiCursorModifier = _stringSet<'altKey' | 'metaKey' | 'ctrlKey'>(configuredMulticursorModifier, defaults.multiCursorModifier, ['altKey', 'metaKey', 'ctrlKey']); + + let autoClosingBrackets: EditorAutoClosingStrategy; + let autoClosingQuotes: EditorAutoClosingStrategy; + let autoSurround: EditorAutoSurroundStrategy; + if (typeof opts.autoClosingBrackets === 'boolean' && opts.autoClosingBrackets === false) { + // backwards compatibility: disable all on boolean false + autoClosingBrackets = 'never'; + autoClosingQuotes = 'never'; + autoSurround = 'never'; + } else { + autoClosingBrackets = _stringSet(opts.autoClosingBrackets, defaults.autoClosingBrackets, ['always', 'languageDefined', 'beforeWhitespace', 'never']); + autoClosingQuotes = _stringSet(opts.autoClosingQuotes, defaults.autoClosingQuotes, ['always', 'languageDefined', 'beforeWhitespace', 'never']); + autoSurround = _stringSet(opts.autoSurround, defaults.autoSurround, ['languageDefined', 'brackets', 'quotes', 'never']); + } + + return { + wordSeparators: _string(opts.wordSeparators, defaults.wordSeparators), + lineDecorationsWidth: (typeof opts.lineDecorationsWidth === 'undefined' ? defaults.lineDecorationsWidth : opts.lineDecorationsWidth), + readOnly: _boolean(opts.readOnly, defaults.readOnly), + mouseStyle: _stringSet<'text' | 'default' | 'copy'>(opts.mouseStyle, defaults.mouseStyle, ['text', 'default', 'copy']), + disableLayerHinting: _boolean(opts.disableLayerHinting, defaults.disableLayerHinting), + automaticLayout: _boolean(opts.automaticLayout, defaults.automaticLayout), + autoClosingBrackets, + autoClosingQuotes, + autoClosingOvertype: _stringSet(opts.autoClosingOvertype, defaults.autoClosingOvertype, ['always', 'auto', 'never']), + autoSurround, + autoIndent: _boolean(opts.autoIndent, defaults.autoIndent), + dragAndDrop: _boolean(opts.dragAndDrop, defaults.dragAndDrop), + emptySelectionClipboard: _boolean(opts.emptySelectionClipboard, defaults.emptySelectionClipboard), + copyWithSyntaxHighlighting: _boolean(opts.copyWithSyntaxHighlighting, defaults.copyWithSyntaxHighlighting), + useTabStops: _boolean(opts.useTabStops, defaults.useTabStops), + multiCursorModifier: multiCursorModifier, + multiCursorMergeOverlapping: _boolean(opts.multiCursorMergeOverlapping, defaults.multiCursorMergeOverlapping), + showUnused: _boolean(opts.showUnused, defaults.showUnused), + viewInfo: viewInfo, + contribInfo: contribInfo, + }; + } + + private static _sanitizeFindOpts(opts: IEditorFindOptions | undefined, defaults: InternalEditorFindOptions): InternalEditorFindOptions { + if (typeof opts !== 'object') { + return defaults; + } + + return { + seedSearchStringFromSelection: _boolean(opts.seedSearchStringFromSelection, defaults.seedSearchStringFromSelection), + autoFindInSelection: _boolean(opts.autoFindInSelection, defaults.autoFindInSelection), + globalFindClipboard: _boolean(opts.globalFindClipboard, defaults.globalFindClipboard), + addExtraSpaceOnTop: _boolean(opts.addExtraSpaceOnTop, defaults.addExtraSpaceOnTop) + }; + } + + private static _sanitizeParameterHintOpts(opts: IEditorParameterHintOptions | undefined, defaults: InternalParameterHintOptions): InternalParameterHintOptions { + if (typeof opts !== 'object') { + return defaults; + } + + return { + enabled: _boolean(opts.enabled, defaults.enabled), + cycle: _boolean(opts.cycle, defaults.cycle) + }; + } + + private static _sanitizeHoverOpts(_opts: boolean | IEditorHoverOptions | undefined, defaults: InternalEditorHoverOptions): InternalEditorHoverOptions { + let opts: IEditorHoverOptions; + if (typeof _opts === 'boolean') { + opts = { + enabled: _opts + }; + } else if (typeof _opts === 'object') { + opts = _opts; + } else { + return defaults; + } + + return { + enabled: _boolean(opts.enabled, defaults.enabled), + delay: _clampedInt(opts.delay, defaults.delay, 0, 10000), + sticky: _boolean(opts.sticky, defaults.sticky) + }; + } + + private static _sanitizeSuggestOpts(opts: IEditorOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { + const suggestOpts = opts.suggest || {}; + return { + filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful), + snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), + snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful), + localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus), + shareSuggestSelections: _boolean(suggestOpts.shareSuggestSelections, defaults.shareSuggestSelections), + showIcons: _boolean(suggestOpts.showIcons, defaults.showIcons), + maxVisibleSuggestions: _clampedInt(suggestOpts.maxVisibleSuggestions, defaults.maxVisibleSuggestions, 1, 15), + filteredTypes: isObject(suggestOpts.filteredTypes) ? suggestOpts.filteredTypes : Object.create(null) + }; + } + + private static _sanitizeGotoLocationOpts(opts: IEditorOptions, defaults: InternalGoToLocationOptions): InternalGoToLocationOptions { + const gotoOpts = opts.gotoLocation || {}; + return { + multiple: _stringSet<'peek' | 'gotoAndPeek' | 'goto'>(gotoOpts.multiple, defaults.multiple, ['peek', 'gotoAndPeek', 'goto']) + }; + } + + private static _sanitizeTabCompletionOpts(opts: boolean | 'on' | 'off' | 'onlySnippets' | undefined, defaults: 'on' | 'off' | 'onlySnippets'): 'on' | 'off' | 'onlySnippets' { + if (opts === false) { + return 'off'; + } else if (opts === true) { + return 'onlySnippets'; + } else { + return _stringSet<'on' | 'off' | 'onlySnippets'>(opts, defaults, ['on', 'off', 'onlySnippets']); + } + } + + private static _sanitizeViewInfo(opts: IEditorOptions, defaults: InternalEditorViewOptions): InternalEditorViewOptions { + + let rulers: number[] = []; + if (Array.isArray(opts.rulers)) { + for (let i = 0, len = opts.rulers.length; i < len; i++) { + rulers.push(_clampedInt(opts.rulers[i], 0, 0, 10000)); + } + rulers.sort(); + } + + const fontLigatures = _boolean(opts.fontLigatures, defaults.fontLigatures); + const disableMonospaceOptimizations = _boolean(opts.disableMonospaceOptimizations, defaults.disableMonospaceOptimizations) || fontLigatures; + + let renderWhitespace = opts.renderWhitespace; + { + // Compatibility with old true or false values + if (renderWhitespace === true) { + renderWhitespace = 'boundary'; + } else if (renderWhitespace === false) { + renderWhitespace = 'none'; + } + renderWhitespace = _stringSet<'none' | 'boundary' | 'selection' | 'all'>(renderWhitespace, defaults.renderWhitespace, ['none', 'boundary', 'selection', 'all']); + } + + let renderLineHighlight = opts.renderLineHighlight; + { + // Compatibility with old true or false values + if (renderLineHighlight === true) { + renderLineHighlight = 'line'; + } else if (renderLineHighlight === false) { + renderLineHighlight = 'none'; + } + renderLineHighlight = _stringSet<'none' | 'gutter' | 'line' | 'all'>(renderLineHighlight, defaults.renderLineHighlight, ['none', 'gutter', 'line', 'all']); + } + + return { + extraEditorClassName: _string(opts.extraEditorClassName, defaults.extraEditorClassName), + disableMonospaceOptimizations: disableMonospaceOptimizations, + rulers: rulers, + cursorSurroundingLines: _clampedInt(opts.cursorSurroundingLines, defaults.cursorWidth, 0, Number.MAX_VALUE), + glyphMargin: _boolean(opts.glyphMargin, defaults.glyphMargin), + revealHorizontalRightPadding: _clampedInt(opts.revealHorizontalRightPadding, defaults.revealHorizontalRightPadding, 0, 1000), + roundedSelection: _boolean(opts.roundedSelection, defaults.roundedSelection), + overviewRulerLanes: _clampedInt(opts.overviewRulerLanes, defaults.overviewRulerLanes, 0, 3), + overviewRulerBorder: _boolean(opts.overviewRulerBorder, defaults.overviewRulerBorder), + cursorBlinking: _cursorBlinkingStyleFromString(opts.cursorBlinking, defaults.cursorBlinking), + mouseWheelZoom: _boolean(opts.mouseWheelZoom, defaults.mouseWheelZoom), + cursorSmoothCaretAnimation: _boolean(opts.cursorSmoothCaretAnimation, defaults.cursorSmoothCaretAnimation), + cursorStyle: _cursorStyleFromString(opts.cursorStyle, defaults.cursorStyle), + cursorWidth: _clampedInt(opts.cursorWidth, defaults.cursorWidth, 0, Number.MAX_VALUE), + hideCursorInOverviewRuler: _boolean(opts.hideCursorInOverviewRuler, defaults.hideCursorInOverviewRuler), + scrollBeyondLastLine: _boolean(opts.scrollBeyondLastLine, defaults.scrollBeyondLastLine), + scrollBeyondLastColumn: _clampedInt(opts.scrollBeyondLastColumn, defaults.scrollBeyondLastColumn, 0, Constants.MAX_SAFE_SMALL_INTEGER), + smoothScrolling: _boolean(opts.smoothScrolling, defaults.smoothScrolling), + stopRenderingLineAfter: _clampedInt(opts.stopRenderingLineAfter, defaults.stopRenderingLineAfter, -1, Constants.MAX_SAFE_SMALL_INTEGER), + renderWhitespace: renderWhitespace, + renderControlCharacters: _boolean(opts.renderControlCharacters, defaults.renderControlCharacters), + fontLigatures: fontLigatures, + renderIndentGuides: _boolean(opts.renderIndentGuides, defaults.renderIndentGuides), + highlightActiveIndentGuide: _boolean(opts.highlightActiveIndentGuide, defaults.highlightActiveIndentGuide), + renderLineHighlight: renderLineHighlight, + fixedOverflowWidgets: _boolean(opts.fixedOverflowWidgets, defaults.fixedOverflowWidgets), + }; + } + + private static _sanitizeContribInfo(opts: IEditorOptions, defaults: EditorContribOptions): EditorContribOptions { + let quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; + if (typeof opts.quickSuggestions === 'object') { + quickSuggestions = { other: true, ...opts.quickSuggestions }; + } else { + quickSuggestions = _boolean(opts.quickSuggestions, defaults.quickSuggestions); + } + // Compatibility support for acceptSuggestionOnEnter + if (typeof opts.acceptSuggestionOnEnter === 'boolean') { + opts.acceptSuggestionOnEnter = opts.acceptSuggestionOnEnter ? 'on' : 'off'; + } + const find = this._sanitizeFindOpts(opts.find, defaults.find); + return { + hover: this._sanitizeHoverOpts(opts.hover, defaults.hover), + links: _boolean(opts.links, defaults.links), + contextmenu: _boolean(opts.contextmenu, defaults.contextmenu), + quickSuggestions: quickSuggestions, + quickSuggestionsDelay: _clampedInt(opts.quickSuggestionsDelay, defaults.quickSuggestionsDelay, Constants.MIN_SAFE_SMALL_INTEGER, Constants.MAX_SAFE_SMALL_INTEGER), + parameterHints: this._sanitizeParameterHintOpts(opts.parameterHints, defaults.parameterHints), + formatOnType: _boolean(opts.formatOnType, defaults.formatOnType), + formatOnPaste: _boolean(opts.formatOnPaste, defaults.formatOnPaste), + suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters), + acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']), + acceptSuggestionOnCommitCharacter: _boolean(opts.acceptSuggestionOnCommitCharacter, defaults.acceptSuggestionOnCommitCharacter), + wordBasedSuggestions: _boolean(opts.wordBasedSuggestions, defaults.wordBasedSuggestions), + suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), + suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), + suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 0, 1000), + tabCompletion: this._sanitizeTabCompletionOpts(opts.tabCompletion, defaults.tabCompletion), + suggest: this._sanitizeSuggestOpts(opts, defaults.suggest), + gotoLocation: this._sanitizeGotoLocationOpts(opts, defaults.gotoLocation), + selectionHighlight: _boolean(opts.selectionHighlight, defaults.selectionHighlight), + occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight), + codeLens: _boolean(opts.codeLens, defaults.codeLens), + foldingStrategy: _stringSet<'auto' | 'indentation'>(opts.foldingStrategy, defaults.foldingStrategy, ['auto', 'indentation']), + showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']), + matchBrackets: _boolean(opts.matchBrackets, defaults.matchBrackets), + find: find, + colorDecorators: _boolean(opts.colorDecorators, defaults.colorDecorators), + lightbulbEnabled: _boolean(opts.lightbulb ? opts.lightbulb.enabled : false, defaults.lightbulbEnabled), + codeActionsOnSave: _booleanMap(opts.codeActionsOnSave, {}), + codeActionsOnSaveTimeout: _clampedInt(opts.codeActionsOnSaveTimeout, defaults.codeActionsOnSaveTimeout, 1, 10000) + }; + } +} + +/** + * @internal + */ +export class InternalEditorOptionsFactory { + + public static createInternalEditorOptions(env: IEnvironmentalOptions, opts: IValidatedEditorOptions) { + + let className = 'monaco-editor'; + if (opts.viewInfo.extraEditorClassName) { + className += ' ' + opts.viewInfo.extraEditorClassName; + } + if (env.extraEditorClassName) { + className += ' ' + env.extraEditorClassName; + } + if (opts.viewInfo.fontLigatures) { + className += ' enable-ligatures'; + } + if (opts.mouseStyle === 'default') { + className += ' mouse-default'; + } else if (opts.mouseStyle === 'copy') { + className += ' mouse-copy'; + } + + return new InternalEditorOptions({ + canUseLayerHinting: opts.disableLayerHinting ? false : true, + pixelRatio: env.pixelRatio, + editorClassName: className, + lineHeight: env.fontInfo.lineHeight, + readOnly: opts.readOnly, + multiCursorModifier: opts.multiCursorModifier, + multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping, + wordSeparators: opts.wordSeparators, + autoClosingBrackets: opts.autoClosingBrackets, + autoClosingQuotes: opts.autoClosingQuotes, + autoClosingOvertype: opts.autoClosingOvertype, + autoSurround: opts.autoSurround, + autoIndent: opts.autoIndent, + useTabStops: opts.useTabStops, + tabFocusMode: opts.readOnly ? true : env.tabFocusMode, + dragAndDrop: opts.dragAndDrop, + emptySelectionClipboard: opts.emptySelectionClipboard && env.emptySelectionClipboard, + copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting, + fontInfo: env.fontInfo, + viewInfo: opts.viewInfo, + contribInfo: opts.contribInfo, + showUnused: opts.showUnused, + }); + } +} + +/** + * @internal + */ +export interface IEditorLayoutProviderOpts { + readonly outerWidth: number; + readonly outerHeight: number; + + readonly showGlyphMargin: boolean; + readonly lineHeight: number; + + readonly showLineNumbers: boolean; + readonly lineNumbersMinChars: number; + readonly lineNumbersDigitCount: number; + + readonly lineDecorationsWidth: number; + + readonly typicalHalfwidthCharacterWidth: number; + readonly maxDigitWidth: number; + + readonly verticalScrollbarWidth: number; + readonly verticalScrollbarHasArrows: boolean; + readonly scrollbarArrowSize: number; + readonly horizontalScrollbarHeight: number; + + readonly minimap: boolean; + readonly minimapSide: string; + readonly minimapRenderCharacters: boolean; + readonly minimapMaxColumn: number; + readonly pixelRatio: number; +} + +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 +}; + +/** + * @internal + */ +export const EDITOR_DEFAULTS: IValidatedEditorOptions = { + wordSeparators: USUAL_WORD_SEPARATORS, + lineDecorationsWidth: 10, + readOnly: false, + mouseStyle: 'text', + disableLayerHinting: false, + automaticLayout: false, + autoClosingBrackets: 'languageDefined', + autoClosingQuotes: 'languageDefined', + autoClosingOvertype: 'auto', + autoSurround: 'languageDefined', + autoIndent: true, + dragAndDrop: true, + emptySelectionClipboard: true, + copyWithSyntaxHighlighting: true, + useTabStops: true, + multiCursorModifier: 'altKey', + multiCursorMergeOverlapping: true, + showUnused: true, + + viewInfo: { + extraEditorClassName: '', + disableMonospaceOptimizations: false, + rulers: [], + cursorSurroundingLines: 0, + glyphMargin: true, + revealHorizontalRightPadding: 30, + roundedSelection: true, + overviewRulerLanes: 2, + overviewRulerBorder: true, + cursorBlinking: TextEditorCursorBlinkingStyle.Blink, + mouseWheelZoom: false, + cursorSmoothCaretAnimation: false, + cursorStyle: TextEditorCursorStyle.Line, + cursorWidth: 0, + hideCursorInOverviewRuler: false, + scrollBeyondLastLine: true, + scrollBeyondLastColumn: 5, + smoothScrolling: false, + stopRenderingLineAfter: 10000, + renderWhitespace: 'none', + renderControlCharacters: false, + fontLigatures: false, + renderIndentGuides: true, + highlightActiveIndentGuide: true, + renderLineHighlight: 'line', + fixedOverflowWidgets: false, + }, + + contribInfo: { + hover: { + enabled: true, + delay: 300, + sticky: true + }, + links: true, + contextmenu: true, + quickSuggestions: { other: true, comments: false, strings: false }, + quickSuggestionsDelay: 10, + parameterHints: { + enabled: true, + cycle: false + }, + formatOnType: false, + formatOnPaste: false, + suggestOnTriggerCharacters: true, + acceptSuggestionOnEnter: 'on', + acceptSuggestionOnCommitCharacter: true, + wordBasedSuggestions: true, + suggestSelection: 'recentlyUsed', + suggestFontSize: 0, + suggestLineHeight: 0, + tabCompletion: 'off', + suggest: { + filterGraceful: true, + snippets: 'inline', + snippetsPreventQuickSuggestions: true, + localityBonus: false, + shareSuggestSelections: false, + showIcons: true, + maxVisibleSuggestions: 12, + filteredTypes: Object.create(null) + }, + gotoLocation: { + multiple: 'peek' + }, + selectionHighlight: true, + occurrencesHighlight: true, + codeLens: true, + foldingStrategy: 'auto', + showFoldingControls: 'mouseover', + matchBrackets: true, + find: { + seedSearchStringFromSelection: true, + autoFindInSelection: false, + globalFindClipboard: false, + addExtraSpaceOnTop: true + }, + colorDecorators: true, + lightbulbEnabled: true, + codeActionsOnSave: {}, + codeActionsOnSaveTimeout: 750 + }, +}; + +export interface IRawEditorOptionsBag extends IEditorOptions { + [key: string]: any; +} + +/** + * @internal + */ +export class RawEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOptionId): T | undefined { + return this._values[id]; + } + public _write(id: EditorOptionId, value: T | undefined): void { + this._values[id] = value; + } +} + +/** + * @internal + */ +export class ValidatedEditorOptions { + private readonly _values: any[] = []; + public _read(option: EditorOptionId): T { + return this._values[option]; + } + public _write(option: EditorOptionId, value: T): void { + this._values[option] = value; + } +} + +export interface IComputedEditorOptions { + get>(id: EditorOptionId): ComputedEditorOptionValue; +} + +/** + * @internal + */ +export class ComputedEditorOptions implements IComputedEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOptionId): T { + return this._values[id]; + } + public get>(id: EditorOptionId): ComputedEditorOptionValue { + return this._values[id]; + } + public _write(id: EditorOptionId, value: T): void { + this._values[id] = value; + } +} + +/** + * @internal + */ +export class ChangedEditorOptions { + private readonly _values: boolean[] = []; + public get(id: EditorOptionId): boolean { + return this._values[id]; + } + public _write(id: EditorOptionId, value: boolean): void { + this._values[id] = value; + } +} + +export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; + +export interface IEditorOption { + readonly id: EditorOptionId; + readonly name: PossibleKeyName; + readonly defaultValue: T2; + read(options: IRawEditorOptionsBag): T1 | undefined; + mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; + validate(input: T1 | undefined): T2; + compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; + equals(a: T3, b: T3): boolean; +} + +/** + * @internal + */ +export const editorOptionsRegistry: IEditorOption[] = []; + +function registerEditorOption(option: IEditorOption): IEditorOption { + editorOptionsRegistry[option.id] = option; + return option; +} + +export abstract class BaseEditorOption implements IEditorOption { + + public readonly id: EditorOptionId; + public readonly name: PossibleKeyName; + public readonly defaultValue: T2; + + constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T2, deps: EditorOptionId[] = []) { + this.id = id; + this.name = name; + this.defaultValue = defaultValue; + for (const dep of deps) { + assert.ok(dep < id); + } + } + public read(options: IRawEditorOptionsBag): T1 | undefined { + return options[this.name]; + } + public mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined { + switch (typeof b) { + case 'bigint': return b; + case 'boolean': return b; + case 'function': return b; + case 'number': return b; + case 'object': return (Array.isArray(b) || typeof a !== 'object' ? b : objects.mixin(objects.mixin({}, a), b)); + case 'string': return b; + default: + return a; + } + } + public abstract validate(input: T1 | undefined): T2; + public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; + public equals(a: T3, b: T3): boolean { + return (a === b); + } +} + +class EditorBooleanOption extends BaseEditorOption { + public validate(input: boolean | undefined): boolean { + return _boolean(input, this.defaultValue); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { + return value; + } +} + +class EditorIntOption extends BaseEditorOption { + public readonly minimum: number; + public readonly maximum: number; + constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOptionId[] = []) { + super(id, name, defaultValue, deps); + this.minimum = minimum; + this.maximum = maximum; + } + public validate(input: number | undefined): number { + return _clampedInt(input, this.defaultValue, this.minimum, this.maximum); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + return value; + } +} + +class EditorFloatOption extends BaseEditorOption { + public readonly validationFn: (value: number) => number; + constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOptionId[] = []) { + super(id, name, defaultValue, deps); + this.validationFn = validationFn; + } + public validate(input: number | undefined): number { + return this.validationFn(_float(input, this.defaultValue)); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + return value; + } +} + +class EditorStringOption extends BaseEditorOption { + public validate(input: string | undefined): string { + return _string(input, this.defaultValue); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { + return value; + } +} + +class EditorEnumOption extends BaseEditorOption { + public readonly allowedValues: T1[]; + public readonly convert: (value: T1) => T2; + constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOptionId[] = []) { + super(id, name, defaultValue, deps); + this.allowedValues = allowedValues; + this.convert = convert; + } + public validate(input: T1 | undefined): T1 { + return _stringSet(input, this.defaultValue, this.allowedValues); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T1): T2 { + return this.convert(value); + } +} + +class EditorPassthroughOption extends BaseEditorOption { + public validate(input: T | undefined): T { + if (typeof input === 'undefined') { + return this.defaultValue; + } + return input; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T): T { + return value; + } +} + +//#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 extends BaseEditorOption { + public validate(lineNumbers: LineNumbersType | undefined): 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 + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorRenderLineNumbersOptions): InternalEditorRenderLineNumbersOptions { + return value; + } + public equals(a: InternalEditorRenderLineNumbersOptions, b: InternalEditorRenderLineNumbersOptions): boolean { + return ( + a.renderType === b.renderType + && a.renderFn === b.renderFn + ); + } +} + +//#endregion + +//#region minimap + +export interface InternalEditorMinimapOptions { + readonly enabled: boolean; + readonly side: 'right' | 'left'; + readonly showSlider: 'always' | 'mouseover'; + readonly renderCharacters: boolean; + readonly maxColumn: number; +} + +class EditorMinimapOption extends BaseEditorOption { + public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + side: _stringSet<'right' | 'left'>(input.side, this.defaultValue.side, ['right', 'left']), + showSlider: _stringSet<'always' | 'mouseover'>(input.showSlider, this.defaultValue.showSlider, ['always', 'mouseover']), + renderCharacters: _boolean(input.renderCharacters, this.defaultValue.renderCharacters), + maxColumn: _clampedInt(input.maxColumn, this.defaultValue.maxColumn, 1, 10000), + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorMinimapOptions): InternalEditorMinimapOptions { + return value; + } + public equals(a: InternalEditorMinimapOptions, b: InternalEditorMinimapOptions): boolean { + return ( + a.enabled === b.enabled + && a.side === b.side + && a.showSlider === b.showSlider + && a.renderCharacters === b.renderCharacters + && a.maxColumn === b.maxColumn + ); + } +} + +//#endregion + +//#region accessibilitySupport + +class EditorAccessibilitySupportOption extends BaseEditorOption<'auto' | 'off' | 'on', 'auto' | 'off' | 'on', AccessibilitySupport> { + public validate(input: 'auto' | 'off' | 'on' | undefined): 'auto' | 'off' | 'on' { + return _stringSet<'auto' | 'off' | 'on'>(input, this.defaultValue, ['auto', 'off', 'on']); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: 'auto' | 'off' | 'on'): AccessibilitySupport { + if (value === 'auto') { + // The editor reads the `accessibilitySupport` from the environment + return env.accessibilitySupport; + } else if (value === 'on') { + return AccessibilitySupport.Enabled; + } else { + return AccessibilitySupport.Disabled; + } + } +} + +//#endregion + +//#region ariaLabel + +class EditorAriaLabel extends BaseEditorOption { + public validate(input: string | undefined): string { + return _string(input, this.defaultValue); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { + const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + if (accessibilitySupport === AccessibilitySupport.Disabled) { + return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options."); + } + return value; + } +} + +//#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; +} + +class EditorScrollbarOption extends BaseEditorOption { + public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + const horizontalScrollbarSize = _clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000); + const verticalScrollbarSize = _clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000); + return { + arrowSize: _clampedInt(input.arrowSize, this.defaultValue.arrowSize, 0, 1000), + vertical: _scrollbarVisibilityFromString(input.vertical, this.defaultValue.vertical), + horizontal: _scrollbarVisibilityFromString(input.horizontal, this.defaultValue.horizontal), + useShadows: _boolean(input.useShadows, this.defaultValue.useShadows), + verticalHasArrows: _boolean(input.verticalHasArrows, this.defaultValue.verticalHasArrows), + horizontalHasArrows: _boolean(input.horizontalHasArrows, this.defaultValue.horizontalHasArrows), + handleMouseWheel: _boolean(input.handleMouseWheel, this.defaultValue.handleMouseWheel), + horizontalScrollbarSize: horizontalScrollbarSize, + horizontalSliderSize: _clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000), + verticalScrollbarSize: verticalScrollbarSize, + verticalSliderSize: _clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000), + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorScrollbarOptions): InternalEditorScrollbarOptions { + return value; + } + public equals(a: InternalEditorScrollbarOptions, b: InternalEditorScrollbarOptions): boolean { + return ( + a.arrowSize === b.arrowSize + && a.vertical === b.vertical + && a.horizontal === b.horizontal + && a.useShadows === b.useShadows + && a.verticalHasArrows === b.verticalHasArrows + && a.horizontalHasArrows === b.horizontalHasArrows + && a.handleMouseWheel === b.handleMouseWheel + && a.horizontalScrollbarSize === b.horizontalScrollbarSize + && a.horizontalSliderSize === b.horizontalSliderSize + && a.verticalScrollbarSize === b.verticalScrollbarSize + && a.verticalSliderSize === b.verticalSliderSize + ); + } +} + +//#endregion + +//#region layoutInfo + /** * A description for the overview ruler position. */ @@ -1634,827 +2472,93 @@ export interface EditorLayoutInfo { readonly overviewRuler: OverviewRulerPosition; } -/** - * An event describing that the configuration of the editor has changed. - */ -export interface IConfigurationChangedEvent { - hasChanged(id: EditorOptionId): boolean; - readonly canUseLayerHinting: boolean; - readonly pixelRatio: boolean; - readonly editorClassName: boolean; - readonly lineHeight: boolean; - readonly readOnly: boolean; - readonly accessibilitySupport: boolean; - readonly multiCursorModifier: boolean; - readonly multiCursorMergeOverlapping: boolean; - readonly wordSeparators: boolean; - readonly autoClosingBrackets: boolean; - readonly autoClosingQuotes: boolean; - readonly autoClosingOvertype: boolean; - readonly autoSurround: boolean; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly tabFocusMode: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; - readonly layoutInfo: boolean; - readonly fontInfo: boolean; - readonly viewInfo: boolean; - readonly wrappingInfo: boolean; - readonly contribInfo: boolean; -} - /** * @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; -} - -function _boolean(value: any, defaultValue: T): boolean | T { - if (typeof value === 'undefined') { - return defaultValue; +export class EditorLayoutInfoComputer extends BaseEditorOption { + public validate(input: undefined): undefined { + return undefined; } - if (value === 'false') { - // treat the string 'false' as false - return false; - } - return Boolean(value); -} - -function _booleanMap(value: { [key: string]: boolean } | undefined, defaultValue: { [key: string]: boolean }): { [key: string]: boolean } { - if (!value) { - return defaultValue; - } - - const out = Object.create(null); - for (const k of Object.keys(value)) { - const v = value[k]; - if (typeof v === 'boolean') { - out[k] = v; - } - } - return out; -} - -function _string(value: any, defaultValue: string): string { - if (typeof value !== 'string') { - return defaultValue; - } - return value; -} - -function _stringSet(value: T | undefined, defaultValue: T, allowedValues: T[]): T { - if (typeof value !== 'string') { - return defaultValue; - } - if (allowedValues.indexOf(value) === -1) { - return defaultValue; - } - return value; -} - -function _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; -} - -function _float(value: any, defaultValue: number): number { - let r = parseFloat(value); - if (isNaN(r)) { - r = defaultValue; - } - return r; -} - -function _wrappingIndentFromString(wrappingIndent: string | undefined, defaultValue: WrappingIndent): WrappingIndent { - if (typeof wrappingIndent !== 'string') { - return defaultValue; - } - if (wrappingIndent === 'same') { - return WrappingIndent.Same; - } else if (wrappingIndent === 'indent') { - return WrappingIndent.Indent; - } else if (wrappingIndent === 'deepIndent') { - return WrappingIndent.DeepIndent; - } else { - return WrappingIndent.None; - } -} - -function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string | undefined, defaultValue: TextEditorCursorBlinkingStyle): TextEditorCursorBlinkingStyle { - if (typeof cursorBlinkingStyle !== 'string') { - return defaultValue; - } - switch (cursorBlinkingStyle) { - case 'blink': - return TextEditorCursorBlinkingStyle.Blink; - case 'smooth': - return TextEditorCursorBlinkingStyle.Smooth; - case 'phase': - return TextEditorCursorBlinkingStyle.Phase; - case 'expand': - return TextEditorCursorBlinkingStyle.Expand; - case 'visible': // maintain compatibility - case 'solid': - return TextEditorCursorBlinkingStyle.Solid; - } - return TextEditorCursorBlinkingStyle.Blink; -} - -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; - } -} - -/** - * @internal - */ -export class EditorOptionsValidator { - - /** - * Validate raw editor options. - * i.e. since they can be defined by the user, they might be invalid. - */ - public static validate(opts: IEditorOptions, defaults: IValidatedEditorOptions): IValidatedEditorOptions { - let wordWrap = opts.wordWrap; - { - // Compatibility with old true or false values - if (wordWrap === true) { - wordWrap = 'on'; - } else if (wordWrap === false) { - wordWrap = 'off'; - } - - wordWrap = _stringSet<'off' | 'on' | 'wordWrapColumn' | 'bounded'>(wordWrap, defaults.wordWrap, ['off', 'on', 'wordWrapColumn', 'bounded']); - } - - const viewInfo = this._sanitizeViewInfo(opts, defaults.viewInfo); - const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo); - - let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey' | undefined = undefined; - if (typeof opts.multiCursorModifier === 'string') { - if (opts.multiCursorModifier === 'ctrlCmd') { - configuredMulticursorModifier = platform.isMacintosh ? 'metaKey' : 'ctrlKey'; - } else { - configuredMulticursorModifier = 'altKey'; - } - } - const multiCursorModifier = _stringSet<'altKey' | 'metaKey' | 'ctrlKey'>(configuredMulticursorModifier, defaults.multiCursorModifier, ['altKey', 'metaKey', 'ctrlKey']); - - let autoClosingBrackets: EditorAutoClosingStrategy; - let autoClosingQuotes: EditorAutoClosingStrategy; - let autoSurround: EditorAutoSurroundStrategy; - if (typeof opts.autoClosingBrackets === 'boolean' && opts.autoClosingBrackets === false) { - // backwards compatibility: disable all on boolean false - autoClosingBrackets = 'never'; - autoClosingQuotes = 'never'; - autoSurround = 'never'; - } else { - autoClosingBrackets = _stringSet(opts.autoClosingBrackets, defaults.autoClosingBrackets, ['always', 'languageDefined', 'beforeWhitespace', 'never']); - autoClosingQuotes = _stringSet(opts.autoClosingQuotes, defaults.autoClosingQuotes, ['always', 'languageDefined', 'beforeWhitespace', 'never']); - autoSurround = _stringSet(opts.autoSurround, defaults.autoSurround, ['languageDefined', 'brackets', 'quotes', 'never']); - } - - return { - inDiffEditor: _boolean(opts.inDiffEditor, defaults.inDiffEditor), - wordSeparators: _string(opts.wordSeparators, defaults.wordSeparators), - lineNumbersMinChars: _clampedInt(opts.lineNumbersMinChars, defaults.lineNumbersMinChars, 1, 10), - lineDecorationsWidth: (typeof opts.lineDecorationsWidth === 'undefined' ? defaults.lineDecorationsWidth : opts.lineDecorationsWidth), - readOnly: _boolean(opts.readOnly, defaults.readOnly), - mouseStyle: _stringSet<'text' | 'default' | 'copy'>(opts.mouseStyle, defaults.mouseStyle, ['text', 'default', 'copy']), - disableLayerHinting: _boolean(opts.disableLayerHinting, defaults.disableLayerHinting), - automaticLayout: _boolean(opts.automaticLayout, defaults.automaticLayout), - wordWrap: wordWrap, - wordWrapColumn: _clampedInt(opts.wordWrapColumn, defaults.wordWrapColumn, 1, Constants.MAX_SAFE_SMALL_INTEGER), - wordWrapMinified: _boolean(opts.wordWrapMinified, defaults.wordWrapMinified), - wrappingIndent: _wrappingIndentFromString(opts.wrappingIndent, defaults.wrappingIndent), - wordWrapBreakBeforeCharacters: _string(opts.wordWrapBreakBeforeCharacters, defaults.wordWrapBreakBeforeCharacters), - wordWrapBreakAfterCharacters: _string(opts.wordWrapBreakAfterCharacters, defaults.wordWrapBreakAfterCharacters), - wordWrapBreakObtrusiveCharacters: _string(opts.wordWrapBreakObtrusiveCharacters, defaults.wordWrapBreakObtrusiveCharacters), - autoClosingBrackets, - autoClosingQuotes, - autoClosingOvertype: _stringSet(opts.autoClosingOvertype, defaults.autoClosingOvertype, ['always', 'auto', 'never']), - autoSurround, - autoIndent: _boolean(opts.autoIndent, defaults.autoIndent), - dragAndDrop: _boolean(opts.dragAndDrop, defaults.dragAndDrop), - emptySelectionClipboard: _boolean(opts.emptySelectionClipboard, defaults.emptySelectionClipboard), - copyWithSyntaxHighlighting: _boolean(opts.copyWithSyntaxHighlighting, defaults.copyWithSyntaxHighlighting), - useTabStops: _boolean(opts.useTabStops, defaults.useTabStops), - multiCursorModifier: multiCursorModifier, - multiCursorMergeOverlapping: _boolean(opts.multiCursorMergeOverlapping, defaults.multiCursorMergeOverlapping), - accessibilitySupport: _stringSet<'auto' | 'on' | 'off'>(opts.accessibilitySupport, defaults.accessibilitySupport, ['auto', 'on', 'off']), - showUnused: _boolean(opts.showUnused, defaults.showUnused), - viewInfo: viewInfo, - contribInfo: contribInfo, - }; - } - - private static _sanitizeScrollbarOpts(opts: IEditorScrollbarOptions | undefined, defaults: InternalEditorScrollbarOptions, mouseWheelScrollSensitivity: number, fastScrollSensitivity: number): InternalEditorScrollbarOptions { - if (typeof opts !== 'object') { - return defaults; - } - const horizontalScrollbarSize = _clampedInt(opts.horizontalScrollbarSize, defaults.horizontalScrollbarSize, 0, 1000); - const verticalScrollbarSize = _clampedInt(opts.verticalScrollbarSize, defaults.verticalScrollbarSize, 0, 1000); - return { - vertical: _scrollbarVisibilityFromString(opts.vertical, defaults.vertical), - horizontal: _scrollbarVisibilityFromString(opts.horizontal, defaults.horizontal), - - arrowSize: _clampedInt(opts.arrowSize, defaults.arrowSize, 0, 1000), - useShadows: _boolean(opts.useShadows, defaults.useShadows), - - verticalHasArrows: _boolean(opts.verticalHasArrows, defaults.verticalHasArrows), - horizontalHasArrows: _boolean(opts.horizontalHasArrows, defaults.horizontalHasArrows), - - horizontalScrollbarSize: horizontalScrollbarSize, - horizontalSliderSize: _clampedInt(opts.horizontalSliderSize, horizontalScrollbarSize, 0, 1000), - - verticalScrollbarSize: verticalScrollbarSize, - verticalSliderSize: _clampedInt(opts.verticalSliderSize, verticalScrollbarSize, 0, 1000), - - handleMouseWheel: _boolean(opts.handleMouseWheel, defaults.handleMouseWheel), - mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, - fastScrollSensitivity: fastScrollSensitivity, - }; - } - - private static _sanitizeMinimapOpts(opts: IEditorMinimapOptions | undefined, defaults: InternalEditorMinimapOptions): InternalEditorMinimapOptions { - if (typeof opts !== 'object') { - return defaults; - } - return { - enabled: _boolean(opts.enabled, defaults.enabled), - side: _stringSet<'right' | 'left'>(opts.side, defaults.side, ['right', 'left']), - showSlider: _stringSet<'always' | 'mouseover'>(opts.showSlider, defaults.showSlider, ['always', 'mouseover']), - renderCharacters: _boolean(opts.renderCharacters, defaults.renderCharacters), - maxColumn: _clampedInt(opts.maxColumn, defaults.maxColumn, 1, 10000), - }; - } - - private static _sanitizeFindOpts(opts: IEditorFindOptions | undefined, defaults: InternalEditorFindOptions): InternalEditorFindOptions { - if (typeof opts !== 'object') { - return defaults; - } - - return { - seedSearchStringFromSelection: _boolean(opts.seedSearchStringFromSelection, defaults.seedSearchStringFromSelection), - autoFindInSelection: _boolean(opts.autoFindInSelection, defaults.autoFindInSelection), - globalFindClipboard: _boolean(opts.globalFindClipboard, defaults.globalFindClipboard), - addExtraSpaceOnTop: _boolean(opts.addExtraSpaceOnTop, defaults.addExtraSpaceOnTop) - }; - } - - private static _sanitizeParameterHintOpts(opts: IEditorParameterHintOptions | undefined, defaults: InternalParameterHintOptions): InternalParameterHintOptions { - if (typeof opts !== 'object') { - return defaults; - } - - return { - enabled: _boolean(opts.enabled, defaults.enabled), - cycle: _boolean(opts.cycle, defaults.cycle) - }; - } - - private static _sanitizeHoverOpts(_opts: boolean | IEditorHoverOptions | undefined, defaults: InternalEditorHoverOptions): InternalEditorHoverOptions { - let opts: IEditorHoverOptions; - if (typeof _opts === 'boolean') { - opts = { - enabled: _opts - }; - } else if (typeof _opts === 'object') { - opts = _opts; - } else { - return defaults; - } - - return { - enabled: _boolean(opts.enabled, defaults.enabled), - delay: _clampedInt(opts.delay, defaults.delay, 0, 10000), - sticky: _boolean(opts.sticky, defaults.sticky) - }; - } - - private static _sanitizeSuggestOpts(opts: IEditorOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { - const suggestOpts = opts.suggest || {}; - return { - filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful), - snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), - snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful), - localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus), - shareSuggestSelections: _boolean(suggestOpts.shareSuggestSelections, defaults.shareSuggestSelections), - showIcons: _boolean(suggestOpts.showIcons, defaults.showIcons), - maxVisibleSuggestions: _clampedInt(suggestOpts.maxVisibleSuggestions, defaults.maxVisibleSuggestions, 1, 15), - filteredTypes: isObject(suggestOpts.filteredTypes) ? suggestOpts.filteredTypes : Object.create(null) - }; - } - - private static _sanitizeGotoLocationOpts(opts: IEditorOptions, defaults: InternalGoToLocationOptions): InternalGoToLocationOptions { - const gotoOpts = opts.gotoLocation || {}; - return { - multiple: _stringSet<'peek' | 'gotoAndPeek' | 'goto'>(gotoOpts.multiple, defaults.multiple, ['peek', 'gotoAndPeek', 'goto']) - }; - } - - private static _sanitizeTabCompletionOpts(opts: boolean | 'on' | 'off' | 'onlySnippets' | undefined, defaults: 'on' | 'off' | 'onlySnippets'): 'on' | 'off' | 'onlySnippets' { - if (opts === false) { - return 'off'; - } else if (opts === true) { - return 'onlySnippets'; - } else { - return _stringSet<'on' | 'off' | 'onlySnippets'>(opts, defaults, ['on', 'off', 'onlySnippets']); - } - } - - private static _sanitizeViewInfo(opts: IEditorOptions, defaults: InternalEditorViewOptions): InternalEditorViewOptions { - - let rulers: number[] = []; - if (Array.isArray(opts.rulers)) { - for (let i = 0, len = opts.rulers.length; i < len; i++) { - rulers.push(_clampedInt(opts.rulers[i], 0, 0, 10000)); - } - rulers.sort(); - } - - let renderLineNumbers: RenderLineNumbersType = defaults.renderLineNumbers; - let renderCustomLineNumbers: ((lineNumber: number) => string) | null = defaults.renderCustomLineNumbers; - - if (typeof opts.lineNumbers !== 'undefined') { - let lineNumbers = opts.lineNumbers; - - // Compatibility with old true or false values - if (lineNumbers === true) { - lineNumbers = 'on'; - } else if (lineNumbers === false) { - lineNumbers = 'off'; - } - - if (typeof lineNumbers === 'function') { - renderLineNumbers = RenderLineNumbersType.Custom; - renderCustomLineNumbers = lineNumbers; - } else if (lineNumbers === 'interval') { - renderLineNumbers = RenderLineNumbersType.Interval; - } else if (lineNumbers === 'relative') { - renderLineNumbers = RenderLineNumbersType.Relative; - } else if (lineNumbers === 'on') { - renderLineNumbers = RenderLineNumbersType.On; - } else { - renderLineNumbers = RenderLineNumbersType.Off; - } - } - - const fontLigatures = _boolean(opts.fontLigatures, defaults.fontLigatures); - const disableMonospaceOptimizations = _boolean(opts.disableMonospaceOptimizations, defaults.disableMonospaceOptimizations) || fontLigatures; - - let renderWhitespace = opts.renderWhitespace; - { - // Compatibility with old true or false values - if (renderWhitespace === true) { - renderWhitespace = 'boundary'; - } else if (renderWhitespace === false) { - renderWhitespace = 'none'; - } - renderWhitespace = _stringSet<'none' | 'boundary' | 'selection' | 'all'>(renderWhitespace, defaults.renderWhitespace, ['none', 'boundary', 'selection', 'all']); - } - - let renderLineHighlight = opts.renderLineHighlight; - { - // Compatibility with old true or false values - if (renderLineHighlight === true) { - renderLineHighlight = 'line'; - } else if (renderLineHighlight === false) { - renderLineHighlight = 'none'; - } - renderLineHighlight = _stringSet<'none' | 'gutter' | 'line' | 'all'>(renderLineHighlight, defaults.renderLineHighlight, ['none', 'gutter', 'line', 'all']); - } - - let mouseWheelScrollSensitivity = _float(opts.mouseWheelScrollSensitivity, defaults.scrollbar.mouseWheelScrollSensitivity); - if (mouseWheelScrollSensitivity === 0) { - // Disallow 0, as it would prevent/block scrolling - mouseWheelScrollSensitivity = 1; - } - - let fastScrollSensitivity = _float(opts.fastScrollSensitivity, defaults.scrollbar.fastScrollSensitivity); - if (fastScrollSensitivity <= 0) { - fastScrollSensitivity = defaults.scrollbar.fastScrollSensitivity; - } - const scrollbar = this._sanitizeScrollbarOpts(opts.scrollbar, defaults.scrollbar, mouseWheelScrollSensitivity, fastScrollSensitivity); - const minimap = this._sanitizeMinimapOpts(opts.minimap, defaults.minimap); - - return { - extraEditorClassName: _string(opts.extraEditorClassName, defaults.extraEditorClassName), - disableMonospaceOptimizations: disableMonospaceOptimizations, - rulers: rulers, - ariaLabel: _string(opts.ariaLabel, defaults.ariaLabel), - cursorSurroundingLines: _clampedInt(opts.cursorSurroundingLines, defaults.cursorWidth, 0, Number.MAX_VALUE), - renderLineNumbers: renderLineNumbers, - renderCustomLineNumbers: renderCustomLineNumbers, - glyphMargin: _boolean(opts.glyphMargin, defaults.glyphMargin), - revealHorizontalRightPadding: _clampedInt(opts.revealHorizontalRightPadding, defaults.revealHorizontalRightPadding, 0, 1000), - roundedSelection: _boolean(opts.roundedSelection, defaults.roundedSelection), - overviewRulerLanes: _clampedInt(opts.overviewRulerLanes, defaults.overviewRulerLanes, 0, 3), - overviewRulerBorder: _boolean(opts.overviewRulerBorder, defaults.overviewRulerBorder), - cursorBlinking: _cursorBlinkingStyleFromString(opts.cursorBlinking, defaults.cursorBlinking), - mouseWheelZoom: _boolean(opts.mouseWheelZoom, defaults.mouseWheelZoom), - cursorSmoothCaretAnimation: _boolean(opts.cursorSmoothCaretAnimation, defaults.cursorSmoothCaretAnimation), - cursorStyle: _cursorStyleFromString(opts.cursorStyle, defaults.cursorStyle), - cursorWidth: _clampedInt(opts.cursorWidth, defaults.cursorWidth, 0, Number.MAX_VALUE), - hideCursorInOverviewRuler: _boolean(opts.hideCursorInOverviewRuler, defaults.hideCursorInOverviewRuler), - scrollBeyondLastLine: _boolean(opts.scrollBeyondLastLine, defaults.scrollBeyondLastLine), - scrollBeyondLastColumn: _clampedInt(opts.scrollBeyondLastColumn, defaults.scrollBeyondLastColumn, 0, Constants.MAX_SAFE_SMALL_INTEGER), - smoothScrolling: _boolean(opts.smoothScrolling, defaults.smoothScrolling), - stopRenderingLineAfter: _clampedInt(opts.stopRenderingLineAfter, defaults.stopRenderingLineAfter, -1, Constants.MAX_SAFE_SMALL_INTEGER), - renderWhitespace: renderWhitespace, - renderControlCharacters: _boolean(opts.renderControlCharacters, defaults.renderControlCharacters), - fontLigatures: fontLigatures, - renderIndentGuides: _boolean(opts.renderIndentGuides, defaults.renderIndentGuides), - highlightActiveIndentGuide: _boolean(opts.highlightActiveIndentGuide, defaults.highlightActiveIndentGuide), - renderLineHighlight: renderLineHighlight, - scrollbar: scrollbar, - minimap: minimap, - fixedOverflowWidgets: _boolean(opts.fixedOverflowWidgets, defaults.fixedOverflowWidgets), - }; - } - - private static _sanitizeContribInfo(opts: IEditorOptions, defaults: EditorContribOptions): EditorContribOptions { - let quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; - if (typeof opts.quickSuggestions === 'object') { - quickSuggestions = { other: true, ...opts.quickSuggestions }; - } else { - quickSuggestions = _boolean(opts.quickSuggestions, defaults.quickSuggestions); - } - // Compatibility support for acceptSuggestionOnEnter - if (typeof opts.acceptSuggestionOnEnter === 'boolean') { - opts.acceptSuggestionOnEnter = opts.acceptSuggestionOnEnter ? 'on' : 'off'; - } - const find = this._sanitizeFindOpts(opts.find, defaults.find); - return { - hover: this._sanitizeHoverOpts(opts.hover, defaults.hover), - links: _boolean(opts.links, defaults.links), - contextmenu: _boolean(opts.contextmenu, defaults.contextmenu), - quickSuggestions: quickSuggestions, - quickSuggestionsDelay: _clampedInt(opts.quickSuggestionsDelay, defaults.quickSuggestionsDelay, Constants.MIN_SAFE_SMALL_INTEGER, Constants.MAX_SAFE_SMALL_INTEGER), - parameterHints: this._sanitizeParameterHintOpts(opts.parameterHints, defaults.parameterHints), - formatOnType: _boolean(opts.formatOnType, defaults.formatOnType), - formatOnPaste: _boolean(opts.formatOnPaste, defaults.formatOnPaste), - suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters), - acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']), - acceptSuggestionOnCommitCharacter: _boolean(opts.acceptSuggestionOnCommitCharacter, defaults.acceptSuggestionOnCommitCharacter), - wordBasedSuggestions: _boolean(opts.wordBasedSuggestions, defaults.wordBasedSuggestions), - suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), - suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), - suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 0, 1000), - tabCompletion: this._sanitizeTabCompletionOpts(opts.tabCompletion, defaults.tabCompletion), - suggest: this._sanitizeSuggestOpts(opts, defaults.suggest), - gotoLocation: this._sanitizeGotoLocationOpts(opts, defaults.gotoLocation), - selectionHighlight: _boolean(opts.selectionHighlight, defaults.selectionHighlight), - occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight), - codeLens: _boolean(opts.codeLens, defaults.codeLens), - folding: _boolean(opts.folding, defaults.folding), - foldingStrategy: _stringSet<'auto' | 'indentation'>(opts.foldingStrategy, defaults.foldingStrategy, ['auto', 'indentation']), - showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']), - matchBrackets: _boolean(opts.matchBrackets, defaults.matchBrackets), - find: find, - colorDecorators: _boolean(opts.colorDecorators, defaults.colorDecorators), - lightbulbEnabled: _boolean(opts.lightbulb ? opts.lightbulb.enabled : false, defaults.lightbulbEnabled), - codeActionsOnSave: _booleanMap(opts.codeActionsOnSave, {}), - codeActionsOnSaveTimeout: _clampedInt(opts.codeActionsOnSaveTimeout, defaults.codeActionsOnSaveTimeout, 1, 10000) - }; - } -} - -/** - * @internal - */ -export class InternalEditorOptionsFactory { - - private static _tweakValidatedOptions(opts: IValidatedEditorOptions, accessibilitySupport: AccessibilitySupport): IValidatedEditorOptions { - const accessibilityIsOff = (accessibilitySupport === AccessibilitySupport.Disabled); - return { - inDiffEditor: opts.inDiffEditor, - wordSeparators: opts.wordSeparators, - lineNumbersMinChars: opts.lineNumbersMinChars, - lineDecorationsWidth: opts.lineDecorationsWidth, - readOnly: opts.readOnly, - mouseStyle: opts.mouseStyle, - disableLayerHinting: opts.disableLayerHinting, - automaticLayout: opts.automaticLayout, - wordWrap: opts.wordWrap, - wordWrapColumn: opts.wordWrapColumn, - wordWrapMinified: opts.wordWrapMinified, - wrappingIndent: opts.wrappingIndent, - wordWrapBreakBeforeCharacters: opts.wordWrapBreakBeforeCharacters, - wordWrapBreakAfterCharacters: opts.wordWrapBreakAfterCharacters, - wordWrapBreakObtrusiveCharacters: opts.wordWrapBreakObtrusiveCharacters, - autoClosingBrackets: opts.autoClosingBrackets, - autoClosingQuotes: opts.autoClosingQuotes, - autoClosingOvertype: opts.autoClosingOvertype, - autoSurround: opts.autoSurround, - autoIndent: opts.autoIndent, - dragAndDrop: opts.dragAndDrop, - emptySelectionClipboard: opts.emptySelectionClipboard, - copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting, - useTabStops: opts.useTabStops, - multiCursorModifier: opts.multiCursorModifier, - multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping, - accessibilitySupport: opts.accessibilitySupport, - showUnused: opts.showUnused, - - viewInfo: { - extraEditorClassName: opts.viewInfo.extraEditorClassName, - disableMonospaceOptimizations: opts.viewInfo.disableMonospaceOptimizations, - rulers: opts.viewInfo.rulers, - ariaLabel: (accessibilityIsOff ? nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options.") : opts.viewInfo.ariaLabel), - renderLineNumbers: opts.viewInfo.renderLineNumbers, - renderCustomLineNumbers: opts.viewInfo.renderCustomLineNumbers, - cursorSurroundingLines: opts.viewInfo.cursorSurroundingLines, - glyphMargin: opts.viewInfo.glyphMargin, - revealHorizontalRightPadding: opts.viewInfo.revealHorizontalRightPadding, - roundedSelection: opts.viewInfo.roundedSelection, - overviewRulerLanes: opts.viewInfo.overviewRulerLanes, - overviewRulerBorder: opts.viewInfo.overviewRulerBorder, - cursorBlinking: opts.viewInfo.cursorBlinking, - mouseWheelZoom: opts.viewInfo.mouseWheelZoom, - cursorSmoothCaretAnimation: opts.viewInfo.cursorSmoothCaretAnimation, - cursorStyle: opts.viewInfo.cursorStyle, - cursorWidth: opts.viewInfo.cursorWidth, - hideCursorInOverviewRuler: opts.viewInfo.hideCursorInOverviewRuler, - scrollBeyondLastLine: opts.viewInfo.scrollBeyondLastLine, - scrollBeyondLastColumn: opts.viewInfo.scrollBeyondLastColumn, - smoothScrolling: opts.viewInfo.smoothScrolling, - stopRenderingLineAfter: opts.viewInfo.stopRenderingLineAfter, - renderWhitespace: opts.viewInfo.renderWhitespace, - renderControlCharacters: opts.viewInfo.renderControlCharacters, - fontLigatures: opts.viewInfo.fontLigatures, - renderIndentGuides: opts.viewInfo.renderIndentGuides, - highlightActiveIndentGuide: opts.viewInfo.highlightActiveIndentGuide, - renderLineHighlight: opts.viewInfo.renderLineHighlight, - scrollbar: opts.viewInfo.scrollbar, - minimap: { - enabled: opts.viewInfo.minimap.enabled, - side: opts.viewInfo.minimap.side, - renderCharacters: opts.viewInfo.minimap.renderCharacters, - showSlider: opts.viewInfo.minimap.showSlider, - maxColumn: opts.viewInfo.minimap.maxColumn - }, - fixedOverflowWidgets: opts.viewInfo.fixedOverflowWidgets - }, - - contribInfo: { - hover: opts.contribInfo.hover, - links: opts.contribInfo.links, - contextmenu: opts.contribInfo.contextmenu, - quickSuggestions: opts.contribInfo.quickSuggestions, - quickSuggestionsDelay: opts.contribInfo.quickSuggestionsDelay, - parameterHints: opts.contribInfo.parameterHints, - formatOnType: opts.contribInfo.formatOnType, - formatOnPaste: opts.contribInfo.formatOnPaste, - suggestOnTriggerCharacters: opts.contribInfo.suggestOnTriggerCharacters, - acceptSuggestionOnEnter: opts.contribInfo.acceptSuggestionOnEnter, - acceptSuggestionOnCommitCharacter: opts.contribInfo.acceptSuggestionOnCommitCharacter, - wordBasedSuggestions: opts.contribInfo.wordBasedSuggestions, - suggestSelection: opts.contribInfo.suggestSelection, - suggestFontSize: opts.contribInfo.suggestFontSize, - suggestLineHeight: opts.contribInfo.suggestLineHeight, - tabCompletion: opts.contribInfo.tabCompletion, - suggest: opts.contribInfo.suggest, - gotoLocation: opts.contribInfo.gotoLocation, - selectionHighlight: opts.contribInfo.selectionHighlight, - occurrencesHighlight: opts.contribInfo.occurrencesHighlight, - codeLens: opts.contribInfo.codeLens, - folding: opts.contribInfo.folding, - foldingStrategy: opts.contribInfo.foldingStrategy, - showFoldingControls: opts.contribInfo.showFoldingControls, - matchBrackets: opts.contribInfo.matchBrackets, - find: opts.contribInfo.find, - colorDecorators: opts.contribInfo.colorDecorators, - lightbulbEnabled: opts.contribInfo.lightbulbEnabled, - codeActionsOnSave: opts.contribInfo.codeActionsOnSave, - codeActionsOnSaveTimeout: opts.contribInfo.codeActionsOnSaveTimeout - } - }; - } - - public static createInternalEditorOptions(env: IEnvironmentalOptions, _opts: IValidatedEditorOptions) { - - let accessibilitySupport: AccessibilitySupport; - if (_opts.accessibilitySupport === 'auto') { - // The editor reads the `accessibilitySupport` from the environment - accessibilitySupport = env.accessibilitySupport; - } else if (_opts.accessibilitySupport === 'on') { - accessibilitySupport = AccessibilitySupport.Enabled; - } else { - accessibilitySupport = AccessibilitySupport.Disabled; - } - - // Disable some non critical features to get as best performance as possible - // See https://github.com/Microsoft/vscode/issues/26730 - const opts = this._tweakValidatedOptions(_opts, accessibilitySupport); + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorLayoutInfo { + const glyphMargin = options.get(EditorOptionId.glyphMargin); + const lineNumbersMinChars = options.get(EditorOptionId.lineNumbersMinChars); + const rawLineDecorationsWidth = options.get(EditorOptionId.lineDecorationsWidth); + const folding = options.get(EditorOptionId.folding); + const minimap = options.get(EditorOptionId.minimap); + const scrollbar = options.get(EditorOptionId.scrollbar); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); let lineDecorationsWidth: number; - if (typeof opts.lineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(opts.lineDecorationsWidth)) { - const multiple = parseFloat(opts.lineDecorationsWidth.substr(0, opts.lineDecorationsWidth.length - 2)); + if (typeof rawLineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(rawLineDecorationsWidth)) { + const multiple = parseFloat(rawLineDecorationsWidth.substr(0, rawLineDecorationsWidth.length - 2)); lineDecorationsWidth = multiple * env.fontInfo.typicalHalfwidthCharacterWidth; } else { - lineDecorationsWidth = _clampedInt(opts.lineDecorationsWidth, 0, 0, 1000); + lineDecorationsWidth = _clampedInt(rawLineDecorationsWidth, 0, 0, 1000); } - if (opts.contribInfo.folding) { + if (folding) { lineDecorationsWidth += 16; } - const layoutInfo = EditorLayoutProvider.compute({ + return EditorLayoutInfoComputer.compute({ outerWidth: env.outerWidth, outerHeight: env.outerHeight, - showGlyphMargin: opts.viewInfo.glyphMargin, + showGlyphMargin: glyphMargin, lineHeight: env.fontInfo.lineHeight, - showLineNumbers: (opts.viewInfo.renderLineNumbers !== RenderLineNumbersType.Off), - lineNumbersMinChars: opts.lineNumbersMinChars, + showLineNumbers: (renderLineNumbers.renderType !== RenderLineNumbersType.Off), + lineNumbersMinChars: lineNumbersMinChars, lineNumbersDigitCount: env.lineNumbersDigitCount, lineDecorationsWidth: lineDecorationsWidth, typicalHalfwidthCharacterWidth: env.fontInfo.typicalHalfwidthCharacterWidth, maxDigitWidth: env.fontInfo.maxDigitWidth, - verticalScrollbarWidth: opts.viewInfo.scrollbar.verticalScrollbarSize, - horizontalScrollbarHeight: opts.viewInfo.scrollbar.horizontalScrollbarSize, - scrollbarArrowSize: opts.viewInfo.scrollbar.arrowSize, - verticalScrollbarHasArrows: opts.viewInfo.scrollbar.verticalHasArrows, - minimap: opts.viewInfo.minimap.enabled, - minimapSide: opts.viewInfo.minimap.side, - minimapRenderCharacters: opts.viewInfo.minimap.renderCharacters, - minimapMaxColumn: opts.viewInfo.minimap.maxColumn, + verticalScrollbarWidth: scrollbar.verticalScrollbarSize, + horizontalScrollbarHeight: scrollbar.horizontalScrollbarSize, + scrollbarArrowSize: scrollbar.arrowSize, + verticalScrollbarHasArrows: scrollbar.verticalHasArrows, + minimap: minimap.enabled, + minimapSide: minimap.side, + minimapRenderCharacters: minimap.renderCharacters, + minimapMaxColumn: minimap.maxColumn, pixelRatio: env.pixelRatio }); - - let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null; - { - const wordWrap = opts.wordWrap; - const wordWrapColumn = opts.wordWrapColumn; - const wordWrapMinified = opts.wordWrapMinified; - - 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 - }; - } - } - - const wrappingInfo: EditorWrappingInfo = { - inDiffEditor: opts.inDiffEditor, - isDominatedByLongLines: env.isDominatedByLongLines, - isWordWrapMinified: bareWrappingInfo.isWordWrapMinified, - isViewportWrapping: bareWrappingInfo.isViewportWrapping, - wrappingColumn: bareWrappingInfo.wrappingColumn, - wrappingIndent: opts.wrappingIndent, - wordWrapBreakBeforeCharacters: opts.wordWrapBreakBeforeCharacters, - wordWrapBreakAfterCharacters: opts.wordWrapBreakAfterCharacters, - wordWrapBreakObtrusiveCharacters: opts.wordWrapBreakObtrusiveCharacters, - }; - - let className = 'monaco-editor'; - if (opts.viewInfo.extraEditorClassName) { - className += ' ' + opts.viewInfo.extraEditorClassName; - } - if (env.extraEditorClassName) { - className += ' ' + env.extraEditorClassName; - } - if (opts.viewInfo.fontLigatures) { - className += ' enable-ligatures'; - } - if (opts.mouseStyle === 'default') { - className += ' mouse-default'; - } else if (opts.mouseStyle === 'copy') { - className += ' mouse-copy'; - } - - return new InternalEditorOptions({ - canUseLayerHinting: opts.disableLayerHinting ? false : true, - pixelRatio: env.pixelRatio, - editorClassName: className, - lineHeight: env.fontInfo.lineHeight, - readOnly: opts.readOnly, - accessibilitySupport: accessibilitySupport, - multiCursorModifier: opts.multiCursorModifier, - multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping, - wordSeparators: opts.wordSeparators, - autoClosingBrackets: opts.autoClosingBrackets, - autoClosingQuotes: opts.autoClosingQuotes, - autoClosingOvertype: opts.autoClosingOvertype, - autoSurround: opts.autoSurround, - autoIndent: opts.autoIndent, - useTabStops: opts.useTabStops, - tabFocusMode: opts.readOnly ? true : env.tabFocusMode, - dragAndDrop: opts.dragAndDrop, - emptySelectionClipboard: opts.emptySelectionClipboard && env.emptySelectionClipboard, - copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting, - layoutInfo: layoutInfo, - fontInfo: env.fontInfo, - viewInfo: opts.viewInfo, - wrappingInfo: wrappingInfo, - contribInfo: opts.contribInfo, - showUnused: opts.showUnused, - }); } -} + public equals(a: EditorLayoutInfo, b: EditorLayoutInfo): boolean { + return ( + a.width === b.width + && a.height === b.height + && a.glyphMarginLeft === b.glyphMarginLeft + && a.glyphMarginWidth === b.glyphMarginWidth + && a.glyphMarginHeight === b.glyphMarginHeight + && a.lineNumbersLeft === b.lineNumbersLeft + && a.lineNumbersWidth === b.lineNumbersWidth + && a.lineNumbersHeight === b.lineNumbersHeight + && a.decorationsLeft === b.decorationsLeft + && a.decorationsWidth === b.decorationsWidth + && a.decorationsHeight === b.decorationsHeight + && a.contentLeft === b.contentLeft + && a.contentWidth === b.contentWidth + && a.contentHeight === b.contentHeight + && a.renderMinimap === b.renderMinimap + && a.minimapLeft === b.minimapLeft + && a.minimapWidth === b.minimapWidth + && a.viewportColumn === b.viewportColumn + && a.verticalScrollbarWidth === b.verticalScrollbarWidth + && a.horizontalScrollbarHeight === b.horizontalScrollbarHeight + && EditorLayoutInfoComputer._equalsOverviewRuler(a.overviewRuler, b.overviewRuler) + ); + } -/** - * @internal - */ -export interface IEditorLayoutProviderOpts { - readonly outerWidth: number; - readonly outerHeight: number; + /** + * @internal + */ + private static _equalsOverviewRuler(a: OverviewRulerPosition, b: OverviewRulerPosition): boolean { + return ( + a.width === b.width + && a.height === b.height + && a.top === b.top + && a.right === b.right + ); + } - readonly showGlyphMargin: boolean; - readonly lineHeight: number; - - readonly showLineNumbers: boolean; - readonly lineNumbersMinChars: number; - readonly lineNumbersDigitCount: number; - - readonly lineDecorationsWidth: number; - - readonly typicalHalfwidthCharacterWidth: number; - readonly maxDigitWidth: number; - - readonly verticalScrollbarWidth: number; - readonly verticalScrollbarHasArrows: boolean; - readonly scrollbarArrowSize: number; - readonly horizontalScrollbarHeight: number; - - readonly minimap: boolean; - readonly minimapSide: string; - readonly minimapRenderCharacters: boolean; - readonly minimapMaxColumn: number; - readonly pixelRatio: number; -} - -/** - * @internal - */ -export class EditorLayoutProvider { public static compute(_opts: IEditorLayoutProviderOpts): EditorLayoutInfo { const outerWidth = _opts.outerWidth | 0; const outerHeight = _opts.outerHeight | 0; @@ -2588,300 +2692,169 @@ export class EditorLayoutProvider { } } -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\''; +//#endregion -/** - * @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, -}; +//#region wrappingInfo -/** - * @internal - */ -export const EDITOR_MODEL_DEFAULTS = { - tabSize: 4, - indentSize: 4, - insertSpaces: true, - detectIndentation: true, - trimAutoWhitespace: true, - largeFileOptimizations: true -}; - -/** - * @internal - */ -export const EDITOR_DEFAULTS: IValidatedEditorOptions = { - inDiffEditor: false, - wordSeparators: USUAL_WORD_SEPARATORS, - lineNumbersMinChars: 5, - lineDecorationsWidth: 10, - readOnly: false, - mouseStyle: 'text', - disableLayerHinting: false, - automaticLayout: false, - wordWrap: 'off', - wordWrapColumn: 80, - wordWrapMinified: true, - wrappingIndent: WrappingIndent.Same, - wordWrapBreakBeforeCharacters: '([{‘“〈《「『【〔([{「£¥$£¥++', - wordWrapBreakAfterCharacters: ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」', - wordWrapBreakObtrusiveCharacters: '.', - autoClosingBrackets: 'languageDefined', - autoClosingQuotes: 'languageDefined', - autoClosingOvertype: 'auto', - autoSurround: 'languageDefined', - autoIndent: true, - dragAndDrop: true, - emptySelectionClipboard: true, - copyWithSyntaxHighlighting: true, - useTabStops: true, - multiCursorModifier: 'altKey', - multiCursorMergeOverlapping: true, - accessibilitySupport: 'auto', - showUnused: true, - - viewInfo: { - extraEditorClassName: '', - disableMonospaceOptimizations: false, - rulers: [], - ariaLabel: nls.localize('editorViewAccessibleLabel', "Editor content"), - renderLineNumbers: RenderLineNumbersType.On, - renderCustomLineNumbers: null, - cursorSurroundingLines: 0, - glyphMargin: true, - revealHorizontalRightPadding: 30, - roundedSelection: true, - overviewRulerLanes: 2, - overviewRulerBorder: true, - cursorBlinking: TextEditorCursorBlinkingStyle.Blink, - mouseWheelZoom: false, - cursorSmoothCaretAnimation: false, - cursorStyle: TextEditorCursorStyle.Line, - cursorWidth: 0, - hideCursorInOverviewRuler: false, - scrollBeyondLastLine: true, - scrollBeyondLastColumn: 5, - smoothScrolling: false, - stopRenderingLineAfter: 10000, - renderWhitespace: 'none', - renderControlCharacters: false, - fontLigatures: false, - renderIndentGuides: true, - highlightActiveIndentGuide: true, - renderLineHighlight: 'line', - scrollbar: { - vertical: ScrollbarVisibility.Auto, - horizontal: ScrollbarVisibility.Auto, - arrowSize: 11, - useShadows: true, - verticalHasArrows: false, - horizontalHasArrows: false, - horizontalScrollbarSize: 10, - horizontalSliderSize: 10, - verticalScrollbarSize: 14, - verticalSliderSize: 14, - handleMouseWheel: true, - mouseWheelScrollSensitivity: 1, - fastScrollSensitivity: 5, - }, - minimap: { - enabled: true, - side: 'right', - showSlider: 'mouseover', - renderCharacters: true, - maxColumn: 120 - }, - fixedOverflowWidgets: false, - }, - - contribInfo: { - hover: { - enabled: true, - delay: 300, - sticky: true - }, - links: true, - contextmenu: true, - quickSuggestions: { other: true, comments: false, strings: false }, - quickSuggestionsDelay: 10, - parameterHints: { - enabled: true, - cycle: false - }, - formatOnType: false, - formatOnPaste: false, - suggestOnTriggerCharacters: true, - acceptSuggestionOnEnter: 'on', - acceptSuggestionOnCommitCharacter: true, - wordBasedSuggestions: true, - suggestSelection: 'recentlyUsed', - suggestFontSize: 0, - suggestLineHeight: 0, - tabCompletion: 'off', - suggest: { - filterGraceful: true, - snippets: 'inline', - snippetsPreventQuickSuggestions: true, - localityBonus: false, - shareSuggestSelections: false, - showIcons: true, - maxVisibleSuggestions: 12, - filteredTypes: Object.create(null) - }, - gotoLocation: { - multiple: 'peek' - }, - selectionHighlight: true, - occurrencesHighlight: true, - codeLens: true, - folding: true, - foldingStrategy: 'auto', - showFoldingControls: 'mouseover', - matchBrackets: true, - find: { - seedSearchStringFromSelection: true, - autoFindInSelection: false, - globalFindClipboard: false, - addExtraSpaceOnTop: true - }, - colorDecorators: true, - lightbulbEnabled: true, - codeActionsOnSave: {}, - codeActionsOnSaveTimeout: 750 - }, -}; - -export interface IRawEditorOptionsBag { - [key: string]: any; +export interface EditorWrappingInfo { + readonly isDominatedByLongLines: boolean; + readonly isWordWrapMinified: boolean; + readonly isViewportWrapping: boolean; + readonly wrappingColumn: number; } -/** - * @internal - */ -export class RawEditorOptions { - private readonly _values: any[] = []; - public _read(id: EditorOptionId): T | undefined { - return this._values[id]; +class EditorWrappingInfoComputer extends BaseEditorOption { + public mix(a: undefined, b: undefined): undefined { + return undefined; } - public _write(id: EditorOptionId, value: T | undefined): void { - this._values[id] = value; + public validate(input: undefined): undefined { + return undefined; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorWrappingInfo { + const wordWrap = options.get(EditorOptionId.wordWrap); + const wordWrapColumn = options.get(EditorOptionId.wordWrapColumn); + const wordWrapMinified = options.get(EditorOptionId.wordWrapMinified); + const layoutInfo = options.get(EditorOptionId.layoutInfo); + const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + + 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, + }; + } + public equals(a: EditorWrappingInfo, b: EditorWrappingInfo): boolean { + return ( + a.isDominatedByLongLines === b.isDominatedByLongLines + && a.isWordWrapMinified === b.isWordWrapMinified + && a.isViewportWrapping === b.isViewportWrapping + && a.wrappingColumn === b.wrappingColumn + ); } } -/** - * @internal - */ -export class ValidatedEditorOptions { - private readonly _values: any[] = []; - public _read(option: EditorOptionId): T { - return this._values[option]; - } - public _write(option: EditorOptionId, value: T): void { - this._values[option] = value; - } -} - -/** - * @internal - */ -export class ComputedEditorOptions { - private readonly _values: any[] = []; - public _read(id: EditorOptionId): T { - return this._values[id]; - } - public _write(id: EditorOptionId, value: T): void { - this._values[id] = value; - } -} - -/** - * @internal - */ -export class ChangedEditorOptions { - private readonly _values: boolean[] = []; - public get(id: EditorOptionId): boolean { - return this._values[id]; - } - public _write(id: EditorOptionId, value: boolean): void { - this._values[id] = value; - } -} - -export interface IEditorOption { - readonly id: EditorOptionId; - readonly name: string; - readonly defaultValue: T1; - read(options: IRawEditorOptionsBag): T1 | undefined; - mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; - validate(input: T1 | undefined): T2; - compute(value: T2): T3; - equals(a: T3, b: T3): boolean; -} - -class BooleanEditorOption implements IEditorOption { - public readonly id: EditorOptionId; - public readonly name: string; - public readonly defaultValue: boolean; - - constructor(id: EditorOptionId, name: string, defaultValue: boolean) { - this.id = id; - this.name = name; - this.defaultValue = defaultValue; - } - - public read(options: IRawEditorOptionsBag): boolean | undefined { - return options[this.name]; - } - - public mix(a: boolean | undefined, b: boolean | undefined): boolean | undefined { - return (typeof b !== 'undefined' ? b : a); - } - - public validate(input: boolean | undefined): boolean { - return _boolean(input, this.defaultValue); - } - - public compute(value: boolean): boolean { - return value; - } - - public equals(a: boolean, b: boolean): boolean { - return (a === b); - } -} - -/** - * @internal - */ -export const editorOptionsRegistry: IEditorOption[] = []; - -function registerEditorOption(option: IEditorOption): IEditorOption { - editorOptionsRegistry[option.id] = option; - return option; -} +//#endregion export const enum EditorOptionId { + accessibilitySupport, + ariaLabel, + fastScrollSensitivity, + folding, + glyphMargin, + inDiffEditor, + lineDecorationsWidth, + lineNumbersMinChars, + minimap, + mouseWheelScrollSensitivity, renderFinalNewline, + renderLineNumbers, + scrollbar, selectionClipboard, selectOnLineNumbers, + wordWrap, + wordWrapBreakAfterCharacters, + wordWrapBreakBeforeCharacters, + wordWrapBreakObtrusiveCharacters, + wordWrapColumn, + wordWrapMinified, + wrappingIndent, + + layoutInfo, + wrappingInfo, } export const EditorOption = { - renderFinalNewline: registerEditorOption(new BooleanEditorOption(EditorOptionId.renderFinalNewline, 'renderFinalNewline', true)), - selectionClipboard: registerEditorOption(new BooleanEditorOption(EditorOptionId.selectionClipboard, 'selectionClipboard', true)), - selectOnLineNumbers: registerEditorOption(new BooleanEditorOption(EditorOptionId.selectOnLineNumbers, 'selectOnLineNumbers', true)), + accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOptionId.accessibilitySupport, 'accessibilitySupport', 'auto')), + ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOptionId.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOptionId.accessibilitySupport])), + fastScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOptionId.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))), + folding: registerEditorOption(new EditorBooleanOption(EditorOptionId.folding, 'folding', true)), + glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOptionId.glyphMargin, 'glyphMargin', true)), + inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOptionId.inDiffEditor, 'inDiffEditor', false)), + lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOptionId.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOptionId.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), + minimap: registerEditorOption(new EditorMinimapOption(EditorOptionId.minimap, 'minimap', { + enabled: true, + side: 'right', + showSlider: 'mouseover', + renderCharacters: true, + maxColumn: 120, + })), + mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOptionId.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), + renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOptionId.renderFinalNewline, 'renderFinalNewline', true)), + renderLineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOptionId.renderLineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), + scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOptionId.scrollbar, 'scrollbar', { + vertical: ScrollbarVisibility.Auto, + horizontal: ScrollbarVisibility.Auto, + arrowSize: 11, + useShadows: true, + verticalHasArrows: false, + horizontalHasArrows: false, + horizontalScrollbarSize: 10, + horizontalSliderSize: 10, + verticalScrollbarSize: 14, + verticalSliderSize: 14, + handleMouseWheel: true, + })), + selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectionClipboard, 'selectionClipboard', true)), + selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectOnLineNumbers, 'selectOnLineNumbers', true)), + wordWrap: registerEditorOption(new EditorEnumOption<'off' | 'on' | 'wordWrapColumn' | 'bounded'>(EditorOptionId.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), + wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), + wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), + wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), + wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOptionId.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), + wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOptionId.wordWrapMinified, 'wordWrapMinified', true)), + wrappingIndent: registerEditorOption(new EditorEnumOption<'none' | 'same' | 'indent' | 'deepIndent', WrappingIndent>(EditorOptionId.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), + + // Leave these at the end! + layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOptionId.layoutInfo, 'layoutInfo', undefined, [EditorOptionId.glyphMargin, EditorOptionId.lineDecorationsWidth, EditorOptionId.folding, EditorOptionId.minimap, EditorOptionId.scrollbar, EditorOptionId.renderLineNumbers])), + wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOptionId.wrappingInfo, 'wrappingInfo', undefined, [EditorOptionId.wordWrap, EditorOptionId.wordWrapColumn, EditorOptionId.wordWrapMinified, EditorOptionId.layoutInfo, EditorOptionId.accessibilitySupport])), }; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index 87c3878b61c..80775a63bd2 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -6,7 +6,7 @@ import { CharCode } from 'vs/base/common/charCode'; import { onUnexpectedError } from 'vs/base/common/errors'; import * as strings from 'vs/base/common/strings'; -import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy } from 'vs/editor/common/config/editorOptions'; +import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -112,7 +112,7 @@ export class CursorConfiguration { public static shouldRecreate(e: IConfigurationChangedEvent): boolean { return ( - e.layoutInfo + e.hasChanged(EditorOptionId.layoutInfo) || e.wordSeparators || e.emptySelectionClipboard || e.multiCursorMergeOverlapping @@ -133,13 +133,15 @@ export class CursorConfiguration { ) { this._languageIdentifier = languageIdentifier; - let c = configuration.editor; + const c = configuration.editor; + const options = configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.readOnly = c.readOnly; this.tabSize = modelOptions.tabSize; this.indentSize = modelOptions.indentSize; this.insertSpaces = modelOptions.insertSpaces; - this.pageSize = Math.max(1, Math.floor(c.layoutInfo.height / c.fontInfo.lineHeight) - 2); + this.pageSize = Math.max(1, Math.floor(layoutInfo.height / c.fontInfo.lineHeight) - 2); this.lineHeight = c.lineHeight; this.useTabStops = c.useTabStops; this.wordSeparators = c.wordSeparators; diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index f070525b99b..6c954159234 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -152,8 +152,7 @@ export interface IConfiguration extends IDisposable { onDidChange(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable; readonly editor: editorOptions.InternalEditorOptions; - - getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue; + readonly options: editorOptions.IComputedEditorOptions; setMaxLineNumber(maxLineNumber: number): void; updateOptions(newOptions: editorOptions.IEditorOptions): void; diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 1af333dd0a4..d3b4118c433 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -332,6 +332,15 @@ export enum CursorChangeReason { Redo = 6 } +export enum AccessibilitySupport { + /** + * This should be the browser case where it is not known if a screen reader is attached or no. + */ + Unknown = 0, + Disabled = 1, + Enabled = 2 +} + export enum RenderMinimap { None = 0, Small = 1, @@ -431,9 +440,30 @@ export enum RenderLineNumbersType { } export enum EditorOptionId { - renderFinalNewline = 0, - selectionClipboard = 1, - selectOnLineNumbers = 2 + accessibilitySupport = 0, + ariaLabel = 1, + fastScrollSensitivity = 2, + folding = 3, + glyphMargin = 4, + inDiffEditor = 5, + lineDecorationsWidth = 6, + lineNumbersMinChars = 7, + minimap = 8, + mouseWheelScrollSensitivity = 9, + renderFinalNewline = 10, + renderLineNumbers = 11, + scrollbar = 12, + selectionClipboard = 13, + selectOnLineNumbers = 14, + wordWrap = 15, + wordWrapBreakAfterCharacters = 16, + wordWrapBreakBeforeCharacters = 17, + wordWrapBreakObtrusiveCharacters = 18, + wordWrapColumn = 19, + wordWrapMinified = 20, + wrappingIndent = 21, + layoutInfo = 22, + wrappingInfo = 23 } /** diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index 962579d3f0f..47006636def 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -6,7 +6,7 @@ import * as errors from 'vs/base/common/errors'; import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { ScrollEvent } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { ScrollType } from 'vs/editor/common/editorCommon'; @@ -34,32 +34,32 @@ export class ViewConfigurationChangedEvent { public readonly type = ViewEventType.ViewConfigurationChanged; + public readonly _source: IConfigurationChangedEvent; public readonly canUseLayerHinting: boolean; public readonly pixelRatio: boolean; public readonly editorClassName: boolean; public readonly lineHeight: boolean; public readonly readOnly: boolean; - public readonly accessibilitySupport: boolean; public readonly emptySelectionClipboard: boolean; public readonly copyWithSyntaxHighlighting: boolean; - public readonly layoutInfo: boolean; public readonly fontInfo: boolean; public readonly viewInfo: boolean; - public readonly wrappingInfo: boolean; constructor(source: IConfigurationChangedEvent) { + this._source = source; this.canUseLayerHinting = source.canUseLayerHinting; this.pixelRatio = source.pixelRatio; this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight; this.readOnly = source.readOnly; - this.accessibilitySupport = source.accessibilitySupport; this.emptySelectionClipboard = source.emptySelectionClipboard; this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; - this.layoutInfo = source.layoutInfo; this.fontInfo = source.fontInfo; this.viewInfo = source.viewInfo; - this.wrappingInfo = source.wrappingInfo; + } + + public hasChanged(id: EditorOptionId): boolean { + return this._source.hasChanged(id); } } diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index ad24479b4b2..978aa54a3bb 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -6,7 +6,7 @@ import { Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { IScrollDimensions, IScrollPosition, ScrollEvent, Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { LinesLayout } from 'vs/editor/common/viewLayout/linesLayout'; import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; @@ -27,14 +27,17 @@ export class ViewLayout extends Disposable implements IViewLayout { super(); this._configuration = configuration; + const options = this._configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._linesLayout = new LinesLayout(lineCount, this._configuration.editor.lineHeight); this.scrollable = this._register(new Scrollable(0, scheduleAtNextAnimationFrame)); this._configureSmoothScrollDuration(); this.scrollable.setScrollDimensions({ - width: configuration.editor.layoutInfo.contentWidth, - height: configuration.editor.layoutInfo.contentHeight + width: layoutInfo.contentWidth, + height: layoutInfo.contentHeight }); this.onDidScroll = this.scrollable.onScroll; @@ -59,10 +62,12 @@ export class ViewLayout extends Disposable implements IViewLayout { if (e.lineHeight) { this._linesLayout.setLineHeight(this._configuration.editor.lineHeight); } - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { + const options = this._configuration.options; + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.scrollable.setScrollDimensions({ - width: this._configuration.editor.layoutInfo.contentWidth, - height: this._configuration.editor.layoutInfo.contentHeight + width: layoutInfo.contentWidth, + height: layoutInfo.contentHeight }); } if (e.viewInfo) { @@ -83,7 +88,9 @@ export class ViewLayout extends Disposable implements IViewLayout { // ---- end view event handlers private _getHorizontalScrollbarHeight(scrollDimensions: IScrollDimensions): number { - if (this._configuration.editor.viewInfo.scrollbar.horizontal === ScrollbarVisibility.Hidden) { + const options = this._configuration.options; + const scrollbar = options.get(EditorOptionId.scrollbar); + if (scrollbar.horizontal === ScrollbarVisibility.Hidden) { // horizontal scrollbar not visible return 0; } @@ -91,7 +98,7 @@ export class ViewLayout extends Disposable implements IViewLayout { // horizontal scrollbar not visible return 0; } - return this._configuration.editor.viewInfo.scrollbar.horizontalScrollbarSize; + return scrollbar.horizontalScrollbarSize; } private _getTotalHeight(): number { @@ -138,7 +145,9 @@ export class ViewLayout extends Disposable implements IViewLayout { } private _computeScrollWidth(maxLineWidth: number, viewportWidth: number): number { - let isViewportWrapping = this._configuration.editor.wrappingInfo.isViewportWrapping; + const options = this._configuration.options; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + let isViewportWrapping = wrappingInfo.isViewportWrapping; if (!isViewportWrapping) { const extraHorizontalSpace = this._configuration.editor.viewInfo.scrollBeyondLastColumn * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; const whitespaceMinWidth = this._linesLayout.getWhitespaceMinWidth(); diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 65284147a64..73350e18214 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import * as strings from 'vs/base/common/strings'; -import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -60,20 +60,26 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } else { const conf = this.configuration.editor; + const options = this.configuration.options; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = options.get(EditorOptionId.wrappingIndent); let hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( - conf.wrappingInfo.wordWrapBreakBeforeCharacters, - conf.wrappingInfo.wordWrapBreakAfterCharacters, - conf.wrappingInfo.wordWrapBreakObtrusiveCharacters + wordWrapBreakBeforeCharacters, + wordWrapBreakAfterCharacters, + wordWrapBreakObtrusiveCharacters ); this.lines = new SplitLinesCollection( this.model, hardWrappingLineMapperFactory, this.model.getOptions().tabSize, - conf.wrappingInfo.wrappingColumn, + wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth, - conf.wrappingInfo.wrappingIndent + wrappingIndent ); } @@ -147,8 +153,11 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel let restorePreviousViewportStart = false; const conf = this.configuration.editor; + const options = this.configuration.options; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingIndent = options.get(EditorOptionId.wrappingIndent); - if (this.lines.setWrappingSettings(conf.wrappingInfo.wrappingIndent, conf.wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth)) { + if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth)) { eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index d35752a078d..3b31b2e3b57 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -23,7 +23,7 @@ import { toDisposable } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_REPLACE_INPUT_FOCUSED, FIND_IDS, MATCHES_LIMIT } from 'vs/editor/contrib/find/findModel'; import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/findState'; @@ -183,11 +183,11 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } this._updateButtons(); } - if (e.layoutInfo) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { this._tryUpdateWidgetWidth(); } - if (e.accessibilitySupport) { + if (e.hasChanged(EditorOptionId.accessibilitySupport)) { this.updateAccessibilitySupport(); } @@ -642,7 +642,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas return; } - const editorContentWidth = this._codeEditor.getConfiguration().layoutInfo.contentWidth; + const layoutInfo = this._codeEditor.getLayoutInfo(); + const editorContentWidth = layoutInfo.contentWidth; if (editorContentWidth <= 0) { // for example, diff view original editor @@ -652,8 +653,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas dom.removeClass(this._domNode, 'hiddenEditor'); } - const editorWidth = this._codeEditor.getConfiguration().layoutInfo.width; - const minimapWidth = this._codeEditor.getConfiguration().layoutInfo.minimapWidth; + const editorWidth = layoutInfo.width; + const minimapWidth = layoutInfo.minimapWidth; let collapsedFindWidget = false; let reducedFindWidget = false; let narrowFindWidget = false; @@ -1187,7 +1188,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas if (!this._resized || currentWidth === FIND_WIDGET_INITIAL_WIDTH) { // 1. never resized before, double click should maximizes it // 2. users resized it already but its width is the same as default - width = this._codeEditor.getConfiguration().layoutInfo.width - 28 - this._codeEditor.getConfiguration().layoutInfo.minimapWidth - 15; + const layoutInfo = this._codeEditor.getLayoutInfo(); + width = layoutInfo.width - 28 - layoutInfo.minimapWidth - 15; this._resized = true; } else { /** diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index cd7cdbe1d13..4a705db696e 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -18,7 +18,7 @@ import { FoldingModel, setCollapseStateAtLevel, CollapseMemento, setCollapseStat import { FoldingDecorationProvider } from './foldingDecorations'; import { FoldingRegions, FoldingRegion } from './foldingRanges'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IMarginData, IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { HiddenRangeModel } from 'vs/editor/contrib/folding/hiddenRangeModel'; import { IRange } from 'vs/editor/common/core/range'; @@ -87,7 +87,8 @@ export class FoldingController extends Disposable implements IEditorContribution ) { super(); this.editor = editor; - this._isEnabled = this.editor.getConfiguration().contribInfo.folding; + const options = this.editor.getOptions(); + this._isEnabled = options.get(EditorOptionId.folding); this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover'; this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation'; @@ -109,9 +110,10 @@ export class FoldingController extends Disposable implements IEditorContribution this._register(this.editor.onDidChangeModel(() => this.onModelChanged())); this._register(this.editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.contribInfo) { + if (e.contribInfo || e.hasChanged(EditorOptionId.folding)) { let oldIsEnabled = this._isEnabled; - this._isEnabled = this.editor.getConfiguration().contribInfo.folding; + const options = this.editor.getOptions(); + this._isEnabled = options.get(EditorOptionId.folding); this.foldingEnabled.set(this._isEnabled); if (oldIsEnabled !== this._isEnabled) { this.onModelChanged(); diff --git a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts index 1981153c0c8..dc640cc2b3c 100644 --- a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts +++ b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts @@ -31,6 +31,7 @@ import { contrastBorder, editorWidgetBackground, widgetShadow, editorWidgetForeg import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { AccessibilityHelpNLS } from 'vs/editor/common/standaloneStrings'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new RawContextKey('accessibilityHelpWidgetVisible', false); @@ -224,6 +225,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { private _buildContent() { let opts = this._editor.getConfiguration(); + const options = this._editor.getOptions(); const selections = this._editor.getSelections(); let charactersSelected = 0; @@ -239,7 +241,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { let text = getSelectionLabel(selections, charactersSelected); - if (opts.wrappingInfo.inDiffEditor) { + if (options.get(EditorOptionId.inDiffEditor)) { if (opts.readOnly) { text += AccessibilityHelpNLS.readonlyDiffEditor; } else { diff --git a/src/vs/editor/standalone/browser/standaloneEditor.ts b/src/vs/editor/standalone/browser/standaloneEditor.ts index c3936c2a1b7..70d17b7f81b 100644 --- a/src/vs/editor/standalone/browser/standaloneEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneEditor.ts @@ -352,6 +352,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { remeasureFonts: remeasureFonts, // enums + AccessibilitySupport: standaloneEnums.AccessibilitySupport, ScrollbarVisibility: standaloneEnums.ScrollbarVisibility, WrappingIndent: standaloneEnums.WrappingIndent, OverviewRulerLane: standaloneEnums.OverviewRulerLane, @@ -372,6 +373,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { EditorOptionId: standaloneEnums.EditorOptionId, // classes + BaseEditorOption: editorOptions.BaseEditorOption, InternalEditorOptions: editorOptions.InternalEditorOptions, BareFontInfo: BareFontInfo, FontInfo: FontInfo, diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index b35959ae2c2..649c7f9718b 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorHoverOptions } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; @@ -67,8 +67,10 @@ suite('Common Editor Config', () => { } function assertWrapping(config: TestConfiguration, isViewportWrapping: boolean, wrappingColumn: number): void { - assert.equal(config.editor.wrappingInfo.isViewportWrapping, isViewportWrapping); - assert.equal(config.editor.wrappingInfo.wrappingColumn, wrappingColumn); + const options = config.options; + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + assert.equal(wrappingInfo.isViewportWrapping, isViewportWrapping); + assert.equal(wrappingInfo.wrappingColumn, wrappingColumn); } test('wordWrap default', () => { diff --git a/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts b/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts index e35df432fcd..593f7b74126 100644 --- a/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts +++ b/src/vs/editor/test/common/viewLayout/editorLayoutProvider.test.ts @@ -4,12 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { EditorLayoutInfo, EditorLayoutProvider, IEditorLayoutProviderOpts, RenderMinimap } from 'vs/editor/common/config/editorOptions'; +import { EditorLayoutInfo, EditorLayoutInfoComputer, IEditorLayoutProviderOpts, RenderMinimap } from 'vs/editor/common/config/editorOptions'; suite('Editor ViewLayout - EditorLayoutProvider', () => { function doTest(input: IEditorLayoutProviderOpts, expected: EditorLayoutInfo): void { - let actual = EditorLayoutProvider.compute(input); + let actual = EditorLayoutInfoComputer.compute(input); assert.deepEqual(actual, expected); } diff --git a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts index 9b053429da8..20ba2e12437 100644 --- a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts +++ b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts @@ -19,6 +19,7 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer' import { ILineMapping, ISimpleModel, SplitLine, SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection'; import { ViewLineData } from 'vs/editor/common/viewModel/viewModel'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; suite('Editor ViewModel - SplitLinesCollection', () => { test('SplitLine', () => { @@ -88,15 +89,20 @@ suite('Editor ViewModel - SplitLinesCollection', () => { }); function withSplitLinesCollection(text: string, callback: (model: TextModel, linesCollection: SplitLinesCollection) => void): void { - let config = new TestConfiguration({}); + const config = new TestConfiguration({}); + const wrappingInfo = config.options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = config.options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = config.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = config.options.get(EditorOptionId.wrappingIndent); - let hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( - config.editor.wrappingInfo.wordWrapBreakBeforeCharacters, - config.editor.wrappingInfo.wordWrapBreakAfterCharacters, - config.editor.wrappingInfo.wordWrapBreakObtrusiveCharacters + const hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( + wordWrapBreakBeforeCharacters, + wordWrapBreakAfterCharacters, + wordWrapBreakObtrusiveCharacters ); - let model = TextModel.createFromString([ + const model = TextModel.createFromString([ 'int main() {', '\tprintf("Hello world!");', '}', @@ -105,13 +111,13 @@ suite('Editor ViewModel - SplitLinesCollection', () => { '}', ].join('\n')); - let linesCollection = new SplitLinesCollection( + const linesCollection = new SplitLinesCollection( model, hardWrappingLineMapperFactory, model.getOptions().tabSize, - config.editor.wrappingInfo.wrappingColumn, + wrappingInfo.wrappingColumn, config.editor.fontInfo.typicalFullwidthCharacterWidth / config.editor.fontInfo.typicalHalfwidthCharacterWidth, - config.editor.wrappingInfo.wrappingIndent + wrappingIndent ); callback(model, linesCollection); @@ -732,25 +738,30 @@ suite('SplitLinesCollection', () => { }); function withSplitLinesCollection(model: TextModel, wordWrap: 'on' | 'off' | 'wordWrapColumn' | 'bounded', wordWrapColumn: number, callback: (splitLinesCollection: SplitLinesCollection) => void): void { - let configuration = new TestConfiguration({ + const configuration = new TestConfiguration({ wordWrap: wordWrap, wordWrapColumn: wordWrapColumn, wrappingIndent: 'indent' }); + const wrappingInfo = configuration.options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = configuration.options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = configuration.options.get(EditorOptionId.wrappingIndent); - let factory = new CharacterHardWrappingLineMapperFactory( - configuration.editor.wrappingInfo.wordWrapBreakBeforeCharacters, - configuration.editor.wrappingInfo.wordWrapBreakAfterCharacters, - configuration.editor.wrappingInfo.wordWrapBreakObtrusiveCharacters + const factory = new CharacterHardWrappingLineMapperFactory( + wordWrapBreakBeforeCharacters, + wordWrapBreakAfterCharacters, + wordWrapBreakObtrusiveCharacters ); - let linesCollection = new SplitLinesCollection( + const linesCollection = new SplitLinesCollection( model, factory, model.getOptions().tabSize, - configuration.editor.wrappingInfo.wrappingColumn, + wrappingInfo.wrappingColumn, configuration.editor.fontInfo.typicalFullwidthCharacterWidth / configuration.editor.fontInfo.typicalHalfwidthCharacterWidth, - configuration.editor.wrappingInfo.wrappingIndent + wrappingIndent ); callback(linesCollection); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 87d85008895..32d7a932be4 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2408,6 +2408,15 @@ declare namespace monaco.editor { readonly reason: CursorChangeReason; } + export enum AccessibilitySupport { + /** + * This should be the browser case where it is not known if a screen reader is attached or no. + */ + Unknown = 0, + Disabled = 1, + Enabled = 2 + } + /** * Configuration options for editor scrollbars */ @@ -2653,7 +2662,7 @@ declare namespace monaco.editor { * Otherwise, line numbers will not be rendered. * Defaults to true. */ - lineNumbers?: 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); + lineNumbers?: LineNumbersType; /** * Controls the minimal number of visible leading and trailing lines surrounding the cursor. * Defaults to 0. @@ -2826,7 +2835,7 @@ declare namespace monaco.editor { * Control indentation of wrapped lines. Can be: 'none', 'same', 'indent' or 'deepIndent'. * Defaults to 'same' in vscode and to 'none' in monaco-editor. */ - wrappingIndent?: string; + wrappingIndent?: 'none' | 'same' | 'indent' | 'deepIndent'; /** * Configure word wrapping characters. A break will be introduced before these characters. * Defaults to '{([+'. @@ -3105,6 +3114,8 @@ declare namespace monaco.editor { * Controls fading out of unused variables. */ showUnused?: boolean; + layoutInfo?: undefined; + wrappingInfo?: undefined; } /** @@ -3228,30 +3239,6 @@ declare namespace monaco.editor { UnderlineThin = 6 } - 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; - readonly mouseWheelScrollSensitivity: number; - readonly fastScrollSensitivity: number; - } - - export interface InternalEditorMinimapOptions { - readonly enabled: boolean; - readonly side: 'right' | 'left'; - readonly showSlider: 'always' | 'mouseover'; - readonly renderCharacters: boolean; - readonly maxColumn: number; - } - export interface InternalEditorFindOptions { readonly seedSearchStringFromSelection: boolean; readonly autoFindInSelection: boolean; @@ -3284,33 +3271,10 @@ declare namespace monaco.editor { readonly cycle: boolean; } - export interface EditorWrappingInfo { - readonly inDiffEditor: boolean; - readonly isDominatedByLongLines: boolean; - readonly isWordWrapMinified: boolean; - readonly isViewportWrapping: boolean; - readonly wrappingColumn: number; - readonly wrappingIndent: WrappingIndent; - readonly wordWrapBreakBeforeCharacters: string; - readonly wordWrapBreakAfterCharacters: string; - readonly wordWrapBreakObtrusiveCharacters: string; - } - - export enum RenderLineNumbersType { - Off = 0, - On = 1, - Relative = 2, - Interval = 3, - Custom = 4 - } - export interface InternalEditorViewOptions { readonly extraEditorClassName: string; readonly disableMonospaceOptimizations: boolean; readonly rulers: number[]; - readonly ariaLabel: string; - readonly renderLineNumbers: RenderLineNumbersType; - readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null; readonly cursorSurroundingLines: number; readonly glyphMargin: boolean; readonly revealHorizontalRightPadding: number; @@ -3333,8 +3297,6 @@ declare namespace monaco.editor { readonly renderIndentGuides: boolean; readonly highlightActiveIndentGuide: boolean; readonly renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; - readonly scrollbar: InternalEditorScrollbarOptions; - readonly minimap: InternalEditorMinimapOptions; readonly fixedOverflowWidgets: boolean; } @@ -3364,7 +3326,6 @@ declare namespace monaco.editor { readonly selectionHighlight: boolean; readonly occurrencesHighlight: boolean; readonly codeLens: boolean; - readonly folding: boolean; readonly foldingStrategy: 'auto' | 'indentation'; readonly showFoldingControls: 'always' | 'mouseover'; readonly matchBrackets: boolean; @@ -3399,13 +3360,124 @@ declare namespace monaco.editor { readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly copyWithSyntaxHighlighting: boolean; - readonly layoutInfo: EditorLayoutInfo; readonly fontInfo: FontInfo; readonly viewInfo: InternalEditorViewOptions; - readonly wrappingInfo: EditorWrappingInfo; readonly contribInfo: EditorContribOptions; } + /** + * An event describing that the configuration of the editor has changed. + */ + export interface IConfigurationChangedEvent { + hasChanged(id: EditorOptionId): boolean; + readonly canUseLayerHinting: boolean; + readonly pixelRatio: boolean; + readonly editorClassName: boolean; + readonly lineHeight: boolean; + readonly readOnly: boolean; + readonly multiCursorModifier: boolean; + readonly multiCursorMergeOverlapping: boolean; + readonly wordSeparators: boolean; + readonly autoClosingBrackets: boolean; + readonly autoClosingQuotes: boolean; + readonly autoClosingOvertype: boolean; + readonly autoSurround: boolean; + readonly autoIndent: boolean; + readonly useTabStops: boolean; + readonly tabFocusMode: boolean; + readonly dragAndDrop: boolean; + readonly emptySelectionClipboard: boolean; + readonly copyWithSyntaxHighlighting: boolean; + readonly fontInfo: boolean; + readonly viewInfo: boolean; + readonly contribInfo: boolean; + } + + 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; + } + + export interface IRawEditorOptionsBag extends IEditorOptions { + [key: string]: any; + } + + export interface IComputedEditorOptions { + get>(id: EditorOptionId): ComputedEditorOptionValue; + } + + export type PossibleKeyName = { + [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never; + }[keyof IEditorOptions]; + + export interface IEditorOption { + readonly id: EditorOptionId; + readonly name: PossibleKeyName; + readonly defaultValue: T2; + read(options: IRawEditorOptionsBag): T1 | undefined; + mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; + validate(input: T1 | undefined): T2; + compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; + equals(a: T3, b: T3): boolean; + } + + export abstract class BaseEditorOption implements IEditorOption { + readonly id: EditorOptionId; + readonly name: PossibleKeyName; + readonly defaultValue: T2; + constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T2, deps?: EditorOptionId[]); + read(options: IRawEditorOptionsBag): T1 | undefined; + mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; + abstract validate(input: T1 | undefined): T2; + abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; + equals(a: T3, b: T3): boolean; + } + + export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); + + export enum RenderLineNumbersType { + Off = 0, + On = 1, + Relative = 2, + Interval = 3, + Custom = 4 + } + + export interface InternalEditorRenderLineNumbersOptions { + readonly renderType: RenderLineNumbersType; + readonly renderFn: ((lineNumber: number) => string) | null; + } + + export interface InternalEditorMinimapOptions { + readonly enabled: boolean; + readonly side: 'right' | 'left'; + readonly showSlider: 'always' | 'mouseover'; + readonly renderCharacters: boolean; + readonly maxColumn: number; + } + + 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 description for the overview ruler position. */ @@ -3518,62 +3590,65 @@ declare namespace monaco.editor { readonly overviewRuler: OverviewRulerPosition; } - /** - * An event describing that the configuration of the editor has changed. - */ - export interface IConfigurationChangedEvent { - hasChanged(id: EditorOptionId): boolean; - readonly canUseLayerHinting: boolean; - readonly pixelRatio: boolean; - readonly editorClassName: boolean; - readonly lineHeight: boolean; - readonly readOnly: boolean; - readonly accessibilitySupport: boolean; - readonly multiCursorModifier: boolean; - readonly multiCursorMergeOverlapping: boolean; - readonly wordSeparators: boolean; - readonly autoClosingBrackets: boolean; - readonly autoClosingQuotes: boolean; - readonly autoClosingOvertype: boolean; - readonly autoSurround: boolean; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly tabFocusMode: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; - readonly layoutInfo: boolean; - readonly fontInfo: boolean; - readonly viewInfo: boolean; - readonly wrappingInfo: boolean; - readonly contribInfo: boolean; - } - - export interface IRawEditorOptionsBag { - [key: string]: any; - } - - export interface IEditorOption { - readonly id: EditorOptionId; - readonly name: string; - readonly defaultValue: T1; - read(options: IRawEditorOptionsBag): T1 | undefined; - mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; - validate(input: T1 | undefined): T2; - compute(value: T2): T3; - equals(a: T3, b: T3): boolean; + export interface EditorWrappingInfo { + readonly isDominatedByLongLines: boolean; + readonly isWordWrapMinified: boolean; + readonly isViewportWrapping: boolean; + readonly wrappingColumn: number; } export enum EditorOptionId { - renderFinalNewline = 0, - selectionClipboard = 1, - selectOnLineNumbers = 2 + accessibilitySupport = 0, + ariaLabel = 1, + fastScrollSensitivity = 2, + folding = 3, + glyphMargin = 4, + inDiffEditor = 5, + lineDecorationsWidth = 6, + lineNumbersMinChars = 7, + minimap = 8, + mouseWheelScrollSensitivity = 9, + renderFinalNewline = 10, + renderLineNumbers = 11, + scrollbar = 12, + selectionClipboard = 13, + selectOnLineNumbers = 14, + wordWrap = 15, + wordWrapBreakAfterCharacters = 16, + wordWrapBreakBeforeCharacters = 17, + wordWrapBreakObtrusiveCharacters = 18, + wordWrapColumn = 19, + wordWrapMinified = 20, + wrappingIndent = 21, + layoutInfo = 22, + wrappingInfo = 23 } export const EditorOption: { + accessibilitySupport: IEditorOption<"auto" | "on" | "off", "auto" | "on" | "off", any>; + ariaLabel: IEditorOption; + fastScrollSensitivity: IEditorOption; + folding: IEditorOption; + glyphMargin: IEditorOption; + inDiffEditor: IEditorOption; + lineDecorationsWidth: IEditorOption; + lineNumbersMinChars: IEditorOption; + minimap: IEditorOption; + mouseWheelScrollSensitivity: IEditorOption; renderFinalNewline: IEditorOption; + renderLineNumbers: IEditorOption; + scrollbar: IEditorOption; selectionClipboard: IEditorOption; selectOnLineNumbers: IEditorOption; + wordWrap: IEditorOption<"on" | "off" | "wordWrapColumn" | "bounded", "on" | "off" | "wordWrapColumn" | "bounded", "on" | "off" | "wordWrapColumn" | "bounded">; + wordWrapBreakAfterCharacters: IEditorOption; + wordWrapBreakBeforeCharacters: IEditorOption; + wordWrapBreakObtrusiveCharacters: IEditorOption; + wordWrapColumn: IEditorOption; + wordWrapMinified: IEditorOption; + wrappingIndent: IEditorOption<"none" | "same" | "indent" | "deepIndent", "none" | "same" | "indent" | "deepIndent", WrappingIndent>; + layoutInfo: IEditorOption; + wrappingInfo: IEditorOption; }; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; @@ -4027,6 +4102,7 @@ declare namespace monaco.editor { * Returns the current editor's configuration */ getConfiguration(): InternalEditorOptions; + getOptions(): IComputedEditorOptions; getOption>(id: EditorOptionId): ComputedEditorOptionValue; /** * Get value of the current model attached to this editor. diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index ff8e1cd5138..10437ec2ed6 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -6,7 +6,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -59,8 +59,10 @@ export class MainThreadTextEditorProperties { let lineNumbers: RenderLineNumbersType; if (codeEditor) { const codeEditorOpts = codeEditor.getConfiguration(); + const options = codeEditor.getOptions(); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); cursorStyle = codeEditorOpts.viewInfo.cursorStyle; - lineNumbers = codeEditorOpts.viewInfo.renderLineNumbers; + lineNumbers = renderLineNumbers.renderType; } else if (previousProperties) { cursorStyle = previousProperties.options.cursorStyle; lineNumbers = previousProperties.options.lineNumbers; diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index ed5bbacdd3e..f96fcd3b787 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -35,7 +35,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ITextFileService, SUPPORTED_ENCODINGS } from 'vs/workbench/services/textfile/common/textfiles'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; -import { IConfigurationChangedEvent, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, IEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { deepClone } from 'vs/base/common/objects'; @@ -584,7 +584,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { // Hook Listener for Configuration changes this.activeEditorListeners.add(activeCodeEditor.onDidChangeConfiguration((event: IConfigurationChangedEvent) => { - if (event.accessibilitySupport) { + if (event.hasChanged(EditorOptionId.accessibilitySupport)) { this.onScreenReaderModeChange(activeCodeEditor); } })); diff --git a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts index eb15bf10a1f..e8472a05fe6 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts @@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { EDITOR_DEFAULTS, InternalEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { ITextModel } from 'vs/editor/common/model'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; @@ -68,7 +68,7 @@ function readWordWrapState(model: ITextModel, configurationService: ITextResourc const _transientState = readTransientState(model, codeEditorService); return { configuredWordWrap: _configuredWordWrap, - configuredWordWrapMinified: (typeof _configuredWordWrapMinified === 'boolean' ? _configuredWordWrapMinified : EDITOR_DEFAULTS.wordWrapMinified), + configuredWordWrapMinified: (typeof _configuredWordWrapMinified === 'boolean' ? _configuredWordWrapMinified : EditorOption.wordWrapMinified.defaultValue), transientState: _transientState }; } @@ -83,10 +83,9 @@ function toggleWordWrap(editor: ICodeEditor, state: IWordWrapState): IWordWrapSt }; } - const config = editor.getConfiguration(); let transientState: IWordWrapTransientState; - const actualWrappingInfo = config.wrappingInfo; + const actualWrappingInfo = editor.getOption(EditorOptionId.wrappingInfo); if (actualWrappingInfo.isWordWrapMinified) { // => wrapping due to minified file transientState = { @@ -139,8 +138,7 @@ class ToggleWordWrapAction extends EditorAction { if (!editor.hasModel()) { return; } - const editorConfiguration = editor.getConfiguration(); - if (editorConfiguration.wrappingInfo.inDiffEditor) { + if (editor.getOption(EditorOptionId.inDiffEditor)) { // Cannot change wrapping settings inside the diff editor const notificationService = accessor.get(INotificationService); notificationService.info(nls.localize('wordWrap.notInDiffEditor', "Cannot toggle word wrap in a diff editor.")); @@ -177,20 +175,22 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution ) { super(); - const configuration = this.editor.getConfiguration(); - const isWordWrapMinified = this.contextKeyService.createKey(isWordWrapMinifiedKey, this._isWordWrapMinified(configuration)); - const isDominatedByLongLines = this.contextKeyService.createKey(isDominatedByLongLinesKey, this._isDominatedByLongLines(configuration)); - const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, this._inDiffEditor(configuration)); + const options = this.editor.getOptions(); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const isWordWrapMinified = this.contextKeyService.createKey(isWordWrapMinifiedKey, wrappingInfo.isWordWrapMinified); + const isDominatedByLongLines = this.contextKeyService.createKey(isDominatedByLongLinesKey, wrappingInfo.isDominatedByLongLines); + const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, options.get(EditorOptionId.inDiffEditor)); let currentlyApplyingEditorConfig = false; this._register(editor.onDidChangeConfiguration((e) => { - if (!e.wrappingInfo) { + if (!e.hasChanged(EditorOptionId.wrappingInfo) || !e.hasChanged(EditorOptionId.inDiffEditor)) { return; } - const configuration = this.editor.getConfiguration(); - isWordWrapMinified.set(this._isWordWrapMinified(configuration)); - isDominatedByLongLines.set(this._isDominatedByLongLines(configuration)); - inDiffEditor.set(this._inDiffEditor(configuration)); + const options = this.editor.getOptions(); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + isWordWrapMinified.set(wrappingInfo.isWordWrapMinified); + isDominatedByLongLines.set(wrappingInfo.isDominatedByLongLines); + inDiffEditor.set(options.get(EditorOptionId.inDiffEditor)); if (!currentlyApplyingEditorConfig) { // I am not the cause of the word wrap getting changed ensureWordWrapSettings(); @@ -216,8 +216,7 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution return; } - const configuration = this.editor.getConfiguration(); - if (this._inDiffEditor(configuration)) { + if (this.editor.getOption(EditorOptionId.inDiffEditor)) { return; } @@ -255,18 +254,6 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution }); } - private _isWordWrapMinified(config: InternalEditorOptions): boolean { - return config.wrappingInfo.isWordWrapMinified; - } - - private _isDominatedByLongLines(config: InternalEditorOptions): boolean { - return config.wrappingInfo.isDominatedByLongLines; - } - - private _inDiffEditor(config: InternalEditorOptions): boolean { - return config.wrappingInfo.inDiffEditor; - } - public getId(): string { return ToggleWordWrapController._ID; } diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index d5cfcfb4f19..94a1a359481 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -37,6 +37,7 @@ import { COMMENTEDITOR_DECORATION_KEY, ReviewZoneWidget } from 'vs/workbench/con import { ctxCommentEditorFocused, SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; export const ID = 'editor.contrib.review'; @@ -590,7 +591,7 @@ export class ReviewController implements IEditorContribution { } this._commentInfos = commentInfos; - let lineDecorationsWidth: number = this.editor.getConfiguration().layoutInfo.decorationsWidth; + let lineDecorationsWidth: number = this.editor.getLayoutInfo().decorationsWidth; if (this._commentInfos.some(info => Boolean(info.commentingRanges && (Array.isArray(info.commentingRanges) ? info.commentingRanges : info.commentingRanges.ranges).length))) { if (!this._commentingRangeSpaceReserved) { @@ -601,7 +602,8 @@ export class ReviewController implements IEditorContribution { extraEditorClassName = configuredExtraClassName.split(' '); } - if (this.editor.getConfiguration().contribInfo.folding) { + const options = this.editor.getOptions(); + if (options.get(EditorOptionId.folding)) { lineDecorationsWidth -= 16; } lineDecorationsWidth += 9; diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts index 66678cbfffb..6b738378609 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts @@ -33,6 +33,7 @@ import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/p import { PANEL_ACTIVE_TITLE_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND } from 'vs/workbench/common/theme'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { ISettingsGroup } from 'vs/workbench/services/preferences/common/preferences'; +import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class SettingsHeaderWidget extends Widget implements IViewZone { @@ -85,8 +86,9 @@ export class SettingsHeaderWidget extends Widget implements IViewZone { private layout(): void { const configuration = this.editor.getConfiguration(); + const options = this.editor.getOptions(); this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; - if (!configuration.contribInfo.folding) { + if (!options.get(EditorOptionId.folding)) { this.titleContainer.style.paddingLeft = '6px'; } } diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts index 3dcbb07c16c..eaafa00f21b 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts @@ -16,7 +16,7 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IRange } from 'vs/editor/common/core/range'; import { overviewRulerRangeHighlight } from 'vs/editor/common/view/editorColorRegistry'; import { themeColorFromId } from 'vs/platform/theme/common/themeService'; -import { IEditorOptions, RenderLineNumbersType } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RenderLineNumbersType, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -50,8 +50,9 @@ export class GotoLineAction extends QuickOpenAction { let restoreOptions: IEditorOptions | null = null; if (isCodeEditor(activeTextEditorWidget)) { - const config = activeTextEditorWidget.getConfiguration(); - if (config.viewInfo.renderLineNumbers === RenderLineNumbersType.Relative) { + const options = activeTextEditorWidget.getOptions(); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + if (renderLineNumbers.renderType === RenderLineNumbersType.Relative) { activeTextEditorWidget.updateOptions({ lineNumbers: 'on' }); From 9ab08c2d308c30ce3774afa110dd1082959ac4ad Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 3 Sep 2019 00:19:00 +0200 Subject: [PATCH 006/109] Adopt conditional types for editor options reading --- .../editor/browser/controller/mouseHandler.ts | 10 +- .../editor/browser/controller/mouseTarget.ts | 6 +- .../browser/controller/textAreaHandler.ts | 16 +- src/vs/editor/browser/editorBrowser.ts | 19 ++- src/vs/editor/browser/view/viewImpl.ts | 5 +- src/vs/editor/browser/view/viewOverlays.ts | 11 +- .../contentWidgets/contentWidgets.ts | 7 +- .../currentLineHighlight.ts | 7 +- .../currentLineMarginHighlight.ts | 7 +- .../editorScrollbar/editorScrollbar.ts | 18 +-- .../viewParts/glyphMargin/glyphMargin.ts | 7 +- .../viewParts/indentGuides/indentGuides.ts | 7 +- .../viewParts/lineNumbers/lineNumbers.ts | 8 +- .../browser/viewParts/lines/viewLines.ts | 6 +- .../linesDecorations/linesDecorations.ts | 7 +- .../editor/browser/viewParts/margin/margin.ts | 7 +- .../browser/viewParts/minimap/minimap.ts | 6 +- .../overlayWidgets/overlayWidgets.ts | 7 +- .../overviewRuler/decorationsOverviewRuler.ts | 6 +- .../scrollDecoration/scrollDecoration.ts | 9 +- .../viewParts/viewCursors/viewCursors.ts | 10 +- .../browser/viewParts/viewZones/viewZones.ts | 7 +- .../editor/browser/widget/codeEditorWidget.ts | 48 +++--- .../editor/browser/widget/diffEditorWidget.ts | 32 ++-- src/vs/editor/browser/widget/diffReview.ts | 4 +- .../editor/browser/widget/inlineDiffMargin.ts | 3 +- .../common/config/commonEditorConfig.ts | 99 ++++++------ src/vs/editor/common/config/editorOptions.ts | 142 ++++++++++-------- src/vs/editor/common/controller/cursor.ts | 3 +- .../editor/common/controller/cursorCommon.ts | 8 +- .../common/standalone/standaloneEnums.ts | 30 ++-- src/vs/editor/common/view/viewEvents.ts | 2 - src/vs/editor/common/viewLayout/viewLayout.ts | 10 +- .../common/viewModel/viewModelDecorations.ts | 3 +- .../editor/common/viewModel/viewModelImpl.ts | 20 +-- .../contrib/codeAction/codeActionModel.ts | 3 +- src/vs/editor/contrib/find/findController.ts | 3 +- src/vs/editor/contrib/find/findWidget.ts | 10 +- src/vs/editor/contrib/folding/folding.ts | 6 +- src/vs/editor/contrib/hover/hover.ts | 4 +- src/vs/editor/contrib/suggest/suggestModel.ts | 3 +- .../accessibilityHelp/accessibilityHelp.ts | 13 +- .../iPadShowKeyboard/iPadShowKeyboard.ts | 3 +- .../common/config/commonEditorConfig.test.ts | 4 +- .../viewModel/splitLinesCollection.test.ts | 23 +-- src/vs/monaco.d.ts | 110 +++++++------- .../workbench/api/browser/mainThreadEditor.ts | 4 +- .../browser/parts/editor/editorStatus.ts | 7 +- .../browser/accessibility/accessibility.ts | 10 +- .../codeEditor/browser/selectionClipboard.ts | 6 +- .../codeEditor/browser/toggleWordWrap.ts | 16 +- .../browser/commentsEditorContribution.ts | 4 +- .../debug/browser/debugEditorContribution.ts | 4 +- .../browser/keybindingsEditorContribution.ts | 5 +- .../preferences/browser/preferencesWidgets.ts | 4 +- .../quickopen/browser/gotoLineHandler.ts | 4 +- .../bulkEdit/browser/bulkEditService.ts | 3 +- 57 files changed, 442 insertions(+), 404 deletions(-) diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index ce65849c418..a28b811da24 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -21,7 +21,8 @@ import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + /** * Merges mouse events when mouse move events are throttled @@ -217,7 +218,7 @@ export class MouseHandler extends ViewEventHandler { const targetIsContent = (t.type === editorBrowser.MouseTargetType.CONTENT_TEXT || t.type === editorBrowser.MouseTargetType.CONTENT_EMPTY); const targetIsGutter = (t.type === editorBrowser.MouseTargetType.GUTTER_GLYPH_MARGIN || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_DECORATIONS); const targetIsLineNumbers = (t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS); - const selectOnLineNumbers = this._context.configuration.options.get(EditorOptionId.selectOnLineNumbers); + const selectOnLineNumbers = this._context.configuration.options.get(EditorOptionId.selectOnLineNumbers); const targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE); const targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET); @@ -352,7 +353,10 @@ class MouseDownOperation extends Disposable { // Overwrite the detail of the MouseEvent, as it will be sent out in an event and contributions might rely on it. e.detail = this._mouseState.count; - if (!this._context.configuration.editor.readOnly + const options = this._context.configuration.options; + const readOnly = options.get(EditorOptionId.readOnly); + + if (!readOnly && this._context.configuration.editor.dragAndDrop && !this._mouseState.altKey // we don't support multiple mouse && e.detail < 2 // only single click on a selection can work diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index 58948e740aa..cde6cad5f2d 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -10,7 +10,7 @@ import { ClientCoordinates, EditorMouseEvent, EditorPagePosition, PageCoordinate import { PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart'; import { ViewLine } from 'vs/editor/browser/viewParts/lines/viewLine'; import { IViewCursorRenderData } from 'vs/editor/browser/viewParts/viewCursors/viewCursor'; -import { EditorLayoutInfo, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorLayoutInfo, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range as EditorRange } from 'vs/editor/common/core/range'; import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; @@ -240,7 +240,7 @@ export class HitTestContext { constructor(context: ViewContext, viewHelper: IPointerHandlerHelper, lastViewCursorsRenderData: IViewCursorRenderData[]) { this.model = context.model; const options = context.configuration.options; - this.layoutInfo = options.get(EditorOptionId.layoutInfo); + this.layoutInfo = options.get(EditorOptionId.layoutInfo); this.viewDomNode = viewHelper.viewDomNode; this.lineHeight = context.configuration.editor.lineHeight; this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; @@ -715,7 +715,7 @@ export class MouseTargetFactory { public getMouseColumn(editorPos: EditorPagePosition, pos: PageCoordinates): number { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + pos.x - editorPos.x - layoutInfo.contentLeft; return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index bfefbfff922..c02aaef8ecd 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -16,7 +16,7 @@ import { ViewController } from 'vs/editor/browser/view/viewController'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers'; import { Margin } from 'vs/editor/browser/viewParts/margin/margin'; -import { RenderLineNumbersType, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { WordCharacterClass, getMapForWordSeparators } from 'vs/editor/common/controller/wordCharacterClassifier'; import { Position } from 'vs/editor/common/core/position'; @@ -120,9 +120,9 @@ export class TextAreaHandler extends ViewPart { const conf = this._context.configuration.editor; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); - this._accessibilitySupport = conf.accessibilitySupport; + this._accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; @@ -145,7 +145,7 @@ export class TextAreaHandler extends ViewPart { this.textArea.setAttribute('autocapitalize', 'off'); this.textArea.setAttribute('autocomplete', 'off'); this.textArea.setAttribute('spellcheck', 'false'); - this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); + this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); this.textArea.setAttribute('role', 'textbox'); this.textArea.setAttribute('aria-multiline', 'true'); this.textArea.setAttribute('aria-haspopup', 'false'); @@ -379,10 +379,10 @@ export class TextAreaHandler extends ViewPart { this._fontInfo = conf.fontInfo; } if (e.viewInfo) { - this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); + this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); } if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; @@ -391,7 +391,7 @@ export class TextAreaHandler extends ViewPart { this._lineHeight = conf.lineHeight; } if (e.hasChanged(EditorOptionId.accessibilitySupport)) { - this._accessibilitySupport = conf.accessibilitySupport; + this._accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); this._textAreaInput.writeScreenReaderContent('strategy changed'); } if (e.emptySelectionClipboard) { @@ -553,7 +553,7 @@ export class TextAreaHandler extends ViewPart { if (this._context.configuration.editor.viewInfo.glyphMargin) { tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME); } else { - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); if (renderLineNumbers.renderType !== RenderLineNumbersType.Off) { tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME); } else { diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index de7dcc54683..5e94f07990b 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -6,7 +6,7 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IMouseEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; import { IDisposable } from 'vs/base/common/lifecycle'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { OverviewRulerPosition, IConfigurationChangedEvent, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOptionId, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { IPosition, Position } from 'vs/editor/common/core/position'; @@ -315,7 +315,7 @@ export interface IOverviewRuler { getDomNode(): HTMLElement; dispose(): void; setZones(zones: OverviewRulerZone[]): void; - setLayout(position: editorOptions.OverviewRulerPosition): void; + setLayout(position: OverviewRulerPosition): void; } /** @@ -351,7 +351,7 @@ export interface ICodeEditor extends editorCommon.IEditor { * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) * @event */ - onDidChangeConfiguration(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable; + onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; /** * An event emitted when the cursor position has changed. * @event @@ -481,7 +481,7 @@ export interface ICodeEditor extends editorCommon.IEditor { * An event emitted when the layout of the editor has changed. * @event */ - onDidLayoutChange(listener: (e: editorOptions.EditorLayoutInfo) => void): IDisposable; + onDidLayoutChange(listener: (e: EditorLayoutInfo) => void): IDisposable; /** * An event emitted when the scroll in the editor has changed. * @event @@ -534,17 +534,16 @@ export interface ICodeEditor extends editorCommon.IEditor { /** * Returns the current editor's configuration */ - getConfiguration(): editorOptions.InternalEditorOptions; + getConfiguration(): InternalEditorOptions; - getOptions(): editorOptions.IComputedEditorOptions; - - getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue; + getOptions(): IComputedEditorOptions; + getOption(id: T): FindComputedEditorOptionValueById; /** * Returns the 'raw' editor's configuration (without any validation or defaults). * @internal */ - getRawConfiguration(): editorOptions.IEditorOptions; + getRawConfiguration(): IEditorOptions; /** * Get value of the current model attached to this editor. @@ -659,7 +658,7 @@ export interface ICodeEditor extends editorCommon.IEditor { /** * Get the layout info for the editor. */ - getLayoutInfo(): editorOptions.EditorLayoutInfo; + getLayoutInfo(): EditorLayoutInfo; /** * Returns the ranges that are currently visible. diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 67fca037793..41a04db7b4a 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -48,7 +48,8 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData' import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IThemeService, getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export interface IContentWidgetData { widget: editorBrowser.IContentWidget; @@ -283,7 +284,7 @@ export class View extends ViewEventHandler { private _setLayout(): void { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.domNode.setWidth(layoutInfo.width); this.domNode.setHeight(layoutInfo.height); diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index 5182408db5a..5e0015eb0a9 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -14,7 +14,8 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class ViewOverlays extends ViewPart implements IVisibleLinesHost { @@ -217,7 +218,7 @@ export class ContentViewOverlays extends ViewOverlays { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentWidth = layoutInfo.contentWidth; this.domNode.setHeight(0); @@ -228,7 +229,7 @@ export class ContentViewOverlays extends ViewOverlays { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentWidth = layoutInfo.contentWidth; } return super.onConfigurationChanged(e); @@ -254,7 +255,7 @@ export class MarginViewOverlays extends ViewOverlays { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this.domNode.setClassName('margin-view-overlays'); @@ -271,7 +272,7 @@ export class MarginViewOverlays extends ViewOverlays { } if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; shouldRender = true; } diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index 9c7998b7427..6975b25a6bc 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -14,7 +14,8 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + class Coordinate { _coordinateBrand: void; @@ -209,7 +210,7 @@ class Widget { this.suppressMouseDown = this._actual.suppressMouseDown || false; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._fixedOverflowWidgets = this._context.configuration.editor.viewInfo.fixedOverflowWidgets; this._contentWidth = layoutInfo.contentWidth; @@ -239,7 +240,7 @@ class Widget { } if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._maxWidth = this._getMaxWidth(); diff --git a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts index 65343ec07eb..63aa1334022 100644 --- a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts @@ -10,7 +10,8 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class CurrentLineHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; @@ -25,7 +26,7 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; @@ -55,7 +56,7 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { } if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentWidth = layoutInfo.contentWidth; } return true; diff --git a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts index 1389ed0e1b0..3601770f5b8 100644 --- a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts @@ -10,7 +10,8 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; @@ -24,7 +25,7 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; @@ -51,7 +52,7 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { } if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; } return true; diff --git a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts index 24185fbc1c5..df5316bfb80 100644 --- a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts +++ b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts @@ -14,7 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class EditorScrollbar extends ViewPart { @@ -31,9 +31,9 @@ export class EditorScrollbar extends ViewPart { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); - const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); - const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); + const scrollbar = options.get(EditorOptionId.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); const scrollbarOptions: ScrollableElementCreationOptions = { listenOnDomNode: viewDomNode.domNode, @@ -101,11 +101,11 @@ export class EditorScrollbar extends ViewPart { private _setLayout(): void { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.scrollbarDomNode.setLeft(layoutInfo.contentLeft); - const minimap = options.get(EditorOptionId.minimap); + const minimap = options.get(EditorOptionId.minimap); const side = minimap.side; if (side === 'right') { this.scrollbarDomNode.setWidth(layoutInfo.contentWidth + layoutInfo.minimapWidth); @@ -136,9 +136,9 @@ export class EditorScrollbar extends ViewPart { || e.hasChanged(EditorOptionId.fastScrollSensitivity) ) { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); - const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); - const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); + const scrollbar = options.get(EditorOptionId.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); const newOpts: ScrollableElementChangeOptions = { handleMouseWheel: scrollbar.handleMouseWheel, mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, diff --git a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts index c063c668071..516cdb1f468 100644 --- a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts +++ b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts @@ -8,7 +8,8 @@ import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class DecorationToRender { _decorationToRenderBrand: void; @@ -86,7 +87,7 @@ export class GlyphMarginOverlay extends DedupOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; this._glyphMarginLeft = layoutInfo.glyphMarginLeft; @@ -113,7 +114,7 @@ export class GlyphMarginOverlay extends DedupOverlay { this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; } if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; } diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index a8ba2a3936a..9da6446edf9 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -11,7 +11,8 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class IndentGuidesOverlay extends DynamicViewOverlay { @@ -33,7 +34,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); @@ -63,7 +64,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; } if (e.hasChanged(EditorOptionId.wrappingInfo) || e.fontInfo) { - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index d07bbdc92ae..aa078b1b834 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -6,7 +6,7 @@ import 'vs/css!./lineNumbers'; import * as platform from 'vs/base/common/platform'; import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; -import { RenderLineNumbersType, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { editorActiveLineNumber, editorLineNumbers } from 'vs/editor/common/view/editorColorRegistry'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -44,11 +44,11 @@ export class LineNumbersOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const config = this._context.configuration.editor; this._lineHeight = config.lineHeight; - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); this._renderLineNumbers = renderLineNumbers.renderType; this._renderCustomLineNumbers = renderLineNumbers.renderFn; - this._renderFinalNewline = options.get(EditorOptionId.renderFinalNewline); - const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._renderFinalNewline = options.get(EditorOptionId.renderFinalNewline); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineNumbersLeft = layoutInfo.lineNumbersLeft; this._lineNumbersWidth = layoutInfo.lineNumbersWidth; } diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 2e64c0c8056..80c851b0084 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -18,7 +18,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { Viewport } from 'vs/editor/common/viewModel/viewModel'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; class LastRenderedData { @@ -92,7 +92,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const conf = this._context.configuration; const options = this._context.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); this._lineHeight = conf.editor.lineHeight; this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; @@ -152,7 +152,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; } if (e.hasChanged(EditorOptionId.wrappingInfo)) { - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); this._isViewportWrapping = wrappingInfo.isViewportWrapping; } if (e.viewInfo) { diff --git a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts index 1d709f5b917..4beec4716a1 100644 --- a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts +++ b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts @@ -8,7 +8,8 @@ import { DecorationToRender, DedupOverlay } from 'vs/editor/browser/viewParts/gl import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class LinesDecorationsOverlay extends DedupOverlay { @@ -22,7 +23,7 @@ export class LinesDecorationsOverlay extends DedupOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._decorationsLeft = layoutInfo.decorationsLeft; this._decorationsWidth = layoutInfo.decorationsWidth; this._renderResult = null; @@ -40,7 +41,7 @@ export class LinesDecorationsOverlay extends DedupOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._decorationsLeft = layoutInfo.decorationsLeft; this._decorationsWidth = layoutInfo.decorationsWidth; } diff --git a/src/vs/editor/browser/viewParts/margin/margin.ts b/src/vs/editor/browser/viewParts/margin/margin.ts index f49a24845e7..79cc1b4f500 100644 --- a/src/vs/editor/browser/viewParts/margin/margin.ts +++ b/src/vs/editor/browser/viewParts/margin/margin.ts @@ -8,7 +8,8 @@ import { ViewPart } from 'vs/editor/browser/view/viewPart'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class Margin extends ViewPart { @@ -25,7 +26,7 @@ export class Margin extends ViewPart { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; this._contentLeft = layoutInfo.contentLeft; @@ -62,7 +63,7 @@ export class Margin extends ViewPart { } if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index 747ef261830..ce8218c915f 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -13,7 +13,7 @@ import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ILine, RenderedLinesCollection } from 'vs/editor/browser/view/viewLayer'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; -import { RenderMinimap, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderMinimap, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { RGBA8 } from 'vs/editor/common/core/rgba'; import { IConfiguration, ScrollType } from 'vs/editor/common/editorCommon'; @@ -109,13 +109,13 @@ class MinimapOptions { constructor(configuration: IConfiguration) { const options = configuration.options; const pixelRatio = configuration.editor.pixelRatio; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); const viewInfo = configuration.editor.viewInfo; const fontInfo = configuration.editor.fontInfo; this.renderMinimap = layoutInfo.renderMinimap | 0; this.scrollBeyondLastLine = viewInfo.scrollBeyondLastLine; - const minimapOpts = options.get(EditorOptionId.minimap); + const minimapOpts = options.get(EditorOptionId.minimap); this.showSlider = minimapOpts.showSlider; this.pixelRatio = pixelRatio; this.typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; diff --git a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts index 0fa9087323d..2d138034568 100644 --- a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts +++ b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts @@ -10,7 +10,8 @@ import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/v import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + interface IWidgetData { widget: IOverlayWidget; @@ -37,7 +38,7 @@ export class ViewOverlayWidgets extends ViewPart { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._widgets = {}; this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; @@ -66,7 +67,7 @@ export class ViewOverlayWidgets extends ViewPart { const options = this._context.configuration.options; if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; this._minimapWidth = layoutInfo.minimapWidth; this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; diff --git a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts index b620c0ed4ea..463a4592c27 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts @@ -15,7 +15,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ITheme } from 'vs/platform/theme/common/themeService'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; class Settings { @@ -58,7 +58,7 @@ class Settings { this.themeType = theme.type; - const minimapOpts = options.get(EditorOptionId.minimap); + const minimapOpts = options.get(EditorOptionId.minimap); const minimapEnabled = minimapOpts.enabled; const minimapSide = minimapOpts.side; const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : null); @@ -68,7 +68,7 @@ class Settings { this.backgroundColor = Color.Format.CSS.formatHex(backgroundColor); } - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); const position = layoutInfo.overviewRuler; this.top = position.top; this.right = position.right; diff --git a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts index d3b4ae392cd..8a482e56031 100644 --- a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts +++ b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts @@ -11,7 +11,8 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { scrollbarShadow } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export class ScrollDecorationViewPart extends ViewPart { @@ -29,7 +30,7 @@ export class ScrollDecorationViewPart extends ViewPart { this._updateWidth(); this._shouldShow = false; const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOptionId.scrollbar); this._useShadows = scrollbar.useShadows; this._domNode = createFastDomNode(document.createElement('div')); this._domNode.setAttribute('role', 'presentation'); @@ -55,7 +56,7 @@ export class ScrollDecorationViewPart extends ViewPart { private _updateWidth(): boolean { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); let newWidth = 0; if (layoutInfo.renderMinimap === 0 || (layoutInfo.minimapWidth > 0 && layoutInfo.minimapLeft === 0)) { newWidth = layoutInfo.width; @@ -75,7 +76,7 @@ export class ScrollDecorationViewPart extends ViewPart { let shouldRender = false; if (e.hasChanged(EditorOptionId.scrollbar)) { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOptionId.scrollbar); this._useShadows = scrollbar.useShadows; } if (e.hasChanged(EditorOptionId.layoutInfo)) { diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts index 023e031dd02..ede284d3543 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts @@ -8,7 +8,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import { IntervalTimer, TimeoutTimer } from 'vs/base/common/async'; import { ViewPart } from 'vs/editor/browser/view/viewPart'; import { IViewCursorRenderData, ViewCursor } from 'vs/editor/browser/viewParts/viewCursors/viewCursor'; -import { TextEditorCursorBlinkingStyle, TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions'; +import { TextEditorCursorBlinkingStyle, TextEditorCursorStyle, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { editorCursorBackground, editorCursorForeground } from 'vs/editor/common/view/editorColorRegistry'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -43,7 +43,8 @@ export class ViewCursors extends ViewPart { constructor(context: ViewContext) { super(context); - this._readOnly = this._context.configuration.editor.readOnly; + const options = this._context.configuration.options; + this._readOnly = options.get(EditorOptionId.readOnly); this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; this._cursorSmoothCaretAnimation = this._context.configuration.editor.viewInfo.cursorSmoothCaretAnimation; @@ -84,9 +85,10 @@ export class ViewCursors extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { + const options = this._context.configuration.options; - if (e.readOnly) { - this._readOnly = this._context.configuration.editor.readOnly; + if (e.hasChanged(EditorOptionId.readOnly)) { + this._readOnly = options.get(EditorOptionId.readOnly); } if (e.viewInfo) { this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; diff --git a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts index 3e0f58f5475..13bf932d19b 100644 --- a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts +++ b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts @@ -12,7 +12,8 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { IViewWhitespaceViewportData } from 'vs/editor/common/viewModel/viewModel'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + export interface IMyViewZone { whitespaceId: string; @@ -42,7 +43,7 @@ export class ViewZones extends ViewPart { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._contentWidth = layoutInfo.contentWidth; @@ -96,7 +97,7 @@ export class ViewZones extends ViewPart { } if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index ca2133d8ab2..d0cdffa1ca2 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -23,7 +23,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService import { ICommandDelegate } from 'vs/editor/browser/view/viewController'; import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl'; import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOptionId, InternalEditorOptions, IComputedEditorOptions, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor'; import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; @@ -125,8 +125,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE private readonly _onDidChangeModelDecorations: Emitter = this._register(new Emitter()); public readonly onDidChangeModelDecorations: Event = this._onDidChangeModelDecorations.event; - private readonly _onDidChangeConfiguration: Emitter = this._register(new Emitter()); - public readonly onDidChangeConfiguration: Event = this._onDidChangeConfiguration.event; + private readonly _onDidChangeConfiguration: Emitter = this._register(new Emitter()); + public readonly onDidChangeConfiguration: Event = this._onDidChangeConfiguration.event; protected readonly _onDidChangeModel: Emitter = this._register(new Emitter()); public readonly onDidChangeModel: Event = this._onDidChangeModel.event; @@ -140,8 +140,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE private readonly _onDidAttemptReadOnlyEdit: Emitter = this._register(new Emitter()); public readonly onDidAttemptReadOnlyEdit: Event = this._onDidAttemptReadOnlyEdit.event; - private readonly _onDidLayoutChange: Emitter = this._register(new Emitter()); - public readonly onDidLayoutChange: Event = this._onDidLayoutChange.event; + private readonly _onDidLayoutChange: Emitter = this._register(new Emitter()); + public readonly onDidLayoutChange: Event = this._onDidLayoutChange.event; private readonly _editorTextFocus: BooleanEventEmitter = this._register(new BooleanEventEmitter()); public readonly onDidFocusEditorText: Event = this._editorTextFocus.onDidChangeToTrue; @@ -236,7 +236,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE constructor( domElement: HTMLElement, - options: editorOptions.IEditorOptions, + options: IEditorOptions, codeEditorWidgetOptions: ICodeEditorWidgetOptions, @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @@ -259,9 +259,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._register(this._configuration.onDidChange((e) => { this._onDidChangeConfiguration.fire(e); - if (e.hasChanged(editorOptions.EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._configuration.options; - const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._onDidLayoutChange.fire(layoutInfo); } if (this._configuration.editor.showUnused) { @@ -329,7 +329,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._codeEditorService.addCodeEditor(this); } - protected _createConfiguration(options: editorOptions.IEditorOptions, accessibilityService: IAccessibilityService): editorCommon.IConfiguration { + protected _createConfiguration(options: IEditorOptions, accessibilityService: IAccessibilityService): editorCommon.IConfiguration { return new Configuration(this.isSimpleWidget, options, this._domElement, accessibilityService); } @@ -364,23 +364,23 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE return this._instantiationService.invokeFunction(fn); } - public updateOptions(newOptions: editorOptions.IEditorOptions): void { + public updateOptions(newOptions: IEditorOptions): void { this._configuration.updateOptions(newOptions); } - public getConfiguration(): editorOptions.InternalEditorOptions { + public getConfiguration(): InternalEditorOptions { return this._configuration.editor; } - public getOptions(): editorOptions.IComputedEditorOptions { + public getOptions(): IComputedEditorOptions { return this._configuration.options; } - public getOption>(id: editorOptions.EditorOptionId): editorOptions.ComputedEditorOptionValue { - return this._configuration.options.get(id); + public getOption(id: T): FindComputedEditorOptionValueById { + return this._configuration.options.get(id); } - public getRawConfiguration(): editorOptions.IEditorOptions { + public getRawConfiguration(): IEditorOptions { return this._configuration.getRawOptions(); } @@ -982,7 +982,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return false; } - if (this._configuration.editor.readOnly) { + if (this._configuration.options.get(EditorOptionId.readOnly)) { // read only editor => sorry! return false; } @@ -994,7 +994,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return false; } - if (this._configuration.editor.readOnly) { + if (this._configuration.options.get(EditorOptionId.readOnly)) { // read only editor => sorry! return false; } @@ -1038,7 +1038,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return null; } - return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.editor.readOnly); + return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.options.get(EditorOptionId.readOnly)); } public deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[] { @@ -1129,9 +1129,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE } } - public getLayoutInfo(): editorOptions.EditorLayoutInfo { + public getLayoutInfo(): EditorLayoutInfo { const options = this._configuration.options; - const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); return layoutInfo; } @@ -1281,7 +1281,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE const position = this._modelData.model.validatePosition(rawPosition); const options = this._configuration.options; - const layoutInfo = options.get(editorOptions.EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); const top = CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, position.lineNumber, position.column) - this.getScrollTop(); const left = this._modelData.view.getOffsetForColumn(position.lineNumber, position.column) + layoutInfo.glyphMarginWidth + layoutInfo.lineNumbersWidth + layoutInfo.decorationsWidth - this.getScrollLeft(); @@ -1614,10 +1614,10 @@ class EditorContextKeysManager extends Disposable { } private _updateFromConfig(): void { - const config = this._editor.getConfiguration(); + const options = this._editor.getOptions(); - this._editorTabMovesFocus.set(config.tabFocusMode); - this._editorReadonly.set(config.readOnly); + this._editorTabMovesFocus.set(options.get(EditorOptionId.tabFocusMode)); + this._editorReadonly.set(options.get(EditorOptionId.readOnly)); } private _updateFromSelection(): void { diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index da9e1ddf553..d2ba7bd565d 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -20,7 +20,7 @@ import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffReview } from 'vs/editor/browser/widget/diffReview'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { IDiffEditorOptions, IEditorOptions, EDITOR_DEFAULTS, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -213,7 +213,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE constructor( domElement: HTMLElement, - options: editorOptions.IDiffEditorOptions, + options: IDiffEditorOptions, @IEditorWorkerService editorWorkerService: IEditorWorkerService, @IContextKeyService contextKeyService: IContextKeyService, @IInstantiationService instantiationService: IInstantiationService, @@ -422,7 +422,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE this._layoutOverviewRulers(); } - private _createLeftHandSideEditor(options: editorOptions.IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget { + private _createLeftHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget { const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable)); this._register(editor.onDidScrollChange((e) => { @@ -455,7 +455,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return editor; } - private _createRightHandSideEditor(options: editorOptions.IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget { + private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget { const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options)); this._register(editor.onDidScrollChange((e) => { @@ -494,7 +494,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return editor; } - protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: editorOptions.IEditorOptions): CodeEditorWidget { + protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditorWidget { return instantiationService.createInstance(CodeEditorWidget, container, options, {}); } @@ -568,7 +568,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return this.modifiedEditor; } - public updateOptions(newOptions: editorOptions.IDiffEditorOptions): void { + public updateOptions(newOptions: IDiffEditorOptions): void { // Handle side by side let renderSideBySideChanged = false; @@ -967,8 +967,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE } } - private _adjustOptionsForSubEditor(options: editorOptions.IDiffEditorOptions): editorOptions.IDiffEditorOptions { - let clonedOptions: editorOptions.IDiffEditorOptions = objects.deepClone(options || {}); + private _adjustOptionsForSubEditor(options: IDiffEditorOptions): IDiffEditorOptions { + let clonedOptions: IDiffEditorOptions = objects.deepClone(options || {}); clonedOptions.inDiffEditor = true; clonedOptions.wordWrap = 'off'; clonedOptions.wordWrapMinified = false; @@ -986,7 +986,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return clonedOptions; } - private _adjustOptionsForLeftHandSide(options: editorOptions.IDiffEditorOptions, isEditable: boolean): editorOptions.IEditorOptions { + private _adjustOptionsForLeftHandSide(options: IDiffEditorOptions, isEditable: boolean): IEditorOptions { let result = this._adjustOptionsForSubEditor(options); result.readOnly = !isEditable; result.overviewRulerLanes = 1; @@ -994,9 +994,9 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE return result; } - private _adjustOptionsForRightHandSide(options: editorOptions.IDiffEditorOptions): editorOptions.IEditorOptions { + private _adjustOptionsForRightHandSide(options: IDiffEditorOptions): IEditorOptions { let result = this._adjustOptionsForSubEditor(options); - result.revealHorizontalRightPadding = editorOptions.EDITOR_DEFAULTS.viewInfo.revealHorizontalRightPadding + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH; + result.revealHorizontalRightPadding = EDITOR_DEFAULTS.viewInfo.revealHorizontalRightPadding + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH; result.scrollbar!.verticalHasArrows = false; result.extraEditorClassName = 'modified-in-monaco-diff-editor'; return result; @@ -1830,7 +1830,7 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito this.decorationsLeft = dataSource.getOriginalEditor().getLayoutInfo().decorationsLeft; - this._register(dataSource.getOriginalEditor().onDidLayoutChange((layoutInfo: editorOptions.EditorLayoutInfo) => { + this._register(dataSource.getOriginalEditor().onDidLayoutChange((layoutInfo: EditorLayoutInfo) => { if (this.decorationsLeft !== layoutInfo.decorationsLeft) { this.decorationsLeft = layoutInfo.decorationsLeft; dataSource.relayoutEditors(); @@ -1946,8 +1946,8 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito class InlineViewZonesComputer extends ViewZonesComputer { private readonly originalModel: ITextModel; - private readonly modifiedEditorConfiguration: editorOptions.InternalEditorOptions; - private readonly modifiedEditorOptions: editorOptions.IComputedEditorOptions; + private readonly modifiedEditorConfiguration: InternalEditorOptions; + private readonly modifiedEditorOptions: IComputedEditorOptions; private readonly modifiedEditorTabSize: number; private readonly renderIndicators: boolean; @@ -1995,7 +1995,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { let sb = createStringBuilder(10000); let marginHTML: string[] = []; - const layoutInfo = this.modifiedEditorOptions.get(editorOptions.EditorOptionId.layoutInfo); + const layoutInfo = this.modifiedEditorOptions.get(EditorOptionId.layoutInfo); const lineDecorationsWidth = layoutInfo.decorationsWidth; let lineHeight = this.modifiedEditorConfiguration.lineHeight; @@ -2042,7 +2042,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { }; } - private _renderOriginalLine(count: number, originalModel: ITextModel, config: editorOptions.InternalEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { + private _renderOriginalLine(count: number, originalModel: ITextModel, config: InternalEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { const lineTokens = originalModel.getLineTokens(lineNumber); const lineContent = lineTokens.getLineContent(); diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index f6ab9ce2f14..8c51ecede42 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -667,10 +667,10 @@ export class DiffReview extends Disposable { originalLineEnd - originalLineStart ); - const originalLayoutInfo = originalOptions.get(editorOptions.EditorOptionId.layoutInfo); + const originalLayoutInfo = originalOptions.get(editorOptions.EditorOptionId.layoutInfo); const originalLineNumbersWidth = originalLayoutInfo.glyphMarginWidth + originalLayoutInfo.lineNumbersWidth; - const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOptionId.layoutInfo); + const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOptionId.layoutInfo); const modifiedLineNumbersWidth = 10 + modifiedLayoutInfo.glyphMarginWidth + modifiedLayoutInfo.lineNumbersWidth; for (let i = 0; i <= cnt; i++) { diff --git a/src/vs/editor/browser/widget/inlineDiffMargin.ts b/src/vs/editor/browser/widget/inlineDiffMargin.ts index 7933869ab4f..afc6287dc02 100644 --- a/src/vs/editor/browser/widget/inlineDiffMargin.ts +++ b/src/vs/editor/browser/widget/inlineDiffMargin.ts @@ -12,6 +12,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { Range } from 'vs/editor/common/core/range'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export interface IDiffLinesChange { readonly originalStartLineNumber: number; @@ -97,7 +98,7 @@ export class InlineDiffMargin extends Disposable { actions.push(copyLineAction); } - const readOnly = editor.getConfiguration().readOnly; + const readOnly = editor.getOption(EditorOptionId.readOnly); if (!readOnly) { actions.push(new Action('diff.inline.revertChange', nls.localize('diff.inline.revertChange.label', "Revert this change"), undefined, true, async () => { if (diff.modifiedEndLineNumber === 0) { diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index a5dc25319e2..921bb9d99b8 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -8,15 +8,12 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOption, EDITOR_MODEL_DEFAULTS, blinkingStyleToString, cursorStyleToString } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { ConfigurationScope, Extensions, IConfigurationNode, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; import { Registry } from 'vs/platform/registry/common/platform'; -import EDITOR_DEFAULTS = editorOptions.EDITOR_DEFAULTS; -import EDITOR_FONT_DEFAULTS = editorOptions.EDITOR_FONT_DEFAULTS; -import EDITOR_MODEL_DEFAULTS = editorOptions.EDITOR_MODEL_DEFAULTS; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; /** @@ -64,47 +61,47 @@ export interface IEnvConfiguration { const hasOwnProperty = Object.hasOwnProperty; export class EditorConfiguration2 { - public static readOptions(options: editorOptions.IEditorOptions): editorOptions.RawEditorOptions { + public static readOptions(options: IEditorOptions): RawEditorOptions { // console.log(`parseOptions`, options); - const result = new editorOptions.RawEditorOptions(); - for (const editorOption of editorOptions.editorOptionsRegistry) { + const result = new RawEditorOptions(); + for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.read(options)); } return result; } - public static mixOptions(a: editorOptions.RawEditorOptions, b: editorOptions.IEditorOptions): editorOptions.RawEditorOptions { + public static mixOptions(a: RawEditorOptions, b: IEditorOptions): RawEditorOptions { // console.log(`mixOptions`, a, b); - const result = new editorOptions.RawEditorOptions(); - for (const editorOption of editorOptions.editorOptionsRegistry) { + const result = new RawEditorOptions(); + for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.mix(a._read(editorOption.id), editorOption.read(b))); } return result; } - public static validateOptions(options: editorOptions.RawEditorOptions): editorOptions.ValidatedEditorOptions { + public static validateOptions(options: RawEditorOptions): ValidatedEditorOptions { // console.log(`validateOptions`, options); - const result = new editorOptions.ValidatedEditorOptions(); - for (const editorOption of editorOptions.editorOptionsRegistry) { + const result = new ValidatedEditorOptions(); + for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.validate(options._read(editorOption.id))); } return result; } - public static computeOptions(options: editorOptions.ValidatedEditorOptions, env: editorOptions.IEnvironmentalOptions): editorOptions.ComputedEditorOptions { + public static computeOptions(options: ValidatedEditorOptions, env: IEnvironmentalOptions): ComputedEditorOptions { // console.log(`computeOptions`, options, env); - const result = new editorOptions.ComputedEditorOptions(); - for (const editorOption of editorOptions.editorOptionsRegistry) { + const result = new ComputedEditorOptions(); + for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.compute(env, result, options._read(editorOption.id))); } return result; } - public static checkEquals(a: editorOptions.ComputedEditorOptions, b: editorOptions.ComputedEditorOptions): editorOptions.ChangedEditorOptions | null { + public static checkEquals(a: ComputedEditorOptions, b: ComputedEditorOptions): ChangedEditorOptions | null { // console.log(`equals`, a, b); - const result = new editorOptions.ChangedEditorOptions(); + const result = new ChangedEditorOptions(); let somethingChanged = false; - for (const editorOption of editorOptions.editorOptionsRegistry) { + for (const editorOption of editorOptionsRegistry) { const changed = !editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); result._write(editorOption.id, changed); if (changed) { @@ -118,7 +115,7 @@ export class EditorConfiguration2 { /** * Compatibility with old options */ -function migrateOptions(options: editorOptions.IEditorOptions): void { +function migrateOptions(options: IEditorOptions): void { let wordWrap = options.wordWrap; if (wordWrap === true) { options.wordWrap = 'on'; @@ -137,20 +134,20 @@ function migrateOptions(options: editorOptions.IEditorOptions): void { export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { public readonly isSimpleWidget: boolean; - protected _rawOptions: editorOptions.IEditorOptions; - protected _validatedOptions: editorOptions.IValidatedEditorOptions; - public editor!: editorOptions.InternalEditorOptions; + protected _rawOptions: IEditorOptions; + protected _validatedOptions: IValidatedEditorOptions; + public editor!: InternalEditorOptions; private _isDominatedByLongLines: boolean; private _lineNumbersDigitCount: number; - private _onDidChange = this._register(new Emitter()); - public readonly onDidChange: Event = this._onDidChange.event; + private _onDidChange = this._register(new Emitter()); + public readonly onDidChange: Event = this._onDidChange.event; - private _rawOptions2: editorOptions.RawEditorOptions; - private _validatedOptions2: editorOptions.ValidatedEditorOptions; - public options!: editorOptions.ComputedEditorOptions; + private _rawOptions2: RawEditorOptions; + private _validatedOptions2: ValidatedEditorOptions; + public options!: ComputedEditorOptions; - constructor(isSimpleWidget: boolean, options: editorOptions.IEditorOptions) { + constructor(isSimpleWidget: boolean, options: IEditorOptions) { super(); migrateOptions(options); @@ -164,7 +161,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._rawOptions.hover = objects.mixin({}, this._rawOptions.hover || {}); this._rawOptions.parameterHints = objects.mixin({}, this._rawOptions.parameterHints || {}); - this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); + this._validatedOptions = EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); this._rawOptions2 = EditorConfiguration2.readOptions(options); this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); @@ -202,15 +199,15 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed } } - public getRawOptions(): editorOptions.IEditorOptions { + public getRawOptions(): IEditorOptions { return this._rawOptions; } - private _computeInternalOptions(): [editorOptions.InternalEditorOptions, editorOptions.ComputedEditorOptions] { + private _computeInternalOptions(): [InternalEditorOptions, ComputedEditorOptions] { const opts = this._validatedOptions; const partialEnv = this._getEnvConfiguration(); const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, partialEnv.zoomLevel, this.isSimpleWidget); - const env: editorOptions.IEnvironmentalOptions = { + const env: IEnvironmentalOptions = { outerWidth: partialEnv.outerWidth, outerHeight: partialEnv.outerHeight, fontInfo: this.readConfiguration(bareFontInfo), @@ -222,7 +219,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; - const r = editorOptions.InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); + const r = InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); const r2 = EditorConfiguration2.computeOptions(this._validatedOptions2, env); return [r, r2]; } @@ -267,7 +264,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return true; } - public updateOptions(newOptions: editorOptions.IEditorOptions): void { + public updateOptions(newOptions: IEditorOptions): void { if (typeof newOptions === 'undefined') { return; } @@ -278,7 +275,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._rawOptions = objects.mixin(this._rawOptions, newOptions || {}); this._rawOptions2 = EditorConfiguration2.mixOptions(this._rawOptions2, newOptions); - this._validatedOptions = editorOptions.EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); + this._validatedOptions = EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); this._recomputeOptions(); @@ -366,7 +363,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.renderFinalNewline': { 'type': 'boolean', - 'default': editorOptions.EditorOption.renderFinalNewline.defaultValue, + 'default': EditorOption.renderFinalNewline.defaultValue, 'description': nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }, 'editor.rulers': { @@ -434,29 +431,29 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.minimap.enabled': { 'type': 'boolean', - 'default': editorOptions.EditorOption.minimap.defaultValue.enabled, + 'default': EditorOption.minimap.defaultValue.enabled, 'description': nls.localize('minimap.enabled', "Controls whether the minimap is shown.") }, 'editor.minimap.side': { 'type': 'string', 'enum': ['left', 'right'], - 'default': editorOptions.EditorOption.minimap.defaultValue.side, + 'default': EditorOption.minimap.defaultValue.side, 'description': nls.localize('minimap.side', "Controls the side where to render the minimap.") }, 'editor.minimap.showSlider': { 'type': 'string', 'enum': ['always', 'mouseover'], - 'default': editorOptions.EditorOption.minimap.defaultValue.showSlider, + 'default': EditorOption.minimap.defaultValue.showSlider, 'description': nls.localize('minimap.showSlider', "Controls whether the minimap slider is automatically hidden.") }, 'editor.minimap.renderCharacters': { 'type': 'boolean', - 'default': editorOptions.EditorOption.minimap.defaultValue.renderCharacters, + 'default': EditorOption.minimap.defaultValue.renderCharacters, 'description': nls.localize('minimap.renderCharacters', "Render the actual characters on a line as opposed to color blocks.") }, 'editor.minimap.maxColumn': { 'type': 'number', - 'default': editorOptions.EditorOption.minimap.defaultValue.maxColumn, + 'default': EditorOption.minimap.defaultValue.maxColumn, 'description': nls.localize('minimap.maxColumn', "Limit the width of the minimap to render at most a certain number of columns.") }, 'editor.hover.enabled': { @@ -515,7 +512,7 @@ const editorConfiguration: IConfigurationNode = { ] }, "Lines will wrap at the minimum of viewport and `#editor.wordWrapColumn#`."), ], - 'default': editorOptions.EditorOption.wordWrap.defaultValue, + 'default': EditorOption.wordWrap.defaultValue, 'description': nls.localize({ key: 'wordWrap', comment: [ @@ -526,7 +523,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.wordWrapColumn': { 'type': 'integer', - 'default': editorOptions.EditorOption.wordWrapColumn.defaultValue, + 'default': EditorOption.wordWrapColumn.defaultValue, 'minimum': 1, 'markdownDescription': nls.localize({ key: 'wordWrapColumn', @@ -550,12 +547,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.mouseWheelScrollSensitivity': { 'type': 'number', - 'default': editorOptions.EditorOption.mouseWheelScrollSensitivity.defaultValue, + 'default': EditorOption.mouseWheelScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.") }, 'editor.fastScrollSensitivity': { 'type': 'number', - 'default': editorOptions.EditorOption.fastScrollSensitivity.defaultValue, + 'default': EditorOption.fastScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('fastScrollSensitivity', "Scrolling speed multiplier when pressing `Alt`.") }, 'editor.multiCursorModifier': { @@ -972,7 +969,7 @@ const editorConfiguration: IConfigurationNode = { 'editor.cursorBlinking': { 'type': 'string', 'enum': ['blink', 'smooth', 'phase', 'expand', 'solid'], - 'default': editorOptions.blinkingStyleToString(EDITOR_DEFAULTS.viewInfo.cursorBlinking), + 'default': blinkingStyleToString(EDITOR_DEFAULTS.viewInfo.cursorBlinking), 'description': nls.localize('cursorBlinking', "Control the cursor animation style.") }, 'editor.mouseWheelZoom': { @@ -988,7 +985,7 @@ const editorConfiguration: IConfigurationNode = { 'editor.cursorStyle': { 'type': 'string', 'enum': ['block', 'block-outline', 'line', 'line-thin', 'underline', 'underline-thin'], - 'default': editorOptions.cursorStyleToString(EDITOR_DEFAULTS.viewInfo.cursorStyle), + 'default': cursorStyleToString(EDITOR_DEFAULTS.viewInfo.cursorStyle), 'description': nls.localize('cursorStyle', "Controls the cursor style.") }, 'editor.cursorWidth': { @@ -1052,7 +1049,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.folding': { 'type': 'boolean', - 'default': editorOptions.EditorOption.folding.defaultValue, + 'default': EditorOption.folding.defaultValue, 'description': nls.localize('folding', "Controls whether the editor has code folding enabled.") }, 'editor.foldingStrategy': { @@ -1105,7 +1102,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('accessibilitySupport.on', "The editor will be permanently optimized for usage with a Screen Reader."), nls.localize('accessibilitySupport.off', "The editor will never be optimized for usage with a Screen Reader."), ], - 'default': editorOptions.EditorOption.accessibilitySupport.defaultValue, + 'default': EditorOption.accessibilitySupport.defaultValue, 'description': nls.localize('accessibilitySupport', "Controls whether the editor should run in a mode where it is optimized for screen readers.") }, 'editor.showUnused': { @@ -1158,7 +1155,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.selectionClipboard': { 'type': 'boolean', - 'default': editorOptions.EditorOption.selectionClipboard.defaultValue, + 'default': EditorOption.selectionClipboard.defaultValue, 'description': nls.localize('selectionClipboard', "Controls whether the Linux primary clipboard should be supported."), 'included': platform.isLinux }, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index dc915f4f80b..8b81ce7e464 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -729,7 +729,20 @@ export interface IEditorOptions { */ showUnused?: boolean; + /** + * Do not use. + * @internal + */ + tabFocusMode?: undefined; + /** + * Do not use. + * @internal + */ layoutInfo?: undefined; + /** + * Do not use. + * @internal + */ wrappingInfo?: undefined; } @@ -1018,7 +1031,6 @@ export interface EditorContribOptions { export interface IValidatedEditorOptions { readonly wordSeparators: string; readonly lineDecorationsWidth: number | string; - readonly readOnly: boolean; readonly mouseStyle: 'text' | 'default' | 'copy'; readonly disableLayerHinting: boolean; readonly automaticLayout: boolean; @@ -1049,11 +1061,6 @@ export class InternalEditorOptions { readonly pixelRatio: number; readonly editorClassName: string; readonly lineHeight: number; - readonly readOnly: boolean; - /** - * @internal - */ - readonly accessibilitySupport: AccessibilitySupport; readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; readonly multiCursorMergeOverlapping: boolean; readonly showUnused: boolean; @@ -1066,7 +1073,6 @@ export class InternalEditorOptions { readonly autoSurround: EditorAutoSurroundStrategy; readonly autoIndent: boolean; readonly useTabStops: boolean; - readonly tabFocusMode: boolean; readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly copyWithSyntaxHighlighting: boolean; @@ -1084,7 +1090,6 @@ export class InternalEditorOptions { pixelRatio: number; editorClassName: string; lineHeight: number; - readOnly: boolean; multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; multiCursorMergeOverlapping: boolean; wordSeparators: string; @@ -1094,7 +1099,6 @@ export class InternalEditorOptions { autoSurround: EditorAutoSurroundStrategy; autoIndent: boolean; useTabStops: boolean; - tabFocusMode: boolean; dragAndDrop: boolean; emptySelectionClipboard: boolean; copyWithSyntaxHighlighting: boolean; @@ -1107,7 +1111,6 @@ export class InternalEditorOptions { this.pixelRatio = source.pixelRatio; this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight | 0; - this.readOnly = source.readOnly; this.multiCursorModifier = source.multiCursorModifier; this.multiCursorMergeOverlapping = source.multiCursorMergeOverlapping; this.wordSeparators = source.wordSeparators; @@ -1117,7 +1120,6 @@ export class InternalEditorOptions { this.autoSurround = source.autoSurround; this.autoIndent = source.autoIndent; this.useTabStops = source.useTabStops; - this.tabFocusMode = source.tabFocusMode; this.dragAndDrop = source.dragAndDrop; this.emptySelectionClipboard = source.emptySelectionClipboard; this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; @@ -1136,7 +1138,6 @@ export class InternalEditorOptions { && this.pixelRatio === other.pixelRatio && this.editorClassName === other.editorClassName && this.lineHeight === other.lineHeight - && this.readOnly === other.readOnly && this.multiCursorModifier === other.multiCursorModifier && this.multiCursorMergeOverlapping === other.multiCursorMergeOverlapping && this.wordSeparators === other.wordSeparators @@ -1146,7 +1147,6 @@ export class InternalEditorOptions { && this.autoSurround === other.autoSurround && this.autoIndent === other.autoIndent && this.useTabStops === other.useTabStops - && this.tabFocusMode === other.tabFocusMode && this.dragAndDrop === other.dragAndDrop && this.showUnused === other.showUnused && this.emptySelectionClipboard === other.emptySelectionClipboard @@ -1172,7 +1172,6 @@ export class InternalEditorOptions { pixelRatio: (this.pixelRatio !== newOpts.pixelRatio), editorClassName: (this.editorClassName !== newOpts.editorClassName), lineHeight: (this.lineHeight !== newOpts.lineHeight), - readOnly: (this.readOnly !== newOpts.readOnly), multiCursorModifier: (this.multiCursorModifier !== newOpts.multiCursorModifier), multiCursorMergeOverlapping: (this.multiCursorMergeOverlapping !== newOpts.multiCursorMergeOverlapping), wordSeparators: (this.wordSeparators !== newOpts.wordSeparators), @@ -1182,7 +1181,6 @@ export class InternalEditorOptions { autoSurround: (this.autoSurround !== newOpts.autoSurround), autoIndent: (this.autoIndent !== newOpts.autoIndent), useTabStops: (this.useTabStops !== newOpts.useTabStops), - tabFocusMode: (this.tabFocusMode !== newOpts.tabFocusMode), dragAndDrop: (this.dragAndDrop !== newOpts.dragAndDrop), emptySelectionClipboard: (this.emptySelectionClipboard !== newOpts.emptySelectionClipboard), copyWithSyntaxHighlighting: (this.copyWithSyntaxHighlighting !== newOpts.copyWithSyntaxHighlighting), @@ -1353,7 +1351,6 @@ export interface IConfigurationChangedEvent { readonly pixelRatio: boolean; readonly editorClassName: boolean; readonly lineHeight: boolean; - readonly readOnly: boolean; readonly multiCursorModifier: boolean; readonly multiCursorMergeOverlapping: boolean; readonly wordSeparators: boolean; @@ -1363,7 +1360,6 @@ export interface IConfigurationChangedEvent { readonly autoSurround: boolean; readonly autoIndent: boolean; readonly useTabStops: boolean; - readonly tabFocusMode: boolean; readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly copyWithSyntaxHighlighting: boolean; @@ -1534,7 +1530,6 @@ export class EditorOptionsValidator { return { wordSeparators: _string(opts.wordSeparators, defaults.wordSeparators), lineDecorationsWidth: (typeof opts.lineDecorationsWidth === 'undefined' ? defaults.lineDecorationsWidth : opts.lineDecorationsWidth), - readOnly: _boolean(opts.readOnly, defaults.readOnly), mouseStyle: _stringSet<'text' | 'default' | 'copy'>(opts.mouseStyle, defaults.mouseStyle, ['text', 'default', 'copy']), disableLayerHinting: _boolean(opts.disableLayerHinting, defaults.disableLayerHinting), automaticLayout: _boolean(opts.automaticLayout, defaults.automaticLayout), @@ -1768,7 +1763,6 @@ export class InternalEditorOptionsFactory { pixelRatio: env.pixelRatio, editorClassName: className, lineHeight: env.fontInfo.lineHeight, - readOnly: opts.readOnly, multiCursorModifier: opts.multiCursorModifier, multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping, wordSeparators: opts.wordSeparators, @@ -1778,7 +1772,6 @@ export class InternalEditorOptionsFactory { autoSurround: opts.autoSurround, autoIndent: opts.autoIndent, useTabStops: opts.useTabStops, - tabFocusMode: opts.readOnly ? true : env.tabFocusMode, dragAndDrop: opts.dragAndDrop, emptySelectionClipboard: opts.emptySelectionClipboard && env.emptySelectionClipboard, copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting, @@ -1858,7 +1851,6 @@ export const EDITOR_MODEL_DEFAULTS = { export const EDITOR_DEFAULTS: IValidatedEditorOptions = { wordSeparators: USUAL_WORD_SEPARATORS, lineDecorationsWidth: 10, - readOnly: false, mouseStyle: 'text', disableLayerHinting: false, automaticLayout: false, @@ -1991,7 +1983,7 @@ export class ValidatedEditorOptions { } export interface IComputedEditorOptions { - get>(id: EditorOptionId): ComputedEditorOptionValue; + get(id: T): FindComputedEditorOptionValueById; } /** @@ -2002,7 +1994,7 @@ export class ComputedEditorOptions implements IComputedEditorOptions { public _read(id: EditorOptionId): T { return this._values[id]; } - public get>(id: EditorOptionId): ComputedEditorOptionValue { + public get(id: T): FindComputedEditorOptionValueById { return this._values[id]; } public _write(id: EditorOptionId, value: T): void { @@ -2025,8 +2017,8 @@ export class ChangedEditorOptions { export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; -export interface IEditorOption { - readonly id: EditorOptionId; +export interface IEditorOption { + readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; read(options: IRawEditorOptionsBag): T1 | undefined; @@ -2039,20 +2031,20 @@ export interface IEditorOption { /** * @internal */ -export const editorOptionsRegistry: IEditorOption[] = []; +export const editorOptionsRegistry: IEditorOption[] = []; -function registerEditorOption(option: IEditorOption): IEditorOption { +function registerEditorOption(option: IEditorOption): IEditorOption { editorOptionsRegistry[option.id] = option; return option; } -export abstract class BaseEditorOption implements IEditorOption { +export abstract class BaseEditorOption implements IEditorOption { - public readonly id: EditorOptionId; + public readonly id: K; public readonly name: PossibleKeyName; public readonly defaultValue: T2; - constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T2, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps: EditorOptionId[] = []) { this.id = id; this.name = name; this.defaultValue = defaultValue; @@ -2082,7 +2074,7 @@ export abstract class BaseEditorOption implements IEditorO } } -class EditorBooleanOption extends BaseEditorOption { +class EditorBooleanOption extends BaseEditorOption { public validate(input: boolean | undefined): boolean { return _boolean(input, this.defaultValue); } @@ -2091,10 +2083,10 @@ class EditorBooleanOption extends BaseEditorOption { } } -class EditorIntOption extends BaseEditorOption { +class EditorIntOption extends BaseEditorOption { public readonly minimum: number; public readonly maximum: number; - constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOptionId[] = []) { super(id, name, defaultValue, deps); this.minimum = minimum; this.maximum = maximum; @@ -2107,9 +2099,9 @@ class EditorIntOption extends BaseEditorOption { } } -class EditorFloatOption extends BaseEditorOption { +class EditorFloatOption extends BaseEditorOption { public readonly validationFn: (value: number) => number; - constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOptionId[] = []) { super(id, name, defaultValue, deps); this.validationFn = validationFn; } @@ -2121,7 +2113,7 @@ class EditorFloatOption extends BaseEditorOption { } } -class EditorStringOption extends BaseEditorOption { +class EditorStringOption extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } @@ -2130,10 +2122,10 @@ class EditorStringOption extends BaseEditorOption { } } -class EditorEnumOption extends BaseEditorOption { +class EditorEnumOption extends BaseEditorOption { public readonly allowedValues: T1[]; public readonly convert: (value: T1) => T2; - constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOptionId[] = []) { super(id, name, defaultValue, deps); this.allowedValues = allowedValues; this.convert = convert; @@ -2146,7 +2138,7 @@ class EditorEnumOption extends BaseEditorOption { } } -class EditorPassthroughOption extends BaseEditorOption { +class EditorPassthroughOption extends BaseEditorOption { public validate(input: T | undefined): T { if (typeof input === 'undefined') { return this.defaultValue; @@ -2175,7 +2167,7 @@ export interface InternalEditorRenderLineNumbersOptions { readonly renderFn: ((lineNumber: number) => string) | null; } -class EditorRenderLineNumbersOption extends BaseEditorOption { +class EditorRenderLineNumbersOption extends BaseEditorOption { public validate(lineNumbers: LineNumbersType | undefined): InternalEditorRenderLineNumbersOptions { let renderType: RenderLineNumbersType = this.defaultValue.renderType; let renderFn: ((lineNumber: number) => string) | null = this.defaultValue.renderFn; @@ -2223,7 +2215,7 @@ export interface InternalEditorMinimapOptions { readonly maxColumn: number; } -class EditorMinimapOption extends BaseEditorOption { +class EditorMinimapOption extends BaseEditorOption { public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2254,7 +2246,7 @@ class EditorMinimapOption extends BaseEditorOption { +class EditorAccessibilitySupportOption extends BaseEditorOption { public validate(input: 'auto' | 'off' | 'on' | undefined): 'auto' | 'off' | 'on' { return _stringSet<'auto' | 'off' | 'on'>(input, this.defaultValue, ['auto', 'off', 'on']); } @@ -2274,12 +2266,12 @@ class EditorAccessibilitySupportOption extends BaseEditorOption<'auto' | 'off' | //#region ariaLabel -class EditorAriaLabel extends BaseEditorOption { +class EditorAriaLabel extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { - const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); if (accessibilitySupport === AccessibilitySupport.Disabled) { return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options."); } @@ -2289,6 +2281,20 @@ class EditorAriaLabel extends BaseEditorOption { //#endregion +//#region tabFocusMode + +class EditorTabFocusMode extends BaseEditorOption { + public validate(input: undefined): undefined { + return undefined; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): boolean { + const readOnly = options.get(EditorOptionId.readOnly); + return (readOnly ? true : env.tabFocusMode); + } +} + +//#endregion + //#region scrollbar export interface InternalEditorScrollbarOptions { @@ -2305,7 +2311,7 @@ export interface InternalEditorScrollbarOptions { readonly verticalSliderSize: number; } -class EditorScrollbarOption extends BaseEditorOption { +class EditorScrollbarOption extends BaseEditorOption { public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2475,18 +2481,18 @@ export interface EditorLayoutInfo { /** * @internal */ -export class EditorLayoutInfoComputer extends BaseEditorOption { +export class EditorLayoutInfoComputer extends BaseEditorOption { public validate(input: undefined): undefined { return undefined; } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorLayoutInfo { - const glyphMargin = options.get(EditorOptionId.glyphMargin); - const lineNumbersMinChars = options.get(EditorOptionId.lineNumbersMinChars); - const rawLineDecorationsWidth = options.get(EditorOptionId.lineDecorationsWidth); - const folding = options.get(EditorOptionId.folding); - const minimap = options.get(EditorOptionId.minimap); - const scrollbar = options.get(EditorOptionId.scrollbar); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const glyphMargin = options.get(EditorOptionId.glyphMargin); + const lineNumbersMinChars = options.get(EditorOptionId.lineNumbersMinChars); + const rawLineDecorationsWidth = options.get(EditorOptionId.lineDecorationsWidth); + const folding = options.get(EditorOptionId.folding); + const minimap = options.get(EditorOptionId.minimap); + const scrollbar = options.get(EditorOptionId.scrollbar); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); let lineDecorationsWidth: number; if (typeof rawLineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(rawLineDecorationsWidth)) { @@ -2547,9 +2553,6 @@ export class EditorLayoutInfoComputer extends BaseEditorOption { +class EditorWrappingInfoComputer extends BaseEditorOption { public mix(a: undefined, b: undefined): undefined { return undefined; } @@ -2711,11 +2714,11 @@ class EditorWrappingInfoComputer extends BaseEditorOption(EditorOptionId.wordWrap); - const wordWrapColumn = options.get(EditorOptionId.wordWrapColumn); - const wordWrapMinified = options.get(EditorOptionId.wordWrapMinified); - const layoutInfo = options.get(EditorOptionId.layoutInfo); - const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + const wordWrap = options.get(EditorOptionId.wordWrap); + const wordWrapColumn = options.get(EditorOptionId.wordWrapColumn); + const wordWrapMinified = options.get(EditorOptionId.wordWrapMinified); + const layoutInfo = options.get(EditorOptionId.layoutInfo); + const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null; { @@ -2793,11 +2796,13 @@ export const enum EditorOptionId { lineNumbersMinChars, minimap, mouseWheelScrollSensitivity, + readOnly, renderFinalNewline, renderLineNumbers, scrollbar, selectionClipboard, selectOnLineNumbers, + tabFocusMode, wordWrap, wordWrapBreakAfterCharacters, wordWrapBreakBeforeCharacters, @@ -2817,7 +2822,7 @@ export const EditorOption = { folding: registerEditorOption(new EditorBooleanOption(EditorOptionId.folding, 'folding', true)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOptionId.glyphMargin, 'glyphMargin', true)), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOptionId.inDiffEditor, 'inDiffEditor', false)), - lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOptionId.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOptionId.lineDecorationsWidth, 'lineDecorationsWidth', 10)), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOptionId.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), minimap: registerEditorOption(new EditorMinimapOption(EditorOptionId.minimap, 'minimap', { enabled: true, @@ -2827,6 +2832,7 @@ export const EditorOption = { maxColumn: 120, })), mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOptionId.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), + readOnly: registerEditorOption(new EditorBooleanOption(EditorOptionId.readOnly, 'readOnly', false)), renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOptionId.renderFinalNewline, 'renderFinalNewline', true)), renderLineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOptionId.renderLineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOptionId.scrollbar, 'scrollbar', { @@ -2844,17 +2850,21 @@ export const EditorOption = { })), selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectionClipboard, 'selectionClipboard', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectOnLineNumbers, 'selectOnLineNumbers', true)), - wordWrap: registerEditorOption(new EditorEnumOption<'off' | 'on' | 'wordWrapColumn' | 'bounded'>(EditorOptionId.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), + tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOptionId.tabFocusMode, 'tabFocusMode', undefined, [EditorOptionId.readOnly])), + wordWrap: registerEditorOption(new EditorEnumOption(EditorOptionId.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOptionId.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOptionId.wordWrapMinified, 'wordWrapMinified', true)), - wrappingIndent: registerEditorOption(new EditorEnumOption<'none' | 'same' | 'indent' | 'deepIndent', WrappingIndent>(EditorOptionId.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), + wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOptionId.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), // Leave these at the end! layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOptionId.layoutInfo, 'layoutInfo', undefined, [EditorOptionId.glyphMargin, EditorOptionId.lineDecorationsWidth, EditorOptionId.folding, EditorOptionId.minimap, EditorOptionId.scrollbar, EditorOptionId.renderLineNumbers])), wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOptionId.wrappingInfo, 'wrappingInfo', undefined, [EditorOptionId.wordWrap, EditorOptionId.wordWrapColumn, EditorOptionId.wordWrapMinified, EditorOptionId.layoutInfo, EditorOptionId.accessibilitySupport])), }; -export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; +export type EditorOptionType = typeof EditorOption; +export type FindEditorOptionKeyById = { [K in keyof EditorOptionType]: EditorOptionType[K]['id'] extends T ? K : never }[keyof EditorOptionType]; +export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; +export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index b76218fe99b..fce316527de 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -20,6 +20,7 @@ import { RawContentChangedType } from 'vs/editor/common/model/textModelEvents'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { dispose } from 'vs/base/common/lifecycle'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; function containsLineMappingChanged(events: viewEvents.ViewEvent[]): boolean { for (let i = 0, len = events.length; i < len; i++) { @@ -673,7 +674,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { this._isDoingComposition = false; } - if (this._configuration.editor.readOnly) { + if (this._configuration.options.get(EditorOptionId.readOnly)) { // All the remaining handlers will try to edit the model, // but we cannot edit when read only... this._onDidAttemptReadOnlyEdit.fire(undefined); diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index 80775a63bd2..8c9ecb6a3d7 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -6,7 +6,7 @@ import { CharCode } from 'vs/base/common/charCode'; import { onUnexpectedError } from 'vs/base/common/errors'; import * as strings from 'vs/base/common/strings'; -import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -122,7 +122,7 @@ export class CursorConfiguration { || e.autoSurround || e.useTabStops || e.lineHeight - || e.readOnly + || e.hasChanged(EditorOptionId.readOnly) ); } @@ -135,9 +135,9 @@ export class CursorConfiguration { const c = configuration.editor; const options = configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); - this.readOnly = c.readOnly; + this.readOnly = options.get(EditorOptionId.readOnly); this.tabSize = modelOptions.tabSize; this.indentSize = modelOptions.indentSize; this.insertSpaces = modelOptions.insertSpaces; diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index d3b4118c433..b23d2a1b9b2 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -450,20 +450,22 @@ export enum EditorOptionId { lineNumbersMinChars = 7, minimap = 8, mouseWheelScrollSensitivity = 9, - renderFinalNewline = 10, - renderLineNumbers = 11, - scrollbar = 12, - selectionClipboard = 13, - selectOnLineNumbers = 14, - wordWrap = 15, - wordWrapBreakAfterCharacters = 16, - wordWrapBreakBeforeCharacters = 17, - wordWrapBreakObtrusiveCharacters = 18, - wordWrapColumn = 19, - wordWrapMinified = 20, - wrappingIndent = 21, - layoutInfo = 22, - wrappingInfo = 23 + readOnly = 10, + renderFinalNewline = 11, + renderLineNumbers = 12, + scrollbar = 13, + selectionClipboard = 14, + selectOnLineNumbers = 15, + tabFocusMode = 16, + wordWrap = 17, + wordWrapBreakAfterCharacters = 18, + wordWrapBreakBeforeCharacters = 19, + wordWrapBreakObtrusiveCharacters = 20, + wordWrapColumn = 21, + wordWrapMinified = 22, + wrappingIndent = 23, + layoutInfo = 24, + wrappingInfo = 25 } /** diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index 47006636def..ebb674197e0 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -39,7 +39,6 @@ export class ViewConfigurationChangedEvent { public readonly pixelRatio: boolean; public readonly editorClassName: boolean; public readonly lineHeight: boolean; - public readonly readOnly: boolean; public readonly emptySelectionClipboard: boolean; public readonly copyWithSyntaxHighlighting: boolean; public readonly fontInfo: boolean; @@ -51,7 +50,6 @@ export class ViewConfigurationChangedEvent { this.pixelRatio = source.pixelRatio; this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight; - this.readOnly = source.readOnly; this.emptySelectionClipboard = source.emptySelectionClipboard; this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; this.fontInfo = source.fontInfo; diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 978aa54a3bb..99cd7efff43 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -6,7 +6,7 @@ import { Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { IScrollDimensions, IScrollPosition, ScrollEvent, Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { LinesLayout } from 'vs/editor/common/viewLayout/linesLayout'; import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; @@ -28,7 +28,7 @@ export class ViewLayout extends Disposable implements IViewLayout { this._configuration = configuration; const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this._linesLayout = new LinesLayout(lineCount, this._configuration.editor.lineHeight); @@ -64,7 +64,7 @@ export class ViewLayout extends Disposable implements IViewLayout { } if (e.hasChanged(EditorOptionId.layoutInfo)) { const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOptionId.layoutInfo); this.scrollable.setScrollDimensions({ width: layoutInfo.contentWidth, height: layoutInfo.contentHeight @@ -89,7 +89,7 @@ export class ViewLayout extends Disposable implements IViewLayout { private _getHorizontalScrollbarHeight(scrollDimensions: IScrollDimensions): number { const options = this._configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOptionId.scrollbar); if (scrollbar.horizontal === ScrollbarVisibility.Hidden) { // horizontal scrollbar not visible return 0; @@ -146,7 +146,7 @@ export class ViewLayout extends Disposable implements IViewLayout { private _computeScrollWidth(maxLineWidth: number, viewportWidth: number): number { const options = this._configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); let isViewportWrapping = wrappingInfo.isViewportWrapping; if (!isViewportWrapping) { const extraHorizontalSpace = this._configuration.editor.viewInfo.scrollBeyondLastColumn * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; diff --git a/src/vs/editor/common/viewModel/viewModelDecorations.ts b/src/vs/editor/common/viewModel/viewModelDecorations.ts index 07df48c622e..bedcfb72b83 100644 --- a/src/vs/editor/common/viewModel/viewModelDecorations.ts +++ b/src/vs/editor/common/viewModel/viewModelDecorations.ts @@ -10,6 +10,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon'; import { IModelDecoration, ITextModel } from 'vs/editor/common/model'; import { IViewModelLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection'; import { ICoordinatesConverter, InlineDecoration, InlineDecorationType, ViewModelDecoration } from 'vs/editor/common/viewModel/viewModel'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export interface IDecorationsViewportData { /** @@ -103,7 +104,7 @@ export class ViewModelDecorations implements IDisposable { } private _getDecorationsViewportData(viewportRange: Range): IDecorationsViewportData { - const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, this.configuration.editor.readOnly); + const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, this.configuration.options.get(EditorOptionId.readOnly)); const startLineNumber = viewportRange.startLineNumber; const endLineNumber = viewportRange.endLineNumber; diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 73350e18214..8ccdd124225 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import * as strings from 'vs/base/common/strings'; -import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -61,11 +61,11 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } else { const conf = this.configuration.editor; const options = this.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = options.get(EditorOptionId.wrappingIndent); let hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, @@ -154,8 +154,8 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel const conf = this.configuration.editor; const options = this.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); - const wrappingIndent = options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingIndent = options.get(EditorOptionId.wrappingIndent); if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth)) { eventsCollector.emit(new viewEvents.ViewFlushedEvent()); @@ -170,7 +170,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } } - if (e.readOnly) { + if (e.hasChanged(EditorOptionId.readOnly)) { // Must read again all decorations due to readOnly filtering this.decorations.reset(); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); @@ -561,7 +561,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } public getAllOverviewRulerDecorations(theme: ITheme): IOverviewRulerDecorations { - return this.lines.getAllOverviewRulerDecorations(this.editorId, this.configuration.editor.readOnly, theme); + return this.lines.getAllOverviewRulerDecorations(this.editorId, this.configuration.options.get(EditorOptionId.readOnly), theme); } public invalidateOverviewRulerColorCache(): void { diff --git a/src/vs/editor/contrib/codeAction/codeActionModel.ts b/src/vs/editor/contrib/codeAction/codeActionModel.ts index d1b33028aee..3c8b4dacdd1 100644 --- a/src/vs/editor/contrib/codeAction/codeActionModel.ts +++ b/src/vs/editor/contrib/codeAction/codeActionModel.ts @@ -17,6 +17,7 @@ import { IMarkerService } from 'vs/platform/markers/common/markers'; import { IEditorProgressService } from 'vs/platform/progress/common/progress'; import { getCodeActions, CodeActionSet } from './codeAction'; import { CodeActionTrigger } from './codeActionTrigger'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export const SUPPORTED_CODE_ACTIONS = new RawContextKey('supportedCodeAction', ''); @@ -192,7 +193,7 @@ export class CodeActionModel extends Disposable { const model = this._editor.getModel(); if (model && CodeActionProviderRegistry.has(model) - && !this._editor.getConfiguration().readOnly + && !this._editor.getOption(EditorOptionId.readOnly) ) { const supportedActions: string[] = []; for (const provider of CodeActionProviderRegistry.all(model)) { diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 664bc8c8bf3..253052dace3 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -26,6 +26,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { INotificationService } from 'vs/platform/notification/common/notification'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; const SEARCH_STRING_MAX_LENGTH = 524288; @@ -698,7 +699,7 @@ export class StartFindReplaceAction extends EditorAction { } public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { - if (!editor.hasModel() || editor.getConfiguration().readOnly) { + if (!editor.hasModel() || editor.getOption(EditorOptionId.readOnly)) { return; } diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index 3b31b2e3b57..c62ff1190bf 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -176,8 +176,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._findInput.inputBox.layout(); this._register(this._codeEditor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.readOnly) { - if (this._codeEditor.getConfiguration().readOnly) { + if (e.hasChanged(EditorOptionId.readOnly)) { + if (this._codeEditor.getOption(EditorOptionId.readOnly)) { // Hide replace part if editor becomes read only this._state.change({ isReplaceRevealed: false }, false); } @@ -315,7 +315,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } if (e.isReplaceRevealed) { if (this._state.isReplaceRevealed) { - if (!this._codeEditor.getConfiguration().readOnly && !this._isReplaceVisible) { + if (!this._codeEditor.getOption(EditorOptionId.readOnly) && !this._isReplaceVisible) { this._isReplaceVisible = true; this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode); this._updateButtons(); @@ -456,7 +456,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._toggleReplaceBtn.toggleClass('expand', this._isReplaceVisible); this._toggleReplaceBtn.setExpanded(this._isReplaceVisible); - let canReplace = !this._codeEditor.getConfiguration().readOnly; + let canReplace = !this._codeEditor.getOption(EditorOptionId.readOnly); this._toggleReplaceBtn.setEnabled(this._isVisible && canReplace); } @@ -1210,7 +1210,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } private updateAccessibilitySupport(): void { - const value = this._codeEditor.getConfiguration().accessibilitySupport; + const value = this._codeEditor.getOption(EditorOptionId.accessibilitySupport); this._findInput.setFocusInputOnOptionClick(value !== AccessibilitySupport.Enabled); } } diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index 4a705db696e..4c4c0f2adc7 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -18,7 +18,7 @@ import { FoldingModel, setCollapseStateAtLevel, CollapseMemento, setCollapseStat import { FoldingDecorationProvider } from './foldingDecorations'; import { FoldingRegions, FoldingRegion } from './foldingRanges'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IMarginData, IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { HiddenRangeModel } from 'vs/editor/contrib/folding/hiddenRangeModel'; import { IRange } from 'vs/editor/common/core/range'; @@ -88,7 +88,7 @@ export class FoldingController extends Disposable implements IEditorContribution super(); this.editor = editor; const options = this.editor.getOptions(); - this._isEnabled = options.get(EditorOptionId.folding); + this._isEnabled = options.get(EditorOptionId.folding); this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover'; this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation'; @@ -113,7 +113,7 @@ export class FoldingController extends Disposable implements IEditorContribution if (e.contribInfo || e.hasChanged(EditorOptionId.folding)) { let oldIsEnabled = this._isEnabled; const options = this.editor.getOptions(); - this._isEnabled = options.get(EditorOptionId.folding); + this._isEnabled = options.get(EditorOptionId.folding); this.foldingEnabled.set(this._isEnabled); if (oldIsEnabled !== this._isEnabled) { this.onModelChanged(); diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index 583e4c65dee..36cd010daff 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -11,7 +11,7 @@ import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution, IScrollEvent } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -265,7 +265,7 @@ class ShowHoverAction extends EditorAction { } const position = editor.getPosition(); const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column); - const focus = editor.getConfiguration().accessibilitySupport === AccessibilitySupport.Enabled; + const focus = editor.getOption(EditorOptionId.accessibilitySupport) === AccessibilitySupport.Enabled; controller.showContentHover(range, HoverStartMode.Immediate, focus); } } diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index d34f911cea8..c82ea98b95b 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -20,6 +20,7 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2 import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export interface ICancelEvent { readonly retrigger: boolean; @@ -183,7 +184,7 @@ export class SuggestModel implements IDisposable { dispose(this._triggerCharacterListener); - if (this._editor.getConfiguration().readOnly + if (this._editor.getOption(EditorOptionId.readOnly) || !this._editor.hasModel() || !this._editor.getConfiguration().contribInfo.suggestOnTriggerCharacters) { diff --git a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts index dc640cc2b3c..a0afb73c164 100644 --- a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts +++ b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts @@ -31,7 +31,7 @@ import { contrastBorder, editorWidgetBackground, widgetShadow, editorWidgetForeg import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { AccessibilityHelpNLS } from 'vs/editor/common/standaloneStrings'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new RawContextKey('accessibilityHelpWidgetVisible', false); @@ -224,7 +224,6 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { } private _buildContent() { - let opts = this._editor.getConfiguration(); const options = this._editor.getOptions(); const selections = this._editor.getSelections(); @@ -241,14 +240,14 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { let text = getSelectionLabel(selections, charactersSelected); - if (options.get(EditorOptionId.inDiffEditor)) { - if (opts.readOnly) { + if (options.get(EditorOptionId.inDiffEditor)) { + if (options.get(EditorOptionId.readOnly)) { text += AccessibilityHelpNLS.readonlyDiffEditor; } else { text += AccessibilityHelpNLS.editableDiffEditor; } } else { - if (opts.readOnly) { + if (options.get(EditorOptionId.readOnly)) { text += AccessibilityHelpNLS.readonlyEditor; } else { text += AccessibilityHelpNLS.editableEditor; @@ -260,7 +259,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { ? AccessibilityHelpNLS.changeConfigToOnMac : AccessibilityHelpNLS.changeConfigToOnWinLinux ); - switch (opts.accessibilitySupport) { + switch (options.get(EditorOptionId.accessibilitySupport)) { case AccessibilitySupport.Unknown: text += '\n\n - ' + turnOnMessage; break; @@ -274,7 +273,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { } - if (opts.tabFocusMode) { + if (options.get(EditorOptionId.tabFocusMode)) { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOnMsg, AccessibilityHelpNLS.tabFocusModeOnMsgNoKb); } else { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOffMsg, AccessibilityHelpNLS.tabFocusModeOffMsgNoKb); diff --git a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts index b36f6ecdc23..82c5fb1a312 100644 --- a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts +++ b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts @@ -10,6 +10,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class IPadShowKeyboard extends Disposable implements IEditorContribution { @@ -29,7 +30,7 @@ export class IPadShowKeyboard extends Disposable implements IEditorContribution } private update(): void { - const shouldHaveWidget = (!this.editor.getConfiguration().readOnly); + const shouldHaveWidget = (!this.editor.getOption(EditorOptionId.readOnly)); if (!this.widget && shouldHaveWidget) { diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index 649c7f9718b..9a0c8edad12 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorHoverOptions, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; @@ -68,7 +68,7 @@ suite('Common Editor Config', () => { function assertWrapping(config: TestConfiguration, isViewportWrapping: boolean, wrappingColumn: number): void { const options = config.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); assert.equal(wrappingInfo.isViewportWrapping, isViewportWrapping); assert.equal(wrappingInfo.wrappingColumn, wrappingColumn); } diff --git a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts index 20ba2e12437..faa9ac14097 100644 --- a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts +++ b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts @@ -19,7 +19,8 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer' import { ILineMapping, ISimpleModel, SplitLine, SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection'; import { ViewLineData } from 'vs/editor/common/viewModel/viewModel'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; + suite('Editor ViewModel - SplitLinesCollection', () => { test('SplitLine', () => { @@ -90,11 +91,11 @@ suite('Editor ViewModel - SplitLinesCollection', () => { function withSplitLinesCollection(text: string, callback: (model: TextModel, linesCollection: SplitLinesCollection) => void): void { const config = new TestConfiguration({}); - const wrappingInfo = config.options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = config.options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = config.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = config.options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = config.options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = config.options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = config.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = config.options.get(EditorOptionId.wrappingIndent); const hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, @@ -743,11 +744,11 @@ suite('SplitLinesCollection', () => { wordWrapColumn: wordWrapColumn, wrappingIndent: 'indent' }); - const wrappingInfo = configuration.options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = configuration.options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = configuration.options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = configuration.options.get(EditorOptionId.wrappingInfo); + const wordWrapBreakAfterCharacters = configuration.options.get(EditorOptionId.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = configuration.options.get(EditorOptionId.wrappingIndent); const factory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 32d7a932be4..ab2061dd683 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3114,8 +3114,6 @@ declare namespace monaco.editor { * Controls fading out of unused variables. */ showUnused?: boolean; - layoutInfo?: undefined; - wrappingInfo?: undefined; } /** @@ -3345,7 +3343,6 @@ declare namespace monaco.editor { readonly pixelRatio: number; readonly editorClassName: string; readonly lineHeight: number; - readonly readOnly: boolean; readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; readonly multiCursorMergeOverlapping: boolean; readonly showUnused: boolean; @@ -3356,7 +3353,6 @@ declare namespace monaco.editor { readonly autoSurround: EditorAutoSurroundStrategy; readonly autoIndent: boolean; readonly useTabStops: boolean; - readonly tabFocusMode: boolean; readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly copyWithSyntaxHighlighting: boolean; @@ -3374,7 +3370,6 @@ declare namespace monaco.editor { readonly pixelRatio: boolean; readonly editorClassName: boolean; readonly lineHeight: boolean; - readonly readOnly: boolean; readonly multiCursorModifier: boolean; readonly multiCursorMergeOverlapping: boolean; readonly wordSeparators: boolean; @@ -3384,7 +3379,6 @@ declare namespace monaco.editor { readonly autoSurround: boolean; readonly autoIndent: boolean; readonly useTabStops: boolean; - readonly tabFocusMode: boolean; readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly copyWithSyntaxHighlighting: boolean; @@ -3411,15 +3405,15 @@ declare namespace monaco.editor { } export interface IComputedEditorOptions { - get>(id: EditorOptionId): ComputedEditorOptionValue; + get(id: T): FindComputedEditorOptionValueById; } export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never; }[keyof IEditorOptions]; - export interface IEditorOption { - readonly id: EditorOptionId; + export interface IEditorOption { + readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; read(options: IRawEditorOptionsBag): T1 | undefined; @@ -3429,11 +3423,11 @@ declare namespace monaco.editor { equals(a: T3, b: T3): boolean; } - export abstract class BaseEditorOption implements IEditorOption { - readonly id: EditorOptionId; + export abstract class BaseEditorOption implements IEditorOption { + readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; - constructor(id: EditorOptionId, name: PossibleKeyName, defaultValue: T2, deps?: EditorOptionId[]); + constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps?: EditorOptionId[]); read(options: IRawEditorOptionsBag): T1 | undefined; mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; abstract validate(input: T1 | undefined): T2; @@ -3608,50 +3602,62 @@ declare namespace monaco.editor { lineNumbersMinChars = 7, minimap = 8, mouseWheelScrollSensitivity = 9, - renderFinalNewline = 10, - renderLineNumbers = 11, - scrollbar = 12, - selectionClipboard = 13, - selectOnLineNumbers = 14, - wordWrap = 15, - wordWrapBreakAfterCharacters = 16, - wordWrapBreakBeforeCharacters = 17, - wordWrapBreakObtrusiveCharacters = 18, - wordWrapColumn = 19, - wordWrapMinified = 20, - wrappingIndent = 21, - layoutInfo = 22, - wrappingInfo = 23 + readOnly = 10, + renderFinalNewline = 11, + renderLineNumbers = 12, + scrollbar = 13, + selectionClipboard = 14, + selectOnLineNumbers = 15, + tabFocusMode = 16, + wordWrap = 17, + wordWrapBreakAfterCharacters = 18, + wordWrapBreakBeforeCharacters = 19, + wordWrapBreakObtrusiveCharacters = 20, + wordWrapColumn = 21, + wordWrapMinified = 22, + wrappingIndent = 23, + layoutInfo = 24, + wrappingInfo = 25 } export const EditorOption: { - accessibilitySupport: IEditorOption<"auto" | "on" | "off", "auto" | "on" | "off", any>; - ariaLabel: IEditorOption; - fastScrollSensitivity: IEditorOption; - folding: IEditorOption; - glyphMargin: IEditorOption; - inDiffEditor: IEditorOption; - lineDecorationsWidth: IEditorOption; - lineNumbersMinChars: IEditorOption; - minimap: IEditorOption; - mouseWheelScrollSensitivity: IEditorOption; - renderFinalNewline: IEditorOption; - renderLineNumbers: IEditorOption; - scrollbar: IEditorOption; - selectionClipboard: IEditorOption; - selectOnLineNumbers: IEditorOption; - wordWrap: IEditorOption<"on" | "off" | "wordWrapColumn" | "bounded", "on" | "off" | "wordWrapColumn" | "bounded", "on" | "off" | "wordWrapColumn" | "bounded">; - wordWrapBreakAfterCharacters: IEditorOption; - wordWrapBreakBeforeCharacters: IEditorOption; - wordWrapBreakObtrusiveCharacters: IEditorOption; - wordWrapColumn: IEditorOption; - wordWrapMinified: IEditorOption; - wrappingIndent: IEditorOption<"none" | "same" | "indent" | "deepIndent", "none" | "same" | "indent" | "deepIndent", WrappingIndent>; - layoutInfo: IEditorOption; - wrappingInfo: IEditorOption; + accessibilitySupport: IEditorOption; + ariaLabel: IEditorOption; + fastScrollSensitivity: IEditorOption; + folding: IEditorOption; + glyphMargin: IEditorOption; + inDiffEditor: IEditorOption; + lineDecorationsWidth: IEditorOption; + lineNumbersMinChars: IEditorOption; + minimap: IEditorOption; + mouseWheelScrollSensitivity: IEditorOption; + readOnly: IEditorOption; + renderFinalNewline: IEditorOption; + renderLineNumbers: IEditorOption; + scrollbar: IEditorOption; + selectionClipboard: IEditorOption; + selectOnLineNumbers: IEditorOption; + tabFocusMode: IEditorOption; + wordWrap: IEditorOption; + wordWrapBreakAfterCharacters: IEditorOption; + wordWrapBreakBeforeCharacters: IEditorOption; + wordWrapBreakObtrusiveCharacters: IEditorOption; + wordWrapColumn: IEditorOption; + wordWrapMinified: IEditorOption; + wrappingIndent: IEditorOption; + layoutInfo: IEditorOption; + wrappingInfo: IEditorOption; }; - export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; + export type EditorOptionType = typeof EditorOption; + + export type FindEditorOptionKeyById = { + [K in keyof EditorOptionType]: EditorOptionType[K]['id'] extends T ? K : never; + }[keyof EditorOptionType]; + + export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; + + export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; /** * A view zone is a full horizontal rectangle that 'pushes' text down. @@ -4103,7 +4109,7 @@ declare namespace monaco.editor { */ getConfiguration(): InternalEditorOptions; getOptions(): IComputedEditorOptions; - getOption>(id: EditorOptionId): ComputedEditorOptionValue; + getOption(id: T): FindComputedEditorOptionValueById; /** * Get value of the current model attached to this editor. * @see `ITextModel.getValue` diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index 10437ec2ed6..7d1d2022fed 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -6,7 +6,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -60,7 +60,7 @@ export class MainThreadTextEditorProperties { if (codeEditor) { const codeEditorOpts = codeEditor.getConfiguration(); const options = codeEditor.getOptions(); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); cursorStyle = codeEditorOpts.viewInfo.cursorStyle; lineNumbers = renderLineNumbers.renderType; } else if (previousProperties) { diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index f96fcd3b787..94e8258b4c1 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -708,7 +708,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { } } - screenReaderMode = (editorWidget.getConfiguration().accessibilitySupport === AccessibilitySupport.Enabled); + screenReaderMode = (editorWidget.getOption(EditorOptionId.accessibilitySupport) === AccessibilitySupport.Enabled); } if (screenReaderMode === false && this.screenReaderNotification) { @@ -758,7 +758,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { private onEOLChange(editorWidget: ICodeEditor | undefined): void { const info: StateDelta = { EOL: undefined }; - if (editorWidget && !editorWidget.getConfiguration().readOnly) { + if (editorWidget && !editorWidget.getOption(EditorOptionId.readOnly)) { const codeEditorModel = editorWidget.getModel(); if (codeEditorModel) { info.EOL = codeEditorModel.getEOL(); @@ -819,8 +819,7 @@ function isWritableCodeEditor(codeEditor: ICodeEditor | undefined): boolean { if (!codeEditor) { return false; } - const config = codeEditor.getConfiguration(); - return (!config.readOnly); + return !codeEditor.getOption(EditorOptionId.readOnly); } function isWritableBaseEditor(e: IBaseEditor): boolean { diff --git a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts index a45ab650031..4f84e1dc2b4 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts @@ -17,7 +17,7 @@ import * as strings from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { EditorAction, EditorCommand, registerEditorAction, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ToggleTabFocusModeAction } from 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode'; @@ -185,13 +185,13 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { } private _buildContent() { - let opts = this._editor.getConfiguration(); + const options = this._editor.getOptions(); let text = nls.localize('introMsg', "Thank you for trying out VS Code's accessibility options."); text += '\n\n' + nls.localize('status', "Status:"); - const configuredValue = this._configurationService.getValue('editor').accessibilitySupport; - const actualValue = opts.accessibilitySupport; + const configuredValue = this._configurationService.getValue('editor').accessibilitySupport; + const actualValue = options.get(EditorOptionId.accessibilitySupport); const emergencyTurnOnMessage = ( platform.isMacintosh @@ -229,7 +229,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { const NLS_TAB_FOCUS_MODE_OFF = nls.localize('tabFocusModeOffMsg', "Pressing Tab in the current editor will insert the tab character. Toggle this behavior by pressing {0}."); const NLS_TAB_FOCUS_MODE_OFF_NO_KB = nls.localize('tabFocusModeOffMsgNoKb', "Pressing Tab in the current editor will insert the tab character. The command {0} is currently not triggerable by a keybinding."); - if (opts.tabFocusMode) { + if (options.get(EditorOptionId.tabFocusMode)) { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, NLS_TAB_FOCUS_MODE_ON, NLS_TAB_FOCUS_MODE_ON_NO_KB); } else { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, NLS_TAB_FOCUS_MODE_OFF, NLS_TAB_FOCUS_MODE_OFF_NO_KB); diff --git a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts index 18aa8e4965e..da10b808d17 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts @@ -9,7 +9,7 @@ import * as process from 'vs/base/common/process'; import * as platform from 'vs/base/common/platform'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; @@ -24,11 +24,11 @@ export class SelectionClipboard extends Disposable implements IEditorContributio super(); if (platform.isLinux) { - let isEnabled = editor.getOption(EditorOptionId.selectionClipboard); + let isEnabled = editor.getOption(EditorOptionId.selectionClipboard); this._register(editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { if (e.hasChanged(EditorOptionId.selectionClipboard)) { - isEnabled = editor.getOption(EditorOptionId.selectionClipboard); + isEnabled = editor.getOption(EditorOptionId.selectionClipboard); } })); diff --git a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts index e8472a05fe6..8d22a06dcba 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts @@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { ITextModel } from 'vs/editor/common/model'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; @@ -85,7 +85,7 @@ function toggleWordWrap(editor: ICodeEditor, state: IWordWrapState): IWordWrapSt let transientState: IWordWrapTransientState; - const actualWrappingInfo = editor.getOption(EditorOptionId.wrappingInfo); + const actualWrappingInfo = editor.getOption(EditorOptionId.wrappingInfo); if (actualWrappingInfo.isWordWrapMinified) { // => wrapping due to minified file transientState = { @@ -138,7 +138,7 @@ class ToggleWordWrapAction extends EditorAction { if (!editor.hasModel()) { return; } - if (editor.getOption(EditorOptionId.inDiffEditor)) { + if (editor.getOption(EditorOptionId.inDiffEditor)) { // Cannot change wrapping settings inside the diff editor const notificationService = accessor.get(INotificationService); notificationService.info(nls.localize('wordWrap.notInDiffEditor', "Cannot toggle word wrap in a diff editor.")); @@ -176,10 +176,10 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution super(); const options = this.editor.getOptions(); - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); const isWordWrapMinified = this.contextKeyService.createKey(isWordWrapMinifiedKey, wrappingInfo.isWordWrapMinified); const isDominatedByLongLines = this.contextKeyService.createKey(isDominatedByLongLinesKey, wrappingInfo.isDominatedByLongLines); - const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, options.get(EditorOptionId.inDiffEditor)); + const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, options.get(EditorOptionId.inDiffEditor)); let currentlyApplyingEditorConfig = false; this._register(editor.onDidChangeConfiguration((e) => { @@ -187,10 +187,10 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution return; } const options = this.editor.getOptions(); - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOptionId.wrappingInfo); isWordWrapMinified.set(wrappingInfo.isWordWrapMinified); isDominatedByLongLines.set(wrappingInfo.isDominatedByLongLines); - inDiffEditor.set(options.get(EditorOptionId.inDiffEditor)); + inDiffEditor.set(options.get(EditorOptionId.inDiffEditor)); if (!currentlyApplyingEditorConfig) { // I am not the cause of the word wrap getting changed ensureWordWrapSettings(); @@ -216,7 +216,7 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution return; } - if (this.editor.getOption(EditorOptionId.inDiffEditor)) { + if (this.editor.getOption(EditorOptionId.inDiffEditor)) { return; } diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index 94a1a359481..52068f454fc 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -37,7 +37,7 @@ import { COMMENTEDITOR_DECORATION_KEY, ReviewZoneWidget } from 'vs/workbench/con import { ctxCommentEditorFocused, SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export const ID = 'editor.contrib.review'; @@ -603,7 +603,7 @@ export class ReviewController implements IEditorContribution { } const options = this.editor.getOptions(); - if (options.get(EditorOptionId.folding)) { + if (options.get(EditorOptionId.folding)) { lineDecorationsWidth -= 16; } lineDecorationsWidth += 9; diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts index 2074a14ab74..d0d7906907c 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts @@ -41,7 +41,7 @@ import { ContextSubMenu } from 'vs/base/browser/contextmenu'; import { memoize } from 'vs/base/common/decorators'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { getHover } from 'vs/editor/contrib/hover/getHover'; -import { IEditorHoverOptions } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { CancellationToken } from 'vs/base/common/cancellation'; import { BreakpointWidget } from 'vs/workbench/contrib/debug/browser/breakpointWidget'; import { DebugHoverWidget } from 'vs/workbench/contrib/debug/browser/debugHover'; @@ -540,7 +540,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { if (this.configurationWidget) { this.configurationWidget.dispose(); } - if (model && LAUNCH_JSON_REGEX.test(model.uri.toString()) && !this.editor.getConfiguration().readOnly) { + if (model && LAUNCH_JSON_REGEX.test(model.uri.toString()) && !this.editor.getOption(EditorOptionId.readOnly)) { this.configurationWidget = this.instantiationService.createInstance(FloatingClickWidget, this.editor, nls.localize('addConfiguration', "Add Configuration..."), null); this.configurationWidget.render(); this.toDispose.push(this.configurationWidget.onClick(() => this.addLaunchConfiguration())); diff --git a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts index d9b7e38db91..f3e4b3ca255 100644 --- a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts @@ -30,6 +30,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { KeybindingParser } from 'vs/base/common/keybindingParser'; import Severity from 'vs/base/common/severity'; import { SeverityIcon } from 'vs/platform/severityIcon/common/severityIcon'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; const NLS_LAUNCH_MESSAGE = nls.localize('defineKeybinding.start', "Define Keybinding"); const NLS_KB_LAYOUT_ERROR_MESSAGE = nls.localize('defineKeybinding.kbLayoutErrorMessage', "You won't be able to produce this key combination under your current keyboard layout."); @@ -82,7 +83,7 @@ export class DefineKeybindingController extends Disposable implements editorComm this._createKeybindingDecorationRenderer(); // The button to define keybindings is shown only for the user keybindings.json - if (!this._editor.getConfiguration().readOnly) { + if (!this._editor.getOption(EditorOptionId.readOnly)) { this._createKeybindingWidgetRenderer(); } else { this._disposeKeybindingWidgetRenderer(); @@ -377,7 +378,7 @@ class DefineKeybindingCommand extends EditorCommand { } runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void { - if (!isInterestingEditorModel(editor) || editor.getConfiguration().readOnly) { + if (!isInterestingEditorModel(editor) || editor.getOption(EditorOptionId.readOnly)) { return; } const controller = DefineKeybindingController.get(editor); diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts index 6b738378609..6f4eb6a5551 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts @@ -33,7 +33,7 @@ import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/p import { PANEL_ACTIVE_TITLE_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND } from 'vs/workbench/common/theme'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { ISettingsGroup } from 'vs/workbench/services/preferences/common/preferences'; -import { EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; export class SettingsHeaderWidget extends Widget implements IViewZone { @@ -88,7 +88,7 @@ export class SettingsHeaderWidget extends Widget implements IViewZone { const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; - if (!options.get(EditorOptionId.folding)) { + if (!options.get(EditorOptionId.folding)) { this.titleContainer.style.paddingLeft = '6px'; } } diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts index eaafa00f21b..418aafc0130 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts @@ -16,7 +16,7 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IRange } from 'vs/editor/common/core/range'; import { overviewRulerRangeHighlight } from 'vs/editor/common/view/editorColorRegistry'; import { themeColorFromId } from 'vs/platform/theme/common/themeService'; -import { IEditorOptions, RenderLineNumbersType, EditorOption, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -51,7 +51,7 @@ export class GotoLineAction extends QuickOpenAction { if (isCodeEditor(activeTextEditorWidget)) { const options = activeTextEditorWidget.getOptions(); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); if (renderLineNumbers.renderType === RenderLineNumbersType.Relative) { activeTextEditorWidget.updateOptions({ lineNumbers: 'on' diff --git a/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts b/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts index fff264d6463..4571d5e6ef8 100644 --- a/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts +++ b/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts @@ -23,6 +23,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ILabelService } from 'vs/platform/label/common/label'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; abstract class Recording { @@ -414,7 +415,7 @@ export class BulkEditService implements IBulkEditService { } } - if (codeEditor && codeEditor.getConfiguration().readOnly) { + if (codeEditor && codeEditor.getOption(EditorOptionId.readOnly)) { // If the code editor is readonly still allow bulk edits to be applied #68549 codeEditor = undefined; } From 16c1772bdf3092c5d41225725c65e566ea8bfd6d Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 3 Sep 2019 00:22:23 +0200 Subject: [PATCH 007/109] renames --- .../editor/browser/controller/mouseHandler.ts | 6 +- .../editor/browser/controller/mouseTarget.ts | 6 +- .../browser/controller/textAreaHandler.ts | 20 +-- src/vs/editor/browser/editorBrowser.ts | 4 +- src/vs/editor/browser/view/viewImpl.ts | 6 +- src/vs/editor/browser/view/viewLayer.ts | 4 +- src/vs/editor/browser/view/viewOverlays.ts | 14 +- .../contentWidgets/contentWidgets.ts | 8 +- .../currentLineHighlight.ts | 8 +- .../currentLineMarginHighlight.ts | 8 +- .../editorScrollbar/editorScrollbar.ts | 26 +-- .../viewParts/glyphMargin/glyphMargin.ts | 8 +- .../viewParts/indentGuides/indentGuides.ts | 8 +- .../viewParts/lineNumbers/lineNumbers.ts | 8 +- .../browser/viewParts/lines/viewLines.ts | 12 +- .../linesDecorations/linesDecorations.ts | 8 +- .../editor/browser/viewParts/margin/margin.ts | 8 +- .../browser/viewParts/minimap/minimap.ts | 6 +- .../overlayWidgets/overlayWidgets.ts | 8 +- .../overviewRuler/decorationsOverviewRuler.ts | 6 +- .../editor/browser/viewParts/rulers/rulers.ts | 4 +- .../scrollDecoration/scrollDecoration.ts | 12 +- .../viewParts/viewCursors/viewCursors.ts | 8 +- .../browser/viewParts/viewZones/viewZones.ts | 8 +- .../editor/browser/widget/codeEditorWidget.ts | 22 +-- .../editor/browser/widget/diffEditorWidget.ts | 4 +- src/vs/editor/browser/widget/diffReview.ts | 4 +- .../editor/browser/widget/inlineDiffMargin.ts | 4 +- .../common/config/commonEditorConfig.ts | 28 ++-- src/vs/editor/common/config/editorOptions.ts | 158 +++++++++--------- src/vs/editor/common/controller/cursor.ts | 4 +- .../editor/common/controller/cursorCommon.ts | 10 +- .../common/standalone/standaloneEnums.ts | 2 +- src/vs/editor/common/view/viewEvents.ts | 4 +- src/vs/editor/common/viewLayout/viewLayout.ts | 12 +- .../common/viewModel/viewModelDecorations.ts | 4 +- .../editor/common/viewModel/viewModelImpl.ts | 20 +-- .../contrib/codeAction/codeActionModel.ts | 4 +- src/vs/editor/contrib/find/findController.ts | 4 +- src/vs/editor/contrib/find/findWidget.ts | 16 +- src/vs/editor/contrib/folding/folding.ts | 8 +- src/vs/editor/contrib/hover/hover.ts | 4 +- src/vs/editor/contrib/suggest/suggestModel.ts | 4 +- .../accessibilityHelp/accessibilityHelp.ts | 12 +- .../iPadShowKeyboard/iPadShowKeyboard.ts | 4 +- .../standalone/browser/standaloneEditor.ts | 4 +- .../common/config/commonEditorConfig.test.ts | 4 +- .../viewModel/splitLinesCollection.test.ts | 22 +-- src/vs/monaco.d.ts | 78 ++++----- .../workbench/api/browser/mainThreadEditor.ts | 4 +- .../browser/parts/editor/editorStatus.ts | 10 +- .../browser/accessibility/accessibility.ts | 6 +- .../codeEditor/browser/selectionClipboard.ts | 8 +- .../codeEditor/browser/toggleWordWrap.ts | 20 +-- .../browser/commentsEditorContribution.ts | 4 +- .../debug/browser/debugEditorContribution.ts | 4 +- .../browser/keybindingsEditorContribution.ts | 6 +- .../preferences/browser/preferencesWidgets.ts | 4 +- .../quickopen/browser/gotoLineHandler.ts | 4 +- .../bulkEdit/browser/bulkEditService.ts | 4 +- 60 files changed, 364 insertions(+), 364 deletions(-) diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index a28b811da24..f9b2f538465 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -21,7 +21,7 @@ import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; /** @@ -218,7 +218,7 @@ export class MouseHandler extends ViewEventHandler { const targetIsContent = (t.type === editorBrowser.MouseTargetType.CONTENT_TEXT || t.type === editorBrowser.MouseTargetType.CONTENT_EMPTY); const targetIsGutter = (t.type === editorBrowser.MouseTargetType.GUTTER_GLYPH_MARGIN || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_DECORATIONS); const targetIsLineNumbers = (t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS); - const selectOnLineNumbers = this._context.configuration.options.get(EditorOptionId.selectOnLineNumbers); + const selectOnLineNumbers = this._context.configuration.options.get(EditorOption.selectOnLineNumbers); const targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE); const targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET); @@ -354,7 +354,7 @@ class MouseDownOperation extends Disposable { e.detail = this._mouseState.count; const options = this._context.configuration.options; - const readOnly = options.get(EditorOptionId.readOnly); + const readOnly = options.get(EditorOption.readOnly); if (!readOnly && this._context.configuration.editor.dragAndDrop diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index cde6cad5f2d..1db7f2849a4 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -10,7 +10,7 @@ import { ClientCoordinates, EditorMouseEvent, EditorPagePosition, PageCoordinate import { PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart'; import { ViewLine } from 'vs/editor/browser/viewParts/lines/viewLine'; import { IViewCursorRenderData } from 'vs/editor/browser/viewParts/viewCursors/viewCursor'; -import { EditorLayoutInfo, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorLayoutInfo, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range as EditorRange } from 'vs/editor/common/core/range'; import { HorizontalRange } from 'vs/editor/common/view/renderingContext'; @@ -240,7 +240,7 @@ export class HitTestContext { constructor(context: ViewContext, viewHelper: IPointerHandlerHelper, lastViewCursorsRenderData: IViewCursorRenderData[]) { this.model = context.model; const options = context.configuration.options; - this.layoutInfo = options.get(EditorOptionId.layoutInfo); + this.layoutInfo = options.get(EditorOption.layoutInfo); this.viewDomNode = viewHelper.viewDomNode; this.lineHeight = context.configuration.editor.lineHeight; this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; @@ -715,7 +715,7 @@ export class MouseTargetFactory { public getMouseColumn(editorPos: EditorPagePosition, pos: PageCoordinates): number { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + pos.x - editorPos.x - layoutInfo.contentLeft; return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index c02aaef8ecd..347cd523a81 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -16,7 +16,7 @@ import { ViewController } from 'vs/editor/browser/view/viewController'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers'; import { Margin } from 'vs/editor/browser/viewParts/margin/margin'; -import { RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOption } from 'vs/editor/common/config/editorOptions'; import { BareFontInfo } from 'vs/editor/common/config/fontInfo'; import { WordCharacterClass, getMapForWordSeparators } from 'vs/editor/common/controller/wordCharacterClassifier'; import { Position } from 'vs/editor/common/core/position'; @@ -120,9 +120,9 @@ export class TextAreaHandler extends ViewPart { const conf = this._context.configuration.editor; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); - this._accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + this._accessibilitySupport = options.get(EditorOption.accessibilitySupport); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; @@ -145,7 +145,7 @@ export class TextAreaHandler extends ViewPart { this.textArea.setAttribute('autocapitalize', 'off'); this.textArea.setAttribute('autocomplete', 'off'); this.textArea.setAttribute('spellcheck', 'false'); - this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); + this.textArea.setAttribute('aria-label', options.get(EditorOption.ariaLabel)); this.textArea.setAttribute('role', 'textbox'); this.textArea.setAttribute('aria-multiline', 'true'); this.textArea.setAttribute('aria-haspopup', 'false'); @@ -379,10 +379,10 @@ export class TextAreaHandler extends ViewPart { this._fontInfo = conf.fontInfo; } if (e.viewInfo) { - this.textArea.setAttribute('aria-label', options.get(EditorOptionId.ariaLabel)); + this.textArea.setAttribute('aria-label', options.get(EditorOption.ariaLabel)); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; @@ -390,8 +390,8 @@ export class TextAreaHandler extends ViewPart { if (e.lineHeight) { this._lineHeight = conf.lineHeight; } - if (e.hasChanged(EditorOptionId.accessibilitySupport)) { - this._accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + if (e.hasChanged(EditorOption.accessibilitySupport)) { + this._accessibilitySupport = options.get(EditorOption.accessibilitySupport); this._textAreaInput.writeScreenReaderContent('strategy changed'); } if (e.emptySelectionClipboard) { @@ -553,7 +553,7 @@ export class TextAreaHandler extends ViewPart { if (this._context.configuration.editor.viewInfo.glyphMargin) { tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME); } else { - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOption.renderLineNumbers); if (renderLineNumbers.renderType !== RenderLineNumbersType.Off) { tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME); } else { diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index 5e94f07990b..c8f7a8ee5ca 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -6,7 +6,7 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IMouseEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { OverviewRulerPosition, IConfigurationChangedEvent, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOptionId, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { OverviewRulerPosition, IConfigurationChangedEvent, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { IPosition, Position } from 'vs/editor/common/core/position'; @@ -538,7 +538,7 @@ export interface ICodeEditor extends editorCommon.IEditor { getOptions(): IComputedEditorOptions; - getOption(id: T): FindComputedEditorOptionValueById; + getOption(id: T): FindComputedEditorOptionValueById; /** * Returns the 'raw' editor's configuration (without any validation or defaults). * @internal diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 41a04db7b4a..2a31441bc86 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -48,7 +48,7 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData' import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IThemeService, getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IContentWidgetData { @@ -284,7 +284,7 @@ export class View extends ViewEventHandler { private _setLayout(): void { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this.domNode.setWidth(layoutInfo.width); this.domNode.setHeight(layoutInfo.height); @@ -307,7 +307,7 @@ export class View extends ViewEventHandler { if (e.editorClassName) { this.domNode.setClassName(this.getEditorClassName()); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { this._setLayout(); } return false; diff --git a/src/vs/editor/browser/view/viewLayer.ts b/src/vs/editor/browser/view/viewLayer.ts index c5624ce9c83..eec48240c90 100644 --- a/src/vs/editor/browser/view/viewLayer.ts +++ b/src/vs/editor/browser/view/viewLayer.ts @@ -7,7 +7,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; /** * Represents a visible line @@ -270,7 +270,7 @@ export class VisibleLinesCollection { // ---- begin view event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { return true; } return false; diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index 5e0015eb0a9..bf7fed99d46 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -14,7 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class ViewOverlays extends ViewPart implements IVisibleLinesHost { @@ -218,7 +218,7 @@ export class ContentViewOverlays extends ViewOverlays { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentWidth = layoutInfo.contentWidth; this.domNode.setHeight(0); @@ -227,9 +227,9 @@ export class ContentViewOverlays extends ViewOverlays { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentWidth = layoutInfo.contentWidth; } return super.onConfigurationChanged(e); @@ -255,7 +255,7 @@ export class MarginViewOverlays extends ViewOverlays { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this.domNode.setClassName('margin-view-overlays'); @@ -270,9 +270,9 @@ export class MarginViewOverlays extends ViewOverlays { Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); shouldRender = true; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; shouldRender = true; } diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index 6975b25a6bc..74ca7cbd66a 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -14,7 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class Coordinate { @@ -210,7 +210,7 @@ class Widget { this.suppressMouseDown = this._actual.suppressMouseDown || false; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._fixedOverflowWidgets = this._context.configuration.editor.viewInfo.fixedOverflowWidgets; this._contentWidth = layoutInfo.contentWidth; @@ -238,9 +238,9 @@ class Widget { if (e.lineHeight) { this._lineHeight = this._context.configuration.editor.lineHeight; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._maxWidth = this._getMaxWidth(); diff --git a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts index 63aa1334022..41cb1c2080c 100644 --- a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts @@ -10,7 +10,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class CurrentLineHighlightOverlay extends DynamicViewOverlay { @@ -26,7 +26,7 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; @@ -54,9 +54,9 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { if (e.viewInfo) { this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentWidth = layoutInfo.contentWidth; } return true; diff --git a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts index 3601770f5b8..e6d01e2ebcf 100644 --- a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts @@ -10,7 +10,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { @@ -25,7 +25,7 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; @@ -50,9 +50,9 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { if (e.viewInfo) { this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; } return true; diff --git a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts index df5316bfb80..d816f1265e8 100644 --- a/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts +++ b/src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts @@ -14,7 +14,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { getThemeTypeSelector } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class EditorScrollbar extends ViewPart { @@ -31,9 +31,9 @@ export class EditorScrollbar extends ViewPart { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); - const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); - const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); + const scrollbar = options.get(EditorOption.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity); const scrollbarOptions: ScrollableElementCreationOptions = { listenOnDomNode: viewDomNode.domNode, @@ -101,11 +101,11 @@ export class EditorScrollbar extends ViewPart { private _setLayout(): void { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this.scrollbarDomNode.setLeft(layoutInfo.contentLeft); - const minimap = options.get(EditorOptionId.minimap); + const minimap = options.get(EditorOption.minimap); const side = minimap.side; if (side === 'right') { this.scrollbarDomNode.setWidth(layoutInfo.contentWidth + layoutInfo.minimapWidth); @@ -131,14 +131,14 @@ export class EditorScrollbar extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { if ( - e.hasChanged(EditorOptionId.scrollbar) - || e.hasChanged(EditorOptionId.mouseWheelScrollSensitivity) - || e.hasChanged(EditorOptionId.fastScrollSensitivity) + e.hasChanged(EditorOption.scrollbar) + || e.hasChanged(EditorOption.mouseWheelScrollSensitivity) + || e.hasChanged(EditorOption.fastScrollSensitivity) ) { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); - const mouseWheelScrollSensitivity = options.get(EditorOptionId.mouseWheelScrollSensitivity); - const fastScrollSensitivity = options.get(EditorOptionId.fastScrollSensitivity); + const scrollbar = options.get(EditorOption.scrollbar); + const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity); + const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity); const newOpts: ScrollableElementChangeOptions = { handleMouseWheel: scrollbar.handleMouseWheel, mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, @@ -146,7 +146,7 @@ export class EditorScrollbar extends ViewPart { }; this.scrollbar.updateOptions(newOpts); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { this._setLayout(); } return true; diff --git a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts index 516cdb1f468..a402d430826 100644 --- a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts +++ b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts @@ -8,7 +8,7 @@ import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class DecorationToRender { @@ -87,7 +87,7 @@ export class GlyphMarginOverlay extends DedupOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; this._glyphMarginLeft = layoutInfo.glyphMarginLeft; @@ -113,8 +113,8 @@ export class GlyphMarginOverlay extends DedupOverlay { if (e.viewInfo) { this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; } diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index 9da6446edf9..fb275d96ba3 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -11,7 +11,7 @@ import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class IndentGuidesOverlay extends DynamicViewOverlay { @@ -34,7 +34,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); @@ -63,8 +63,8 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; } - if (e.hasChanged(EditorOptionId.wrappingInfo) || e.fontInfo) { - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + if (e.hasChanged(EditorOption.wrappingInfo) || e.fontInfo) { + const wrappingInfo = options.get(EditorOption.wrappingInfo); const wrappingColumn = wrappingInfo.wrappingColumn; this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); } diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index aa078b1b834..8673e31f153 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -6,7 +6,7 @@ import 'vs/css!./lineNumbers'; import * as platform from 'vs/base/common/platform'; import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay'; -import { RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { editorActiveLineNumber, editorLineNumbers } from 'vs/editor/common/view/editorColorRegistry'; import { RenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -44,11 +44,11 @@ export class LineNumbersOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const config = this._context.configuration.editor; this._lineHeight = config.lineHeight; - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOption.renderLineNumbers); this._renderLineNumbers = renderLineNumbers.renderType; this._renderCustomLineNumbers = renderLineNumbers.renderFn; - this._renderFinalNewline = options.get(EditorOptionId.renderFinalNewline); - const layoutInfo = options.get(EditorOptionId.layoutInfo); + this._renderFinalNewline = options.get(EditorOption.renderFinalNewline); + const layoutInfo = options.get(EditorOption.layoutInfo); this._lineNumbersLeft = layoutInfo.lineNumbersLeft; this._lineNumbersWidth = layoutInfo.lineNumbersWidth; } diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 80c851b0084..7fff4453ba5 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -18,7 +18,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { Viewport } from 'vs/editor/common/viewModel/viewModel'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class LastRenderedData { @@ -92,7 +92,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const conf = this._context.configuration; const options = this._context.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); this._lineHeight = conf.editor.lineHeight; this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; @@ -138,7 +138,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { this._visibleLines.onConfigurationChanged(e); - if (e.hasChanged(EditorOptionId.wrappingInfo)) { + if (e.hasChanged(EditorOption.wrappingInfo)) { this._maxLineWidth = 0; } @@ -151,8 +151,8 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, if (e.fontInfo) { this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; } - if (e.hasChanged(EditorOptionId.wrappingInfo)) { - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + if (e.hasChanged(EditorOption.wrappingInfo)) { + const wrappingInfo = options.get(EditorOption.wrappingInfo); this._isViewportWrapping = wrappingInfo.isViewportWrapping; } if (e.viewInfo) { @@ -168,7 +168,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this._onOptionsMaybeChanged(); - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { this._maxLineWidth = 0; } diff --git a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts index 4beec4716a1..c8ad48eb26f 100644 --- a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts +++ b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts @@ -8,7 +8,7 @@ import { DecorationToRender, DedupOverlay } from 'vs/editor/browser/viewParts/gl import { RenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class LinesDecorationsOverlay extends DedupOverlay { @@ -23,7 +23,7 @@ export class LinesDecorationsOverlay extends DedupOverlay { super(); this._context = context; const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._decorationsLeft = layoutInfo.decorationsLeft; this._decorationsWidth = layoutInfo.decorationsWidth; this._renderResult = null; @@ -40,8 +40,8 @@ export class LinesDecorationsOverlay extends DedupOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._decorationsLeft = layoutInfo.decorationsLeft; this._decorationsWidth = layoutInfo.decorationsWidth; } diff --git a/src/vs/editor/browser/viewParts/margin/margin.ts b/src/vs/editor/browser/viewParts/margin/margin.ts index 79cc1b4f500..2710a194dd0 100644 --- a/src/vs/editor/browser/viewParts/margin/margin.ts +++ b/src/vs/editor/browser/viewParts/margin/margin.ts @@ -8,7 +8,7 @@ import { ViewPart } from 'vs/editor/browser/view/viewPart'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class Margin extends ViewPart { @@ -26,7 +26,7 @@ export class Margin extends ViewPart { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; this._contentLeft = layoutInfo.contentLeft; @@ -62,8 +62,8 @@ export class Margin extends ViewPart { this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index ce8218c915f..7df0b183c3c 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -13,7 +13,7 @@ import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ILine, RenderedLinesCollection } from 'vs/editor/browser/view/viewLayer'; import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart'; -import { RenderMinimap, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderMinimap, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { RGBA8 } from 'vs/editor/common/core/rgba'; import { IConfiguration, ScrollType } from 'vs/editor/common/editorCommon'; @@ -109,13 +109,13 @@ class MinimapOptions { constructor(configuration: IConfiguration) { const options = configuration.options; const pixelRatio = configuration.editor.pixelRatio; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); const viewInfo = configuration.editor.viewInfo; const fontInfo = configuration.editor.fontInfo; this.renderMinimap = layoutInfo.renderMinimap | 0; this.scrollBeyondLastLine = viewInfo.scrollBeyondLastLine; - const minimapOpts = options.get(EditorOptionId.minimap); + const minimapOpts = options.get(EditorOption.minimap); this.showSlider = minimapOpts.showSlider; this.pixelRatio = pixelRatio; this.typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; diff --git a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts index 2d138034568..ba9128c06de 100644 --- a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts +++ b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts @@ -10,7 +10,7 @@ import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/v import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; interface IWidgetData { @@ -38,7 +38,7 @@ export class ViewOverlayWidgets extends ViewPart { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._widgets = {}; this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; @@ -66,8 +66,8 @@ export class ViewOverlayWidgets extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; this._minimapWidth = layoutInfo.minimapWidth; this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; diff --git a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts index 463a4592c27..2f02db4df43 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts @@ -15,7 +15,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ITheme } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class Settings { @@ -58,7 +58,7 @@ class Settings { this.themeType = theme.type; - const minimapOpts = options.get(EditorOptionId.minimap); + const minimapOpts = options.get(EditorOption.minimap); const minimapEnabled = minimapOpts.enabled; const minimapSide = minimapOpts.side; const backgroundColor = (minimapEnabled ? TokenizationRegistry.getDefaultBackground() : null); @@ -68,7 +68,7 @@ class Settings { this.backgroundColor = Color.Format.CSS.formatHex(backgroundColor); } - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); const position = layoutInfo.overviewRuler; this.top = position.top; this.right = position.right; diff --git a/src/vs/editor/browser/viewParts/rulers/rulers.ts b/src/vs/editor/browser/viewParts/rulers/rulers.ts index ceb396185fd..21981080a0e 100644 --- a/src/vs/editor/browser/viewParts/rulers/rulers.ts +++ b/src/vs/editor/browser/viewParts/rulers/rulers.ts @@ -11,7 +11,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class Rulers extends ViewPart { @@ -39,7 +39,7 @@ export class Rulers extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { if (e.viewInfo - || e.hasChanged(EditorOptionId.layoutInfo) + || e.hasChanged(EditorOption.layoutInfo) || e.fontInfo ) { this._rulers = this._context.configuration.editor.viewInfo.rulers; diff --git a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts index 8a482e56031..7e516f8e221 100644 --- a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts +++ b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts @@ -11,7 +11,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { scrollbarShadow } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class ScrollDecorationViewPart extends ViewPart { @@ -30,7 +30,7 @@ export class ScrollDecorationViewPart extends ViewPart { this._updateWidth(); this._shouldShow = false; const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOption.scrollbar); this._useShadows = scrollbar.useShadows; this._domNode = createFastDomNode(document.createElement('div')); this._domNode.setAttribute('role', 'presentation'); @@ -56,7 +56,7 @@ export class ScrollDecorationViewPart extends ViewPart { private _updateWidth(): boolean { const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); let newWidth = 0; if (layoutInfo.renderMinimap === 0 || (layoutInfo.minimapWidth > 0 && layoutInfo.minimapLeft === 0)) { newWidth = layoutInfo.width; @@ -74,12 +74,12 @@ export class ScrollDecorationViewPart extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { let shouldRender = false; - if (e.hasChanged(EditorOptionId.scrollbar)) { + if (e.hasChanged(EditorOption.scrollbar)) { const options = this._context.configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOption.scrollbar); this._useShadows = scrollbar.useShadows; } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { shouldRender = this._updateWidth(); } return this._updateShouldShow() || shouldRender; diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts index ede284d3543..f9dc4932f76 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts @@ -8,7 +8,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import { IntervalTimer, TimeoutTimer } from 'vs/base/common/async'; import { ViewPart } from 'vs/editor/browser/view/viewPart'; import { IViewCursorRenderData, ViewCursor } from 'vs/editor/browser/viewParts/viewCursors/viewCursor'; -import { TextEditorCursorBlinkingStyle, TextEditorCursorStyle, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { TextEditorCursorBlinkingStyle, TextEditorCursorStyle, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { editorCursorBackground, editorCursorForeground } from 'vs/editor/common/view/editorColorRegistry'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -44,7 +44,7 @@ export class ViewCursors extends ViewPart { super(context); const options = this._context.configuration.options; - this._readOnly = options.get(EditorOptionId.readOnly); + this._readOnly = options.get(EditorOption.readOnly); this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; this._cursorSmoothCaretAnimation = this._context.configuration.editor.viewInfo.cursorSmoothCaretAnimation; @@ -87,8 +87,8 @@ export class ViewCursors extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.hasChanged(EditorOptionId.readOnly)) { - this._readOnly = options.get(EditorOptionId.readOnly); + if (e.hasChanged(EditorOption.readOnly)) { + this._readOnly = options.get(EditorOption.readOnly); } if (e.viewInfo) { this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; diff --git a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts index 13bf932d19b..ed6976ba9fa 100644 --- a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts +++ b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts @@ -12,7 +12,7 @@ import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/v import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { IViewWhitespaceViewportData } from 'vs/editor/common/viewModel/viewModel'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IMyViewZone { @@ -43,7 +43,7 @@ export class ViewZones extends ViewPart { constructor(context: ViewContext) { super(context); const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; this._contentWidth = layoutInfo.contentWidth; @@ -96,8 +96,8 @@ export class ViewZones extends ViewPart { return this._recomputeWhitespacesProps(); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { - const layoutInfo = options.get(EditorOptionId.layoutInfo); + if (e.hasChanged(EditorOption.layoutInfo)) { + const layoutInfo = options.get(EditorOption.layoutInfo); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index d0cdffa1ca2..cdc154e5521 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -23,7 +23,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService import { ICommandDelegate } from 'vs/editor/browser/view/viewController'; import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl'; import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents'; -import { IConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOptionId, InternalEditorOptions, IComputedEditorOptions, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, InternalEditorOptions, IComputedEditorOptions, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor'; import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; @@ -259,9 +259,9 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._register(this._configuration.onDidChange((e) => { this._onDidChangeConfiguration.fire(e); - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._onDidLayoutChange.fire(layoutInfo); } if (this._configuration.editor.showUnused) { @@ -376,7 +376,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE return this._configuration.options; } - public getOption(id: T): FindComputedEditorOptionValueById { + public getOption(id: T): FindComputedEditorOptionValueById { return this._configuration.options.get(id); } @@ -982,7 +982,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return false; } - if (this._configuration.options.get(EditorOptionId.readOnly)) { + if (this._configuration.options.get(EditorOption.readOnly)) { // read only editor => sorry! return false; } @@ -994,7 +994,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return false; } - if (this._configuration.options.get(EditorOptionId.readOnly)) { + if (this._configuration.options.get(EditorOption.readOnly)) { // read only editor => sorry! return false; } @@ -1038,7 +1038,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE if (!this._modelData) { return null; } - return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.options.get(EditorOptionId.readOnly)); + return this._modelData.model.getLineDecorations(lineNumber, this._id, this._configuration.options.get(EditorOption.readOnly)); } public deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[] { @@ -1131,7 +1131,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE public getLayoutInfo(): EditorLayoutInfo { const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); return layoutInfo; } @@ -1281,7 +1281,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE const position = this._modelData.model.validatePosition(rawPosition); const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); const top = CodeEditorWidget._getVerticalOffsetForPosition(this._modelData, position.lineNumber, position.column) - this.getScrollTop(); const left = this._modelData.view.getOffsetForColumn(position.lineNumber, position.column) + layoutInfo.glyphMarginWidth + layoutInfo.lineNumbersWidth + layoutInfo.decorationsWidth - this.getScrollLeft(); @@ -1616,8 +1616,8 @@ class EditorContextKeysManager extends Disposable { private _updateFromConfig(): void { const options = this._editor.getOptions(); - this._editorTabMovesFocus.set(options.get(EditorOptionId.tabFocusMode)); - this._editorReadonly.set(options.get(EditorOptionId.readOnly)); + this._editorTabMovesFocus.set(options.get(EditorOption.tabFocusMode)); + this._editorReadonly.set(options.get(EditorOption.readOnly)); } private _updateFromSelection(): void { diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index d2ba7bd565d..c07f9ec9552 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -20,7 +20,7 @@ import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffReview } from 'vs/editor/browser/widget/diffReview'; -import { IDiffEditorOptions, IEditorOptions, EDITOR_DEFAULTS, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IDiffEditorOptions, IEditorOptions, EDITOR_DEFAULTS, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -1995,7 +1995,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { let sb = createStringBuilder(10000); let marginHTML: string[] = []; - const layoutInfo = this.modifiedEditorOptions.get(EditorOptionId.layoutInfo); + const layoutInfo = this.modifiedEditorOptions.get(EditorOption.layoutInfo); const lineDecorationsWidth = layoutInfo.decorationsWidth; let lineHeight = this.modifiedEditorConfiguration.lineHeight; diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index 8c51ecede42..63eba820ab8 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -667,10 +667,10 @@ export class DiffReview extends Disposable { originalLineEnd - originalLineStart ); - const originalLayoutInfo = originalOptions.get(editorOptions.EditorOptionId.layoutInfo); + const originalLayoutInfo = originalOptions.get(editorOptions.EditorOption.layoutInfo); const originalLineNumbersWidth = originalLayoutInfo.glyphMarginWidth + originalLayoutInfo.lineNumbersWidth; - const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOptionId.layoutInfo); + const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOption.layoutInfo); const modifiedLineNumbersWidth = 10 + modifiedLayoutInfo.glyphMarginWidth + modifiedLayoutInfo.lineNumbersWidth; for (let i = 0; i <= cnt; i++) { diff --git a/src/vs/editor/browser/widget/inlineDiffMargin.ts b/src/vs/editor/browser/widget/inlineDiffMargin.ts index afc6287dc02..a55022c8b52 100644 --- a/src/vs/editor/browser/widget/inlineDiffMargin.ts +++ b/src/vs/editor/browser/widget/inlineDiffMargin.ts @@ -12,7 +12,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { Range } from 'vs/editor/common/core/range'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IDiffLinesChange { readonly originalStartLineNumber: number; @@ -98,7 +98,7 @@ export class InlineDiffMargin extends Disposable { actions.push(copyLineAction); } - const readOnly = editor.getOption(EditorOptionId.readOnly); + const readOnly = editor.getOption(EditorOption.readOnly); if (!readOnly) { actions.push(new Action('diff.inline.revertChange', nls.localize('diff.inline.revertChange.label', "Revert this change"), undefined, true, async () => { if (diff.modifiedEndLineNumber === 0) { diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 921bb9d99b8..433788372bd 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; -import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOption, EDITOR_MODEL_DEFAULTS, blinkingStyleToString, cursorStyleToString } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, blinkingStyleToString, cursorStyleToString } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -363,7 +363,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.renderFinalNewline': { 'type': 'boolean', - 'default': EditorOption.renderFinalNewline.defaultValue, + 'default': EditorOptions.renderFinalNewline.defaultValue, 'description': nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }, 'editor.rulers': { @@ -431,29 +431,29 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.minimap.enabled': { 'type': 'boolean', - 'default': EditorOption.minimap.defaultValue.enabled, + 'default': EditorOptions.minimap.defaultValue.enabled, 'description': nls.localize('minimap.enabled', "Controls whether the minimap is shown.") }, 'editor.minimap.side': { 'type': 'string', 'enum': ['left', 'right'], - 'default': EditorOption.minimap.defaultValue.side, + 'default': EditorOptions.minimap.defaultValue.side, 'description': nls.localize('minimap.side', "Controls the side where to render the minimap.") }, 'editor.minimap.showSlider': { 'type': 'string', 'enum': ['always', 'mouseover'], - 'default': EditorOption.minimap.defaultValue.showSlider, + 'default': EditorOptions.minimap.defaultValue.showSlider, 'description': nls.localize('minimap.showSlider', "Controls whether the minimap slider is automatically hidden.") }, 'editor.minimap.renderCharacters': { 'type': 'boolean', - 'default': EditorOption.minimap.defaultValue.renderCharacters, + 'default': EditorOptions.minimap.defaultValue.renderCharacters, 'description': nls.localize('minimap.renderCharacters', "Render the actual characters on a line as opposed to color blocks.") }, 'editor.minimap.maxColumn': { 'type': 'number', - 'default': EditorOption.minimap.defaultValue.maxColumn, + 'default': EditorOptions.minimap.defaultValue.maxColumn, 'description': nls.localize('minimap.maxColumn', "Limit the width of the minimap to render at most a certain number of columns.") }, 'editor.hover.enabled': { @@ -512,7 +512,7 @@ const editorConfiguration: IConfigurationNode = { ] }, "Lines will wrap at the minimum of viewport and `#editor.wordWrapColumn#`."), ], - 'default': EditorOption.wordWrap.defaultValue, + 'default': EditorOptions.wordWrap.defaultValue, 'description': nls.localize({ key: 'wordWrap', comment: [ @@ -523,7 +523,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.wordWrapColumn': { 'type': 'integer', - 'default': EditorOption.wordWrapColumn.defaultValue, + 'default': EditorOptions.wordWrapColumn.defaultValue, 'minimum': 1, 'markdownDescription': nls.localize({ key: 'wordWrapColumn', @@ -547,12 +547,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.mouseWheelScrollSensitivity': { 'type': 'number', - 'default': EditorOption.mouseWheelScrollSensitivity.defaultValue, + 'default': EditorOptions.mouseWheelScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.") }, 'editor.fastScrollSensitivity': { 'type': 'number', - 'default': EditorOption.fastScrollSensitivity.defaultValue, + 'default': EditorOptions.fastScrollSensitivity.defaultValue, 'markdownDescription': nls.localize('fastScrollSensitivity', "Scrolling speed multiplier when pressing `Alt`.") }, 'editor.multiCursorModifier': { @@ -1049,7 +1049,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.folding': { 'type': 'boolean', - 'default': EditorOption.folding.defaultValue, + 'default': EditorOptions.folding.defaultValue, 'description': nls.localize('folding', "Controls whether the editor has code folding enabled.") }, 'editor.foldingStrategy': { @@ -1102,7 +1102,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('accessibilitySupport.on', "The editor will be permanently optimized for usage with a Screen Reader."), nls.localize('accessibilitySupport.off', "The editor will never be optimized for usage with a Screen Reader."), ], - 'default': EditorOption.accessibilitySupport.defaultValue, + 'default': EditorOptions.accessibilitySupport.defaultValue, 'description': nls.localize('accessibilitySupport', "Controls whether the editor should run in a mode where it is optimized for screen readers.") }, 'editor.showUnused': { @@ -1155,7 +1155,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.selectionClipboard': { 'type': 'boolean', - 'default': EditorOption.selectionClipboard.defaultValue, + 'default': EditorOptions.selectionClipboard.defaultValue, 'description': nls.localize('selectionClipboard', "Controls whether the Linux primary clipboard should be supported."), 'included': platform.isLinux }, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 8b81ce7e464..98ce2974528 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -1162,7 +1162,7 @@ export class InternalEditorOptions { */ public createChangeEvent(newOpts: InternalEditorOptions, changeEvent: ChangedEditorOptions | null): IConfigurationChangedEvent { return { - hasChanged: (id: EditorOptionId) => { + hasChanged: (id: EditorOption) => { if (!changeEvent) { return false; } @@ -1346,7 +1346,7 @@ export class InternalEditorOptions { * An event describing that the configuration of the editor has changed. */ export interface IConfigurationChangedEvent { - hasChanged(id: EditorOptionId): boolean; + hasChanged(id: EditorOption): boolean; readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; readonly editorClassName: boolean; @@ -1961,10 +1961,10 @@ export interface IRawEditorOptionsBag extends IEditorOptions { */ export class RawEditorOptions { private readonly _values: any[] = []; - public _read(id: EditorOptionId): T | undefined { + public _read(id: EditorOption): T | undefined { return this._values[id]; } - public _write(id: EditorOptionId, value: T | undefined): void { + public _write(id: EditorOption, value: T | undefined): void { this._values[id] = value; } } @@ -1974,16 +1974,16 @@ export class RawEditorOptions { */ export class ValidatedEditorOptions { private readonly _values: any[] = []; - public _read(option: EditorOptionId): T { + public _read(option: EditorOption): T { return this._values[option]; } - public _write(option: EditorOptionId, value: T): void { + public _write(option: EditorOption, value: T): void { this._values[option] = value; } } export interface IComputedEditorOptions { - get(id: T): FindComputedEditorOptionValueById; + get(id: T): FindComputedEditorOptionValueById; } /** @@ -1991,13 +1991,13 @@ export interface IComputedEditorOptions { */ export class ComputedEditorOptions implements IComputedEditorOptions { private readonly _values: any[] = []; - public _read(id: EditorOptionId): T { + public _read(id: EditorOption): T { return this._values[id]; } - public get(id: T): FindComputedEditorOptionValueById { + public get(id: T): FindComputedEditorOptionValueById { return this._values[id]; } - public _write(id: EditorOptionId, value: T): void { + public _write(id: EditorOption, value: T): void { this._values[id] = value; } } @@ -2007,17 +2007,17 @@ export class ComputedEditorOptions implements IComputedEditorOptions { */ export class ChangedEditorOptions { private readonly _values: boolean[] = []; - public get(id: EditorOptionId): boolean { + public get(id: EditorOption): boolean { return this._values[id]; } - public _write(id: EditorOptionId, value: boolean): void { + public _write(id: EditorOption, value: boolean): void { this._values[id] = value; } } export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; -export interface IEditorOption { +export interface IEditorOption { readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; @@ -2031,20 +2031,20 @@ export interface IEditorOption { /** * @internal */ -export const editorOptionsRegistry: IEditorOption[] = []; +export const editorOptionsRegistry: IEditorOption[] = []; -function registerEditorOption(option: IEditorOption): IEditorOption { +function registerEditorOption(option: IEditorOption): IEditorOption { editorOptionsRegistry[option.id] = option; return option; } -export abstract class BaseEditorOption implements IEditorOption { +export abstract class BaseEditorOption implements IEditorOption { public readonly id: K; public readonly name: PossibleKeyName; public readonly defaultValue: T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps: EditorOption[] = []) { this.id = id; this.name = name; this.defaultValue = defaultValue; @@ -2074,7 +2074,7 @@ export abstract class BaseEditorOption extends BaseEditorOption { +class EditorBooleanOption extends BaseEditorOption { public validate(input: boolean | undefined): boolean { return _boolean(input, this.defaultValue); } @@ -2083,10 +2083,10 @@ class EditorBooleanOption extends BaseEditorOption extends BaseEditorOption { +class EditorIntOption extends BaseEditorOption { public readonly minimum: number; public readonly maximum: number; - constructor(id: K, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.minimum = minimum; this.maximum = maximum; @@ -2099,9 +2099,9 @@ class EditorIntOption extends BaseEditorOption extends BaseEditorOption { +class EditorFloatOption extends BaseEditorOption { public readonly validationFn: (value: number) => number; - constructor(id: K, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.validationFn = validationFn; } @@ -2113,7 +2113,7 @@ class EditorFloatOption extends BaseEditorOption extends BaseEditorOption { +class EditorStringOption extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } @@ -2122,10 +2122,10 @@ class EditorStringOption extends BaseEditorOption extends BaseEditorOption { +class EditorEnumOption extends BaseEditorOption { public readonly allowedValues: T1[]; public readonly convert: (value: T1) => T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOptionId[] = []) { + constructor(id: K, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.allowedValues = allowedValues; this.convert = convert; @@ -2138,7 +2138,7 @@ class EditorEnumOption extends BaseEditor } } -class EditorPassthroughOption extends BaseEditorOption { +class EditorPassthroughOption extends BaseEditorOption { public validate(input: T | undefined): T { if (typeof input === 'undefined') { return this.defaultValue; @@ -2167,7 +2167,7 @@ export interface InternalEditorRenderLineNumbersOptions { readonly renderFn: ((lineNumber: number) => string) | null; } -class EditorRenderLineNumbersOption extends BaseEditorOption { +class EditorRenderLineNumbersOption extends BaseEditorOption { public validate(lineNumbers: LineNumbersType | undefined): InternalEditorRenderLineNumbersOptions { let renderType: RenderLineNumbersType = this.defaultValue.renderType; let renderFn: ((lineNumber: number) => string) | null = this.defaultValue.renderFn; @@ -2215,7 +2215,7 @@ export interface InternalEditorMinimapOptions { readonly maxColumn: number; } -class EditorMinimapOption extends BaseEditorOption { +class EditorMinimapOption extends BaseEditorOption { public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2246,7 +2246,7 @@ class EditorMinimapOption extends BaseEditorOption extends BaseEditorOption { +class EditorAccessibilitySupportOption extends BaseEditorOption { public validate(input: 'auto' | 'off' | 'on' | undefined): 'auto' | 'off' | 'on' { return _stringSet<'auto' | 'off' | 'on'>(input, this.defaultValue, ['auto', 'off', 'on']); } @@ -2266,12 +2266,12 @@ class EditorAccessibilitySupportOption extends BaseEdi //#region ariaLabel -class EditorAriaLabel extends BaseEditorOption { +class EditorAriaLabel extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { - const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + const accessibilitySupport = options.get(EditorOption.accessibilitySupport); if (accessibilitySupport === AccessibilitySupport.Disabled) { return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options."); } @@ -2283,12 +2283,12 @@ class EditorAriaLabel extends BaseEditorOption extends BaseEditorOption { +class EditorTabFocusMode extends BaseEditorOption { public validate(input: undefined): undefined { return undefined; } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): boolean { - const readOnly = options.get(EditorOptionId.readOnly); + const readOnly = options.get(EditorOption.readOnly); return (readOnly ? true : env.tabFocusMode); } } @@ -2311,7 +2311,7 @@ export interface InternalEditorScrollbarOptions { readonly verticalSliderSize: number; } -class EditorScrollbarOption extends BaseEditorOption { +class EditorScrollbarOption extends BaseEditorOption { public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2481,18 +2481,18 @@ export interface EditorLayoutInfo { /** * @internal */ -export class EditorLayoutInfoComputer extends BaseEditorOption { +export class EditorLayoutInfoComputer extends BaseEditorOption { public validate(input: undefined): undefined { return undefined; } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorLayoutInfo { - const glyphMargin = options.get(EditorOptionId.glyphMargin); - const lineNumbersMinChars = options.get(EditorOptionId.lineNumbersMinChars); - const rawLineDecorationsWidth = options.get(EditorOptionId.lineDecorationsWidth); - const folding = options.get(EditorOptionId.folding); - const minimap = options.get(EditorOptionId.minimap); - const scrollbar = options.get(EditorOptionId.scrollbar); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const glyphMargin = options.get(EditorOption.glyphMargin); + const lineNumbersMinChars = options.get(EditorOption.lineNumbersMinChars); + const rawLineDecorationsWidth = options.get(EditorOption.lineDecorationsWidth); + const folding = options.get(EditorOption.folding); + const minimap = options.get(EditorOption.minimap); + const scrollbar = options.get(EditorOption.scrollbar); + const renderLineNumbers = options.get(EditorOption.renderLineNumbers); let lineDecorationsWidth: number; if (typeof rawLineDecorationsWidth === 'string' && /^\d+(\.\d+)?ch$/.test(rawLineDecorationsWidth)) { @@ -2706,7 +2706,7 @@ export interface EditorWrappingInfo { readonly wrappingColumn: number; } -class EditorWrappingInfoComputer extends BaseEditorOption { +class EditorWrappingInfoComputer extends BaseEditorOption { public mix(a: undefined, b: undefined): undefined { return undefined; } @@ -2714,11 +2714,11 @@ class EditorWrappingInfoComputer extends BaseEditorOpt return undefined; } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorWrappingInfo { - const wordWrap = options.get(EditorOptionId.wordWrap); - const wordWrapColumn = options.get(EditorOptionId.wordWrapColumn); - const wordWrapMinified = options.get(EditorOptionId.wordWrapMinified); - const layoutInfo = options.get(EditorOptionId.layoutInfo); - const accessibilitySupport = options.get(EditorOptionId.accessibilitySupport); + 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); let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null; { @@ -2785,7 +2785,7 @@ class EditorWrappingInfoComputer extends BaseEditorOpt //#endregion -export const enum EditorOptionId { +export const enum EditorOption { accessibilitySupport, ariaLabel, fastScrollSensitivity, @@ -2815,27 +2815,27 @@ export const enum EditorOptionId { wrappingInfo, } -export const EditorOption = { - accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOptionId.accessibilitySupport, 'accessibilitySupport', 'auto')), - ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOptionId.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOptionId.accessibilitySupport])), - fastScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOptionId.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))), - folding: registerEditorOption(new EditorBooleanOption(EditorOptionId.folding, 'folding', true)), - glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOptionId.glyphMargin, 'glyphMargin', true)), - inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOptionId.inDiffEditor, 'inDiffEditor', false)), - lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOptionId.lineDecorationsWidth, 'lineDecorationsWidth', 10)), - lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOptionId.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), - minimap: registerEditorOption(new EditorMinimapOption(EditorOptionId.minimap, 'minimap', { +export const EditorOptions = { + accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOption.accessibilitySupport, 'accessibilitySupport', 'auto')), + ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOption.accessibilitySupport])), + fastScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))), + folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), + glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), + inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), + lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), + minimap: registerEditorOption(new EditorMinimapOption(EditorOption.minimap, 'minimap', { enabled: true, side: 'right', showSlider: 'mouseover', renderCharacters: true, maxColumn: 120, })), - mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOptionId.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), - readOnly: registerEditorOption(new EditorBooleanOption(EditorOptionId.readOnly, 'readOnly', false)), - renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOptionId.renderFinalNewline, 'renderFinalNewline', true)), - renderLineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOptionId.renderLineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), - scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOptionId.scrollbar, 'scrollbar', { + mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), + readOnly: registerEditorOption(new EditorBooleanOption(EditorOption.readOnly, 'readOnly', false)), + renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOption.renderFinalNewline, 'renderFinalNewline', true)), + renderLineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.renderLineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), + scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOption.scrollbar, 'scrollbar', { vertical: ScrollbarVisibility.Auto, horizontal: ScrollbarVisibility.Auto, arrowSize: 11, @@ -2848,23 +2848,23 @@ export const EditorOption = { verticalSliderSize: 14, handleMouseWheel: true, })), - selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectionClipboard, 'selectionClipboard', true)), - selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOptionId.selectOnLineNumbers, 'selectOnLineNumbers', true)), - tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOptionId.tabFocusMode, 'tabFocusMode', undefined, [EditorOptionId.readOnly])), - wordWrap: registerEditorOption(new EditorEnumOption(EditorOptionId.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), - wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), - wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), - wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOptionId.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), - wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOptionId.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), - wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOptionId.wordWrapMinified, 'wordWrapMinified', true)), - wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOptionId.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), + selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), + selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), + tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), + wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), + wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), + wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), + wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), + wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), + wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOption.wordWrapMinified, 'wordWrapMinified', true)), + wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), // Leave these at the end! - layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOptionId.layoutInfo, 'layoutInfo', undefined, [EditorOptionId.glyphMargin, EditorOptionId.lineDecorationsWidth, EditorOptionId.folding, EditorOptionId.minimap, EditorOptionId.scrollbar, EditorOptionId.renderLineNumbers])), - wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOptionId.wrappingInfo, 'wrappingInfo', undefined, [EditorOptionId.wordWrap, EditorOptionId.wordWrapColumn, EditorOptionId.wordWrapMinified, EditorOptionId.layoutInfo, EditorOptionId.accessibilitySupport])), + layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.renderLineNumbers])), + wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, 'wrappingInfo', undefined, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), }; -export type EditorOptionType = typeof EditorOption; -export type FindEditorOptionKeyById = { [K in keyof EditorOptionType]: EditorOptionType[K]['id'] extends T ? K : never }[keyof EditorOptionType]; +export type EditorOptionsType = typeof EditorOptions; +export type FindEditorOptionsKeyById = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType]; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; -export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; +export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index fce316527de..180829a5ebb 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -20,7 +20,7 @@ import { RawContentChangedType } from 'vs/editor/common/model/textModelEvents'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { dispose } from 'vs/base/common/lifecycle'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; function containsLineMappingChanged(events: viewEvents.ViewEvent[]): boolean { for (let i = 0, len = events.length; i < len; i++) { @@ -674,7 +674,7 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors { this._isDoingComposition = false; } - if (this._configuration.options.get(EditorOptionId.readOnly)) { + if (this._configuration.options.get(EditorOption.readOnly)) { // All the remaining handlers will try to edit the model, // but we cannot edit when read only... this._onDidAttemptReadOnlyEdit.fire(undefined); diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index 8c9ecb6a3d7..e4de9b731c1 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -6,7 +6,7 @@ import { CharCode } from 'vs/base/common/charCode'; import { onUnexpectedError } from 'vs/base/common/errors'; import * as strings from 'vs/base/common/strings'; -import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption } from 'vs/editor/common/config/editorOptions'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -112,7 +112,7 @@ export class CursorConfiguration { public static shouldRecreate(e: IConfigurationChangedEvent): boolean { return ( - e.hasChanged(EditorOptionId.layoutInfo) + e.hasChanged(EditorOption.layoutInfo) || e.wordSeparators || e.emptySelectionClipboard || e.multiCursorMergeOverlapping @@ -122,7 +122,7 @@ export class CursorConfiguration { || e.autoSurround || e.useTabStops || e.lineHeight - || e.hasChanged(EditorOptionId.readOnly) + || e.hasChanged(EditorOption.readOnly) ); } @@ -135,9 +135,9 @@ export class CursorConfiguration { const c = configuration.editor; const options = configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); - this.readOnly = options.get(EditorOptionId.readOnly); + this.readOnly = options.get(EditorOption.readOnly); this.tabSize = modelOptions.tabSize; this.indentSize = modelOptions.indentSize; this.insertSpaces = modelOptions.insertSpaces; diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index b23d2a1b9b2..4027972d75e 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -439,7 +439,7 @@ export enum RenderLineNumbersType { Custom = 4 } -export enum EditorOptionId { +export enum EditorOption { accessibilitySupport = 0, ariaLabel = 1, fastScrollSensitivity = 2, diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index ebb674197e0..a3da3dfa94c 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -6,7 +6,7 @@ import * as errors from 'vs/base/common/errors'; import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { ScrollEvent } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { ScrollType } from 'vs/editor/common/editorCommon'; @@ -56,7 +56,7 @@ export class ViewConfigurationChangedEvent { this.viewInfo = source.viewInfo; } - public hasChanged(id: EditorOptionId): boolean { + public hasChanged(id: EditorOption): boolean { return this._source.hasChanged(id); } } diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 99cd7efff43..6950cb302a8 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -6,7 +6,7 @@ import { Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { IScrollDimensions, IScrollPosition, ScrollEvent, Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { LinesLayout } from 'vs/editor/common/viewLayout/linesLayout'; import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; @@ -28,7 +28,7 @@ export class ViewLayout extends Disposable implements IViewLayout { this._configuration = configuration; const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this._linesLayout = new LinesLayout(lineCount, this._configuration.editor.lineHeight); @@ -62,9 +62,9 @@ export class ViewLayout extends Disposable implements IViewLayout { if (e.lineHeight) { this._linesLayout.setLineHeight(this._configuration.editor.lineHeight); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { const options = this._configuration.options; - const layoutInfo = options.get(EditorOptionId.layoutInfo); + const layoutInfo = options.get(EditorOption.layoutInfo); this.scrollable.setScrollDimensions({ width: layoutInfo.contentWidth, height: layoutInfo.contentHeight @@ -89,7 +89,7 @@ export class ViewLayout extends Disposable implements IViewLayout { private _getHorizontalScrollbarHeight(scrollDimensions: IScrollDimensions): number { const options = this._configuration.options; - const scrollbar = options.get(EditorOptionId.scrollbar); + const scrollbar = options.get(EditorOption.scrollbar); if (scrollbar.horizontal === ScrollbarVisibility.Hidden) { // horizontal scrollbar not visible return 0; @@ -146,7 +146,7 @@ export class ViewLayout extends Disposable implements IViewLayout { private _computeScrollWidth(maxLineWidth: number, viewportWidth: number): number { const options = this._configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); let isViewportWrapping = wrappingInfo.isViewportWrapping; if (!isViewportWrapping) { const extraHorizontalSpace = this._configuration.editor.viewInfo.scrollBeyondLastColumn * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; diff --git a/src/vs/editor/common/viewModel/viewModelDecorations.ts b/src/vs/editor/common/viewModel/viewModelDecorations.ts index bedcfb72b83..b74baa8dd1c 100644 --- a/src/vs/editor/common/viewModel/viewModelDecorations.ts +++ b/src/vs/editor/common/viewModel/viewModelDecorations.ts @@ -10,7 +10,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon'; import { IModelDecoration, ITextModel } from 'vs/editor/common/model'; import { IViewModelLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection'; import { ICoordinatesConverter, InlineDecoration, InlineDecorationType, ViewModelDecoration } from 'vs/editor/common/viewModel/viewModel'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IDecorationsViewportData { /** @@ -104,7 +104,7 @@ export class ViewModelDecorations implements IDisposable { } private _getDecorationsViewportData(viewportRange: Range): IDecorationsViewportData { - const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, this.configuration.options.get(EditorOptionId.readOnly)); + const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, this.configuration.options.get(EditorOption.readOnly)); const startLineNumber = viewportRange.startLineNumber; const endLineNumber = viewportRange.endLineNumber; diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 8ccdd124225..055cf6ae0d1 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import * as strings from 'vs/base/common/strings'; -import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -61,11 +61,11 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } else { const conf = this.configuration.editor; const options = this.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = options.get(EditorOption.wrappingInfo); + const wordWrapBreakAfterCharacters = options.get(EditorOption.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = options.get(EditorOption.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = options.get(EditorOption.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = options.get(EditorOption.wrappingIndent); let hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, @@ -154,8 +154,8 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel const conf = this.configuration.editor; const options = this.configuration.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); - const wrappingIndent = options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = options.get(EditorOption.wrappingInfo); + const wrappingIndent = options.get(EditorOption.wrappingIndent); if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth)) { eventsCollector.emit(new viewEvents.ViewFlushedEvent()); @@ -170,7 +170,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } } - if (e.hasChanged(EditorOptionId.readOnly)) { + if (e.hasChanged(EditorOption.readOnly)) { // Must read again all decorations due to readOnly filtering this.decorations.reset(); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); @@ -561,7 +561,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } public getAllOverviewRulerDecorations(theme: ITheme): IOverviewRulerDecorations { - return this.lines.getAllOverviewRulerDecorations(this.editorId, this.configuration.options.get(EditorOptionId.readOnly), theme); + return this.lines.getAllOverviewRulerDecorations(this.editorId, this.configuration.options.get(EditorOption.readOnly), theme); } public invalidateOverviewRulerColorCache(): void { diff --git a/src/vs/editor/contrib/codeAction/codeActionModel.ts b/src/vs/editor/contrib/codeAction/codeActionModel.ts index 3c8b4dacdd1..2af98e865aa 100644 --- a/src/vs/editor/contrib/codeAction/codeActionModel.ts +++ b/src/vs/editor/contrib/codeAction/codeActionModel.ts @@ -17,7 +17,7 @@ import { IMarkerService } from 'vs/platform/markers/common/markers'; import { IEditorProgressService } from 'vs/platform/progress/common/progress'; import { getCodeActions, CodeActionSet } from './codeAction'; import { CodeActionTrigger } from './codeActionTrigger'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const SUPPORTED_CODE_ACTIONS = new RawContextKey('supportedCodeAction', ''); @@ -193,7 +193,7 @@ export class CodeActionModel extends Disposable { const model = this._editor.getModel(); if (model && CodeActionProviderRegistry.has(model) - && !this._editor.getOption(EditorOptionId.readOnly) + && !this._editor.getOption(EditorOption.readOnly) ) { const supportedActions: string[] = []; for (const provider of CodeActionProviderRegistry.all(model)) { diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 253052dace3..631d9041902 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -26,7 +26,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { INotificationService } from 'vs/platform/notification/common/notification'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const SEARCH_STRING_MAX_LENGTH = 524288; @@ -699,7 +699,7 @@ export class StartFindReplaceAction extends EditorAction { } public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void { - if (!editor.hasModel() || editor.getOption(EditorOptionId.readOnly)) { + if (!editor.hasModel() || editor.getOption(EditorOption.readOnly)) { return; } diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index c62ff1190bf..232502b5ba8 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -23,7 +23,7 @@ import { toDisposable } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_REPLACE_INPUT_FOCUSED, FIND_IDS, MATCHES_LIMIT } from 'vs/editor/contrib/find/findModel'; import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/findState'; @@ -176,18 +176,18 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._findInput.inputBox.layout(); this._register(this._codeEditor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.hasChanged(EditorOptionId.readOnly)) { - if (this._codeEditor.getOption(EditorOptionId.readOnly)) { + if (e.hasChanged(EditorOption.readOnly)) { + if (this._codeEditor.getOption(EditorOption.readOnly)) { // Hide replace part if editor becomes read only this._state.change({ isReplaceRevealed: false }, false); } this._updateButtons(); } - if (e.hasChanged(EditorOptionId.layoutInfo)) { + if (e.hasChanged(EditorOption.layoutInfo)) { this._tryUpdateWidgetWidth(); } - if (e.hasChanged(EditorOptionId.accessibilitySupport)) { + if (e.hasChanged(EditorOption.accessibilitySupport)) { this.updateAccessibilitySupport(); } @@ -315,7 +315,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } if (e.isReplaceRevealed) { if (this._state.isReplaceRevealed) { - if (!this._codeEditor.getOption(EditorOptionId.readOnly) && !this._isReplaceVisible) { + if (!this._codeEditor.getOption(EditorOption.readOnly) && !this._isReplaceVisible) { this._isReplaceVisible = true; this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode); this._updateButtons(); @@ -456,7 +456,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._toggleReplaceBtn.toggleClass('expand', this._isReplaceVisible); this._toggleReplaceBtn.setExpanded(this._isReplaceVisible); - let canReplace = !this._codeEditor.getOption(EditorOptionId.readOnly); + let canReplace = !this._codeEditor.getOption(EditorOption.readOnly); this._toggleReplaceBtn.setEnabled(this._isVisible && canReplace); } @@ -1210,7 +1210,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } private updateAccessibilitySupport(): void { - const value = this._codeEditor.getOption(EditorOptionId.accessibilitySupport); + const value = this._codeEditor.getOption(EditorOption.accessibilitySupport); this._findInput.setFocusInputOnOptionClick(value !== AccessibilitySupport.Enabled); } } diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index 4c4c0f2adc7..648461cd082 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -18,7 +18,7 @@ import { FoldingModel, setCollapseStateAtLevel, CollapseMemento, setCollapseStat import { FoldingDecorationProvider } from './foldingDecorations'; import { FoldingRegions, FoldingRegion } from './foldingRanges'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IMarginData, IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { HiddenRangeModel } from 'vs/editor/contrib/folding/hiddenRangeModel'; import { IRange } from 'vs/editor/common/core/range'; @@ -88,7 +88,7 @@ export class FoldingController extends Disposable implements IEditorContribution super(); this.editor = editor; const options = this.editor.getOptions(); - this._isEnabled = options.get(EditorOptionId.folding); + this._isEnabled = options.get(EditorOption.folding); this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover'; this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation'; @@ -110,10 +110,10 @@ export class FoldingController extends Disposable implements IEditorContribution this._register(this.editor.onDidChangeModel(() => this.onModelChanged())); this._register(this.editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.contribInfo || e.hasChanged(EditorOptionId.folding)) { + if (e.contribInfo || e.hasChanged(EditorOption.folding)) { let oldIsEnabled = this._isEnabled; const options = this.editor.getOptions(); - this._isEnabled = options.get(EditorOptionId.folding); + this._isEnabled = options.get(EditorOption.folding); this.foldingEnabled.set(this._isEnabled); if (oldIsEnabled !== this._isEnabled) { this.onModelChanged(); diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index 36cd010daff..e03c5464e51 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -11,7 +11,7 @@ import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution, IScrollEvent } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -265,7 +265,7 @@ class ShowHoverAction extends EditorAction { } const position = editor.getPosition(); const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column); - const focus = editor.getOption(EditorOptionId.accessibilitySupport) === AccessibilitySupport.Enabled; + const focus = editor.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled; controller.showContentHover(range, HoverStartMode.Immediate, focus); } } diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index c82ea98b95b..174f87f6a0c 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -20,7 +20,7 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2 import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface ICancelEvent { readonly retrigger: boolean; @@ -184,7 +184,7 @@ export class SuggestModel implements IDisposable { dispose(this._triggerCharacterListener); - if (this._editor.getOption(EditorOptionId.readOnly) + if (this._editor.getOption(EditorOption.readOnly) || !this._editor.hasModel() || !this._editor.getConfiguration().contribInfo.suggestOnTriggerCharacters) { diff --git a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts index a0afb73c164..948a2b2ad8c 100644 --- a/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts +++ b/src/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.ts @@ -31,7 +31,7 @@ import { contrastBorder, editorWidgetBackground, widgetShadow, editorWidgetForeg import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { AccessibilityHelpNLS } from 'vs/editor/common/standaloneStrings'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new RawContextKey('accessibilityHelpWidgetVisible', false); @@ -240,14 +240,14 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { let text = getSelectionLabel(selections, charactersSelected); - if (options.get(EditorOptionId.inDiffEditor)) { - if (options.get(EditorOptionId.readOnly)) { + if (options.get(EditorOption.inDiffEditor)) { + if (options.get(EditorOption.readOnly)) { text += AccessibilityHelpNLS.readonlyDiffEditor; } else { text += AccessibilityHelpNLS.editableDiffEditor; } } else { - if (options.get(EditorOptionId.readOnly)) { + if (options.get(EditorOption.readOnly)) { text += AccessibilityHelpNLS.readonlyEditor; } else { text += AccessibilityHelpNLS.editableEditor; @@ -259,7 +259,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { ? AccessibilityHelpNLS.changeConfigToOnMac : AccessibilityHelpNLS.changeConfigToOnWinLinux ); - switch (options.get(EditorOptionId.accessibilitySupport)) { + switch (options.get(EditorOption.accessibilitySupport)) { case AccessibilitySupport.Unknown: text += '\n\n - ' + turnOnMessage; break; @@ -273,7 +273,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { } - if (options.get(EditorOptionId.tabFocusMode)) { + if (options.get(EditorOption.tabFocusMode)) { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOnMsg, AccessibilityHelpNLS.tabFocusModeOnMsgNoKb); } else { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, AccessibilityHelpNLS.tabFocusModeOffMsg, AccessibilityHelpNLS.tabFocusModeOffMsgNoKb); diff --git a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts index 82c5fb1a312..82ccd6a63f7 100644 --- a/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts +++ b/src/vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts @@ -10,7 +10,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class IPadShowKeyboard extends Disposable implements IEditorContribution { @@ -30,7 +30,7 @@ export class IPadShowKeyboard extends Disposable implements IEditorContribution } private update(): void { - const shouldHaveWidget = (!this.editor.getOption(EditorOptionId.readOnly)); + const shouldHaveWidget = (!this.editor.getOption(EditorOption.readOnly)); if (!this.widget && shouldHaveWidget) { diff --git a/src/vs/editor/standalone/browser/standaloneEditor.ts b/src/vs/editor/standalone/browser/standaloneEditor.ts index 70d17b7f81b..a910ffb2b76 100644 --- a/src/vs/editor/standalone/browser/standaloneEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneEditor.ts @@ -370,7 +370,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { RenderMinimap: standaloneEnums.RenderMinimap, ScrollType: standaloneEnums.ScrollType, RenderLineNumbersType: standaloneEnums.RenderLineNumbersType, - EditorOptionId: standaloneEnums.EditorOptionId, + EditorOption: standaloneEnums.EditorOption, // classes BaseEditorOption: editorOptions.BaseEditorOption, @@ -382,7 +382,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { // vars EditorType: editorCommon.EditorType, - EditorOption: editorOptions.EditorOption, + EditorOptions: editorOptions.EditorOptions, }; } diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index 9a0c8edad12..a105d7b2c29 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorHoverOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; @@ -68,7 +68,7 @@ suite('Common Editor Config', () => { function assertWrapping(config: TestConfiguration, isViewportWrapping: boolean, wrappingColumn: number): void { const options = config.options; - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); assert.equal(wrappingInfo.isViewportWrapping, isViewportWrapping); assert.equal(wrappingInfo.wrappingColumn, wrappingColumn); } diff --git a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts index faa9ac14097..2ecf905ed35 100644 --- a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts +++ b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts @@ -19,7 +19,7 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer' import { ILineMapping, ISimpleModel, SplitLine, SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection'; import { ViewLineData } from 'vs/editor/common/viewModel/viewModel'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; suite('Editor ViewModel - SplitLinesCollection', () => { @@ -91,11 +91,11 @@ suite('Editor ViewModel - SplitLinesCollection', () => { function withSplitLinesCollection(text: string, callback: (model: TextModel, linesCollection: SplitLinesCollection) => void): void { const config = new TestConfiguration({}); - const wrappingInfo = config.options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = config.options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = config.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = config.options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = config.options.get(EditorOption.wrappingInfo); + const wordWrapBreakAfterCharacters = config.options.get(EditorOption.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = config.options.get(EditorOption.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOption.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = config.options.get(EditorOption.wrappingIndent); const hardWrappingLineMapperFactory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, @@ -744,11 +744,11 @@ suite('SplitLinesCollection', () => { wordWrapColumn: wordWrapColumn, wrappingIndent: 'indent' }); - const wrappingInfo = configuration.options.get(EditorOptionId.wrappingInfo); - const wordWrapBreakAfterCharacters = configuration.options.get(EditorOptionId.wordWrapBreakAfterCharacters); - const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOptionId.wordWrapBreakBeforeCharacters); - const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOptionId.wordWrapBreakObtrusiveCharacters); - const wrappingIndent = configuration.options.get(EditorOptionId.wrappingIndent); + const wrappingInfo = configuration.options.get(EditorOption.wrappingInfo); + const wordWrapBreakAfterCharacters = configuration.options.get(EditorOption.wordWrapBreakAfterCharacters); + const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOption.wordWrapBreakBeforeCharacters); + const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOption.wordWrapBreakObtrusiveCharacters); + const wrappingIndent = configuration.options.get(EditorOption.wrappingIndent); const factory = new CharacterHardWrappingLineMapperFactory( wordWrapBreakBeforeCharacters, diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index ab2061dd683..3e52cdbc9a3 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3365,7 +3365,7 @@ declare namespace monaco.editor { * An event describing that the configuration of the editor has changed. */ export interface IConfigurationChangedEvent { - hasChanged(id: EditorOptionId): boolean; + hasChanged(id: EditorOption): boolean; readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; readonly editorClassName: boolean; @@ -3405,14 +3405,14 @@ declare namespace monaco.editor { } export interface IComputedEditorOptions { - get(id: T): FindComputedEditorOptionValueById; + get(id: T): FindComputedEditorOptionValueById; } export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never; }[keyof IEditorOptions]; - export interface IEditorOption { + export interface IEditorOption { readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; @@ -3423,11 +3423,11 @@ declare namespace monaco.editor { equals(a: T3, b: T3): boolean; } - export abstract class BaseEditorOption implements IEditorOption { + export abstract class BaseEditorOption implements IEditorOption { readonly id: K; readonly name: PossibleKeyName; readonly defaultValue: T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps?: EditorOptionId[]); + constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps?: EditorOption[]); read(options: IRawEditorOptionsBag): T1 | undefined; mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; abstract validate(input: T1 | undefined): T2; @@ -3591,7 +3591,7 @@ declare namespace monaco.editor { readonly wrappingColumn: number; } - export enum EditorOptionId { + export enum EditorOption { accessibilitySupport = 0, ariaLabel = 1, fastScrollSensitivity = 2, @@ -3620,44 +3620,44 @@ declare namespace monaco.editor { wrappingInfo = 25 } - export const EditorOption: { - accessibilitySupport: IEditorOption; - ariaLabel: IEditorOption; - fastScrollSensitivity: IEditorOption; - folding: IEditorOption; - glyphMargin: IEditorOption; - inDiffEditor: IEditorOption; - lineDecorationsWidth: IEditorOption; - lineNumbersMinChars: IEditorOption; - minimap: IEditorOption; - mouseWheelScrollSensitivity: IEditorOption; - readOnly: IEditorOption; - renderFinalNewline: IEditorOption; - renderLineNumbers: IEditorOption; - scrollbar: IEditorOption; - selectionClipboard: IEditorOption; - selectOnLineNumbers: IEditorOption; - tabFocusMode: IEditorOption; - wordWrap: IEditorOption; - wordWrapBreakAfterCharacters: IEditorOption; - wordWrapBreakBeforeCharacters: IEditorOption; - wordWrapBreakObtrusiveCharacters: IEditorOption; - wordWrapColumn: IEditorOption; - wordWrapMinified: IEditorOption; - wrappingIndent: IEditorOption; - layoutInfo: IEditorOption; - wrappingInfo: IEditorOption; + export const EditorOptions: { + accessibilitySupport: IEditorOption; + ariaLabel: IEditorOption; + fastScrollSensitivity: IEditorOption; + folding: IEditorOption; + glyphMargin: IEditorOption; + inDiffEditor: IEditorOption; + lineDecorationsWidth: IEditorOption; + lineNumbersMinChars: IEditorOption; + minimap: IEditorOption; + mouseWheelScrollSensitivity: IEditorOption; + readOnly: IEditorOption; + renderFinalNewline: IEditorOption; + renderLineNumbers: IEditorOption; + scrollbar: IEditorOption; + selectionClipboard: IEditorOption; + selectOnLineNumbers: IEditorOption; + tabFocusMode: IEditorOption; + wordWrap: IEditorOption; + wordWrapBreakAfterCharacters: IEditorOption; + wordWrapBreakBeforeCharacters: IEditorOption; + wordWrapBreakObtrusiveCharacters: IEditorOption; + wordWrapColumn: IEditorOption; + wordWrapMinified: IEditorOption; + wrappingIndent: IEditorOption; + layoutInfo: IEditorOption; + wrappingInfo: IEditorOption; }; - export type EditorOptionType = typeof EditorOption; + export type EditorOptionsType = typeof EditorOptions; - export type FindEditorOptionKeyById = { - [K in keyof EditorOptionType]: EditorOptionType[K]['id'] extends T ? K : never; - }[keyof EditorOptionType]; + export type FindEditorOptionsKeyById = { + [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never; + }[keyof EditorOptionsType]; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; - export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; + export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; /** * A view zone is a full horizontal rectangle that 'pushes' text down. @@ -4109,7 +4109,7 @@ declare namespace monaco.editor { */ getConfiguration(): InternalEditorOptions; getOptions(): IComputedEditorOptions; - getOption(id: T): FindComputedEditorOptionValueById; + getOption(id: T): FindComputedEditorOptionValueById; /** * Get value of the current model attached to this editor. * @see `ITextModel.getValue` diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index 7d1d2022fed..2d210bb3feb 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -6,7 +6,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { RenderLineNumbersType, TextEditorCursorStyle, cursorStyleToString, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -60,7 +60,7 @@ export class MainThreadTextEditorProperties { if (codeEditor) { const codeEditorOpts = codeEditor.getConfiguration(); const options = codeEditor.getOptions(); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOption.renderLineNumbers); cursorStyle = codeEditorOpts.viewInfo.cursorStyle; lineNumbers = renderLineNumbers.renderType; } else if (previousProperties) { diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 94e8258b4c1..b167f3ea8df 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -35,7 +35,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ITextFileService, SUPPORTED_ENCODINGS } from 'vs/workbench/services/textfile/common/textfiles'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; -import { IConfigurationChangedEvent, IEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { deepClone } from 'vs/base/common/objects'; @@ -584,7 +584,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { // Hook Listener for Configuration changes this.activeEditorListeners.add(activeCodeEditor.onDidChangeConfiguration((event: IConfigurationChangedEvent) => { - if (event.hasChanged(EditorOptionId.accessibilitySupport)) { + if (event.hasChanged(EditorOption.accessibilitySupport)) { this.onScreenReaderModeChange(activeCodeEditor); } })); @@ -708,7 +708,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { } } - screenReaderMode = (editorWidget.getOption(EditorOptionId.accessibilitySupport) === AccessibilitySupport.Enabled); + screenReaderMode = (editorWidget.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled); } if (screenReaderMode === false && this.screenReaderNotification) { @@ -758,7 +758,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { private onEOLChange(editorWidget: ICodeEditor | undefined): void { const info: StateDelta = { EOL: undefined }; - if (editorWidget && !editorWidget.getOption(EditorOptionId.readOnly)) { + if (editorWidget && !editorWidget.getOption(EditorOption.readOnly)) { const codeEditorModel = editorWidget.getModel(); if (codeEditorModel) { info.EOL = codeEditorModel.getEOL(); @@ -819,7 +819,7 @@ function isWritableCodeEditor(codeEditor: ICodeEditor | undefined): boolean { if (!codeEditor) { return false; } - return !codeEditor.getOption(EditorOptionId.readOnly); + return !codeEditor.getOption(EditorOption.readOnly); } function isWritableBaseEditor(e: IBaseEditor): boolean { diff --git a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts index 4f84e1dc2b4..4e2253b8731 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/accessibility/accessibility.ts @@ -17,7 +17,7 @@ import * as strings from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { EditorAction, EditorCommand, registerEditorAction, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IEditorOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ToggleTabFocusModeAction } from 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode'; @@ -191,7 +191,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { text += '\n\n' + nls.localize('status', "Status:"); const configuredValue = this._configurationService.getValue('editor').accessibilitySupport; - const actualValue = options.get(EditorOptionId.accessibilitySupport); + const actualValue = options.get(EditorOption.accessibilitySupport); const emergencyTurnOnMessage = ( platform.isMacintosh @@ -229,7 +229,7 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget { const NLS_TAB_FOCUS_MODE_OFF = nls.localize('tabFocusModeOffMsg', "Pressing Tab in the current editor will insert the tab character. Toggle this behavior by pressing {0}."); const NLS_TAB_FOCUS_MODE_OFF_NO_KB = nls.localize('tabFocusModeOffMsgNoKb', "Pressing Tab in the current editor will insert the tab character. The command {0} is currently not triggerable by a keybinding."); - if (options.get(EditorOptionId.tabFocusMode)) { + if (options.get(EditorOption.tabFocusMode)) { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, NLS_TAB_FOCUS_MODE_ON, NLS_TAB_FOCUS_MODE_ON_NO_KB); } else { text += '\n\n - ' + this._descriptionForCommand(ToggleTabFocusModeAction.ID, NLS_TAB_FOCUS_MODE_OFF, NLS_TAB_FOCUS_MODE_OFF_NO_KB); diff --git a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts index da10b808d17..32133496349 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts @@ -9,7 +9,7 @@ import * as process from 'vs/base/common/process'; import * as platform from 'vs/base/common/platform'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; @@ -24,11 +24,11 @@ export class SelectionClipboard extends Disposable implements IEditorContributio super(); if (platform.isLinux) { - let isEnabled = editor.getOption(EditorOptionId.selectionClipboard); + let isEnabled = editor.getOption(EditorOption.selectionClipboard); this._register(editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.hasChanged(EditorOptionId.selectionClipboard)) { - isEnabled = editor.getOption(EditorOptionId.selectionClipboard); + if (e.hasChanged(EditorOption.selectionClipboard)) { + isEnabled = editor.getOption(EditorOption.selectionClipboard); } })); diff --git a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts index 8d22a06dcba..9032288864d 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/toggleWordWrap.ts @@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { EditorOptionId, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOption, EditorOptions } from 'vs/editor/common/config/editorOptions'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { ITextModel } from 'vs/editor/common/model'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; @@ -68,7 +68,7 @@ function readWordWrapState(model: ITextModel, configurationService: ITextResourc const _transientState = readTransientState(model, codeEditorService); return { configuredWordWrap: _configuredWordWrap, - configuredWordWrapMinified: (typeof _configuredWordWrapMinified === 'boolean' ? _configuredWordWrapMinified : EditorOption.wordWrapMinified.defaultValue), + configuredWordWrapMinified: (typeof _configuredWordWrapMinified === 'boolean' ? _configuredWordWrapMinified : EditorOptions.wordWrapMinified.defaultValue), transientState: _transientState }; } @@ -85,7 +85,7 @@ function toggleWordWrap(editor: ICodeEditor, state: IWordWrapState): IWordWrapSt let transientState: IWordWrapTransientState; - const actualWrappingInfo = editor.getOption(EditorOptionId.wrappingInfo); + const actualWrappingInfo = editor.getOption(EditorOption.wrappingInfo); if (actualWrappingInfo.isWordWrapMinified) { // => wrapping due to minified file transientState = { @@ -138,7 +138,7 @@ class ToggleWordWrapAction extends EditorAction { if (!editor.hasModel()) { return; } - if (editor.getOption(EditorOptionId.inDiffEditor)) { + if (editor.getOption(EditorOption.inDiffEditor)) { // Cannot change wrapping settings inside the diff editor const notificationService = accessor.get(INotificationService); notificationService.info(nls.localize('wordWrap.notInDiffEditor', "Cannot toggle word wrap in a diff editor.")); @@ -176,21 +176,21 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution super(); const options = this.editor.getOptions(); - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); const isWordWrapMinified = this.contextKeyService.createKey(isWordWrapMinifiedKey, wrappingInfo.isWordWrapMinified); const isDominatedByLongLines = this.contextKeyService.createKey(isDominatedByLongLinesKey, wrappingInfo.isDominatedByLongLines); - const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, options.get(EditorOptionId.inDiffEditor)); + const inDiffEditor = this.contextKeyService.createKey(inDiffEditorKey, options.get(EditorOption.inDiffEditor)); let currentlyApplyingEditorConfig = false; this._register(editor.onDidChangeConfiguration((e) => { - if (!e.hasChanged(EditorOptionId.wrappingInfo) || !e.hasChanged(EditorOptionId.inDiffEditor)) { + if (!e.hasChanged(EditorOption.wrappingInfo) || !e.hasChanged(EditorOption.inDiffEditor)) { return; } const options = this.editor.getOptions(); - const wrappingInfo = options.get(EditorOptionId.wrappingInfo); + const wrappingInfo = options.get(EditorOption.wrappingInfo); isWordWrapMinified.set(wrappingInfo.isWordWrapMinified); isDominatedByLongLines.set(wrappingInfo.isDominatedByLongLines); - inDiffEditor.set(options.get(EditorOptionId.inDiffEditor)); + inDiffEditor.set(options.get(EditorOption.inDiffEditor)); if (!currentlyApplyingEditorConfig) { // I am not the cause of the word wrap getting changed ensureWordWrapSettings(); @@ -216,7 +216,7 @@ class ToggleWordWrapController extends Disposable implements IEditorContribution return; } - if (this.editor.getOption(EditorOptionId.inDiffEditor)) { + if (this.editor.getOption(EditorOption.inDiffEditor)) { return; } diff --git a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts index 52068f454fc..c6f45b8d912 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts @@ -37,7 +37,7 @@ import { COMMENTEDITOR_DECORATION_KEY, ReviewZoneWidget } from 'vs/workbench/con import { ctxCommentEditorFocused, SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const ID = 'editor.contrib.review'; @@ -603,7 +603,7 @@ export class ReviewController implements IEditorContribution { } const options = this.editor.getOptions(); - if (options.get(EditorOptionId.folding)) { + if (options.get(EditorOption.folding)) { lineDecorationsWidth -= 16; } lineDecorationsWidth += 9; diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts index d0d7906907c..0758b523ae3 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts @@ -41,7 +41,7 @@ import { ContextSubMenu } from 'vs/base/browser/contextmenu'; import { memoize } from 'vs/base/common/decorators'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { getHover } from 'vs/editor/contrib/hover/getHover'; -import { IEditorHoverOptions, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { CancellationToken } from 'vs/base/common/cancellation'; import { BreakpointWidget } from 'vs/workbench/contrib/debug/browser/breakpointWidget'; import { DebugHoverWidget } from 'vs/workbench/contrib/debug/browser/debugHover'; @@ -540,7 +540,7 @@ export class DebugEditorContribution implements IDebugEditorContribution { if (this.configurationWidget) { this.configurationWidget.dispose(); } - if (model && LAUNCH_JSON_REGEX.test(model.uri.toString()) && !this.editor.getOption(EditorOptionId.readOnly)) { + if (model && LAUNCH_JSON_REGEX.test(model.uri.toString()) && !this.editor.getOption(EditorOption.readOnly)) { this.configurationWidget = this.instantiationService.createInstance(FloatingClickWidget, this.editor, nls.localize('addConfiguration', "Add Configuration..."), null); this.configurationWidget.render(); this.toDispose.push(this.configurationWidget.onClick(() => this.addLaunchConfiguration())); diff --git a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts index f3e4b3ca255..9b45e34dee4 100644 --- a/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts +++ b/src/vs/workbench/contrib/preferences/browser/keybindingsEditorContribution.ts @@ -30,7 +30,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { KeybindingParser } from 'vs/base/common/keybindingParser'; import Severity from 'vs/base/common/severity'; import { SeverityIcon } from 'vs/platform/severityIcon/common/severityIcon'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const NLS_LAUNCH_MESSAGE = nls.localize('defineKeybinding.start', "Define Keybinding"); const NLS_KB_LAYOUT_ERROR_MESSAGE = nls.localize('defineKeybinding.kbLayoutErrorMessage', "You won't be able to produce this key combination under your current keyboard layout."); @@ -83,7 +83,7 @@ export class DefineKeybindingController extends Disposable implements editorComm this._createKeybindingDecorationRenderer(); // The button to define keybindings is shown only for the user keybindings.json - if (!this._editor.getOption(EditorOptionId.readOnly)) { + if (!this._editor.getOption(EditorOption.readOnly)) { this._createKeybindingWidgetRenderer(); } else { this._disposeKeybindingWidgetRenderer(); @@ -378,7 +378,7 @@ class DefineKeybindingCommand extends EditorCommand { } runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void { - if (!isInterestingEditorModel(editor) || editor.getOption(EditorOptionId.readOnly)) { + if (!isInterestingEditorModel(editor) || editor.getOption(EditorOption.readOnly)) { return; } const controller = DefineKeybindingController.get(editor); diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts index 6f4eb6a5551..7f66cba3d62 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts @@ -33,7 +33,7 @@ import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/p import { PANEL_ACTIVE_TITLE_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND } from 'vs/workbench/common/theme'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { ISettingsGroup } from 'vs/workbench/services/preferences/common/preferences'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class SettingsHeaderWidget extends Widget implements IViewZone { @@ -88,7 +88,7 @@ export class SettingsHeaderWidget extends Widget implements IViewZone { const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; - if (!options.get(EditorOptionId.folding)) { + if (!options.get(EditorOption.folding)) { this.titleContainer.style.paddingLeft = '6px'; } } diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts index 418aafc0130..5a0e888e931 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts @@ -16,7 +16,7 @@ import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IRange } from 'vs/editor/common/core/range'; import { overviewRulerRangeHighlight } from 'vs/editor/common/view/editorColorRegistry'; import { themeColorFromId } from 'vs/platform/theme/common/themeService'; -import { IEditorOptions, RenderLineNumbersType, EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RenderLineNumbersType, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -51,7 +51,7 @@ export class GotoLineAction extends QuickOpenAction { if (isCodeEditor(activeTextEditorWidget)) { const options = activeTextEditorWidget.getOptions(); - const renderLineNumbers = options.get(EditorOptionId.renderLineNumbers); + const renderLineNumbers = options.get(EditorOption.renderLineNumbers); if (renderLineNumbers.renderType === RenderLineNumbersType.Relative) { activeTextEditorWidget.updateOptions({ lineNumbers: 'on' diff --git a/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts b/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts index 4571d5e6ef8..5708eef553f 100644 --- a/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts +++ b/src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts @@ -23,7 +23,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ILabelService } from 'vs/platform/label/common/label'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { EditorOptionId } from 'vs/editor/common/config/editorOptions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; abstract class Recording { @@ -415,7 +415,7 @@ export class BulkEditService implements IBulkEditService { } } - if (codeEditor && codeEditor.getOption(EditorOptionId.readOnly)) { + if (codeEditor && codeEditor.getOption(EditorOption.readOnly)) { // If the code editor is readonly still allow bulk edits to be applied #68549 codeEditor = undefined; } From 844c90a6ca8ee8354349d503fd960262dd83d5a6 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 3 Sep 2019 01:19:42 +0200 Subject: [PATCH 008/109] Lift editor options key name to a generic --- src/vs/editor/common/config/editorOptions.ts | 84 ++++++++++---------- src/vs/monaco.d.ts | 84 ++++++++++---------- 2 files changed, 85 insertions(+), 83 deletions(-) diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 98ce2974528..653d28714e3 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -2014,16 +2014,16 @@ export class ChangedEditorOptions { this._values[id] = value; } } +type PossibleKeyName0 = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; +type PossibleKeyName = NonNullable>; -export type PossibleKeyName = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; - -export interface IEditorOption { - readonly id: K; - readonly name: PossibleKeyName; +export interface IEditorOption, T3 = T2> { + readonly id: K1; + readonly name: K2; readonly defaultValue: T2; - read(options: IRawEditorOptionsBag): T1 | undefined; - mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; - validate(input: T1 | undefined): T2; + read(options: IRawEditorOptionsBag): IEditorOptions[K2] | undefined; + mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined; + validate(input: IEditorOptions[K2] | undefined): T2; compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; equals(a: T3, b: T3): boolean; } @@ -2033,18 +2033,18 @@ export interface IEditorOption { */ export const editorOptionsRegistry: IEditorOption[] = []; -function registerEditorOption(option: IEditorOption): IEditorOption { +function registerEditorOption(option: IEditorOption): IEditorOption { editorOptionsRegistry[option.id] = option; return option; } -export abstract class BaseEditorOption implements IEditorOption { +export abstract class BaseEditorOption implements IEditorOption { - public readonly id: K; - public readonly name: PossibleKeyName; + public readonly id: K1; + public readonly name: K2; public readonly defaultValue: T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps: EditorOption[] = []) { + constructor(id: K1, name: K2, defaultValue: T2, deps: EditorOption[] = []) { this.id = id; this.name = name; this.defaultValue = defaultValue; @@ -2052,10 +2052,10 @@ export abstract class BaseEditorOptionthis.name]; } - public mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined { + public mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined { switch (typeof b) { case 'bigint': return b; case 'boolean': return b; @@ -2067,14 +2067,14 @@ export abstract class BaseEditorOption extends BaseEditorOption { +class EditorBooleanOption> extends BaseEditorOption { public validate(input: boolean | undefined): boolean { return _boolean(input, this.defaultValue); } @@ -2083,10 +2083,10 @@ class EditorBooleanOption extends BaseEditorOption extends BaseEditorOption { +class EditorIntOption> extends BaseEditorOption { public readonly minimum: number; public readonly maximum: number; - constructor(id: K, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number, deps: EditorOption[] = []) { + constructor(id: K1, name: K2, defaultValue: number, minimum: number, maximum: number, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.minimum = minimum; this.maximum = maximum; @@ -2099,9 +2099,9 @@ class EditorIntOption extends BaseEditorOption extends BaseEditorOption { +class EditorFloatOption> extends BaseEditorOption { public readonly validationFn: (value: number) => number; - constructor(id: K, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number, deps: EditorOption[] = []) { + constructor(id: K1, name: K2, defaultValue: number, validationFn: (value: number) => number, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.validationFn = validationFn; } @@ -2113,7 +2113,7 @@ class EditorFloatOption extends BaseEditorOption extends BaseEditorOption { +class EditorStringOption> extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } @@ -2122,30 +2122,30 @@ class EditorStringOption extends BaseEditorOption extends BaseEditorOption { +class EditorEnumOption, T1 extends string, T2 = T1> extends BaseEditorOption { public readonly allowedValues: T1[]; public readonly convert: (value: T1) => T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOption[] = []) { + constructor(id: K1, name: K2, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.allowedValues = allowedValues; this.convert = convert; } - public validate(input: T1 | undefined): T1 { - return _stringSet(input, this.defaultValue, this.allowedValues); + public validate(input: IEditorOptions[K2] | undefined): T1 { + return _stringSet(input, this.defaultValue, this.allowedValues); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T1): T2 { return this.convert(value); } } -class EditorPassthroughOption extends BaseEditorOption { - public validate(input: T | undefined): T { +class EditorPassthroughOption extends BaseEditorOption { + public validate(input: IEditorOptions[K2] | undefined): IEditorOptions[K2] { if (typeof input === 'undefined') { return this.defaultValue; } return input; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T): T { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: IEditorOptions[K2]): IEditorOptions[K2] { return value; } } @@ -2167,7 +2167,7 @@ export interface InternalEditorRenderLineNumbersOptions { readonly renderFn: ((lineNumber: number) => string) | null; } -class EditorRenderLineNumbersOption extends BaseEditorOption { +class EditorRenderLineNumbersOption> extends BaseEditorOption { public validate(lineNumbers: LineNumbersType | undefined): InternalEditorRenderLineNumbersOptions { let renderType: RenderLineNumbersType = this.defaultValue.renderType; let renderFn: ((lineNumber: number) => string) | null = this.defaultValue.renderFn; @@ -2215,7 +2215,7 @@ export interface InternalEditorMinimapOptions { readonly maxColumn: number; } -class EditorMinimapOption extends BaseEditorOption { +class EditorMinimapOption> extends BaseEditorOption { public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2246,7 +2246,7 @@ class EditorMinimapOption extends BaseEditorOption extends BaseEditorOption { +class EditorAccessibilitySupportOption> extends BaseEditorOption { public validate(input: 'auto' | 'off' | 'on' | undefined): 'auto' | 'off' | 'on' { return _stringSet<'auto' | 'off' | 'on'>(input, this.defaultValue, ['auto', 'off', 'on']); } @@ -2266,7 +2266,7 @@ class EditorAccessibilitySupportOption extends BaseEdito //#region ariaLabel -class EditorAriaLabel extends BaseEditorOption { +class EditorAriaLabel> extends BaseEditorOption { public validate(input: string | undefined): string { return _string(input, this.defaultValue); } @@ -2283,7 +2283,7 @@ class EditorAriaLabel extends BaseEditorOption extends BaseEditorOption { +class EditorTabFocusMode> extends BaseEditorOption { public validate(input: undefined): undefined { return undefined; } @@ -2311,7 +2311,7 @@ export interface InternalEditorScrollbarOptions { readonly verticalSliderSize: number; } -class EditorScrollbarOption extends BaseEditorOption { +class EditorScrollbarOption> extends BaseEditorOption { public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2481,7 +2481,7 @@ export interface EditorLayoutInfo { /** * @internal */ -export class EditorLayoutInfoComputer extends BaseEditorOption { +export class EditorLayoutInfoComputer> extends BaseEditorOption { public validate(input: undefined): undefined { return undefined; } @@ -2706,7 +2706,7 @@ export interface EditorWrappingInfo { readonly wrappingColumn: number; } -class EditorWrappingInfoComputer extends BaseEditorOption { +class EditorWrappingInfoComputer> extends BaseEditorOption { public mix(a: undefined, b: undefined): undefined { return undefined; } @@ -2822,7 +2822,7 @@ export const EditorOptions = { folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), - lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), minimap: registerEditorOption(new EditorMinimapOption(EditorOption.minimap, 'minimap', { enabled: true, @@ -2851,13 +2851,13 @@ export const EditorOptions = { selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), - wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), + wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), - wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), + wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'tabFocusMode', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOption.wordWrapMinified, 'wordWrapMinified', true)), - wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), + wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), // Leave these at the end! layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.renderLineNumbers])), @@ -2867,4 +2867,4 @@ export const EditorOptions = { export type EditorOptionsType = typeof EditorOptions; export type FindEditorOptionsKeyById = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType]; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; -export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; +export type FindComputedEditorOptionValueById = NonNullable]>>; diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 3e52cdbc9a3..304261d9342 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3408,29 +3408,31 @@ declare namespace monaco.editor { get(id: T): FindComputedEditorOptionValueById; } - export type PossibleKeyName = { + type PossibleKeyName0 = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never; }[keyof IEditorOptions]; - export interface IEditorOption { - readonly id: K; - readonly name: PossibleKeyName; + type PossibleKeyName = NonNullable>; + + export interface IEditorOption, T3 = T2> { + readonly id: K1; + readonly name: K2; readonly defaultValue: T2; - read(options: IRawEditorOptionsBag): T1 | undefined; - mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; - validate(input: T1 | undefined): T2; + read(options: IRawEditorOptionsBag): IEditorOptions[K2] | undefined; + mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined; + validate(input: IEditorOptions[K2] | undefined): T2; compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; equals(a: T3, b: T3): boolean; } - export abstract class BaseEditorOption implements IEditorOption { - readonly id: K; - readonly name: PossibleKeyName; + export abstract class BaseEditorOption implements IEditorOption { + readonly id: K1; + readonly name: K2; readonly defaultValue: T2; - constructor(id: K, name: PossibleKeyName, defaultValue: T2, deps?: EditorOption[]); - read(options: IRawEditorOptionsBag): T1 | undefined; - mix(a: T1 | undefined, b: T1 | undefined): T1 | undefined; - abstract validate(input: T1 | undefined): T2; + constructor(id: K1, name: K2, defaultValue: T2, deps?: EditorOption[]); + read(options: IRawEditorOptionsBag): IEditorOptions[K2] | undefined; + mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined; + abstract validate(input: IEditorOptions[K2] | undefined): T2; abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; equals(a: T3, b: T3): boolean; } @@ -3621,32 +3623,32 @@ declare namespace monaco.editor { } export const EditorOptions: { - accessibilitySupport: IEditorOption; - ariaLabel: IEditorOption; - fastScrollSensitivity: IEditorOption; - folding: IEditorOption; - glyphMargin: IEditorOption; - inDiffEditor: IEditorOption; - lineDecorationsWidth: IEditorOption; - lineNumbersMinChars: IEditorOption; - minimap: IEditorOption; - mouseWheelScrollSensitivity: IEditorOption; - readOnly: IEditorOption; - renderFinalNewline: IEditorOption; - renderLineNumbers: IEditorOption; - scrollbar: IEditorOption; - selectionClipboard: IEditorOption; - selectOnLineNumbers: IEditorOption; - tabFocusMode: IEditorOption; - wordWrap: IEditorOption; - wordWrapBreakAfterCharacters: IEditorOption; - wordWrapBreakBeforeCharacters: IEditorOption; - wordWrapBreakObtrusiveCharacters: IEditorOption; - wordWrapColumn: IEditorOption; - wordWrapMinified: IEditorOption; - wrappingIndent: IEditorOption; - layoutInfo: IEditorOption; - wrappingInfo: IEditorOption; + accessibilitySupport: any; + ariaLabel: any; + fastScrollSensitivity: any; + folding: any; + glyphMargin: any; + inDiffEditor: any; + lineDecorationsWidth: IEditorOption; + lineNumbersMinChars: any; + minimap: any; + mouseWheelScrollSensitivity: any; + readOnly: any; + renderFinalNewline: any; + renderLineNumbers: any; + scrollbar: any; + selectionClipboard: any; + selectOnLineNumbers: any; + tabFocusMode: any; + wordWrap: any; + wordWrapBreakAfterCharacters: any; + wordWrapBreakBeforeCharacters: any; + wordWrapBreakObtrusiveCharacters: any; + wordWrapColumn: any; + wordWrapMinified: any; + wrappingIndent: any; + layoutInfo: any; + wrappingInfo: any; }; export type EditorOptionsType = typeof EditorOptions; @@ -3657,7 +3659,7 @@ declare namespace monaco.editor { export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; - export type FindComputedEditorOptionValueById = ComputedEditorOptionValue]>; + export type FindComputedEditorOptionValueById = NonNullable]>>; /** * A view zone is a full horizontal rectangle that 'pushes' text down. From 051205018f9c254d4ba761014e03cefd57954756 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 3 Sep 2019 20:55:26 +0200 Subject: [PATCH 009/109] Migrate more editor options --- src/vs/editor/browser/config/configuration.ts | 4 +- .../editor/browser/controller/mouseHandler.ts | 7 +- .../browser/controller/textAreaHandler.ts | 53 +- src/vs/editor/browser/view/viewController.ts | 5 +- src/vs/editor/browser/view/viewImpl.ts | 16 +- src/vs/editor/browser/view/viewOverlays.ts | 27 +- .../contentWidgets/contentWidgets.ts | 2 +- .../currentLineHighlight.ts | 24 +- .../currentLineMarginHighlight.ts | 25 +- .../viewParts/glyphMargin/glyphMargin.ts | 20 +- .../viewParts/indentGuides/indentGuides.ts | 33 +- .../viewParts/lineNumbers/lineNumbers.ts | 6 +- .../browser/viewParts/lines/viewLine.ts | 12 +- .../browser/viewParts/lines/viewLines.ts | 38 +- .../linesDecorations/linesDecorations.ts | 8 +- .../editor/browser/viewParts/margin/margin.ts | 17 +- .../browser/viewParts/minimap/minimap.ts | 3 +- .../overlayWidgets/overlayWidgets.ts | 17 +- .../overviewRuler/decorationsOverviewRuler.ts | 6 +- .../editor/browser/viewParts/rulers/rulers.ts | 16 +- .../scrollDecoration/scrollDecoration.ts | 29 +- .../viewParts/selections/selections.ts | 19 +- .../viewParts/viewCursors/viewCursor.ts | 25 +- .../viewParts/viewCursors/viewCursors.ts | 25 +- .../browser/viewParts/viewZones/viewZones.ts | 14 +- .../editor/browser/widget/codeEditorWidget.ts | 4 +- .../editor/browser/widget/diffEditorWidget.ts | 20 +- src/vs/editor/browser/widget/diffReview.ts | 26 +- .../common/config/commonEditorConfig.ts | 95 ++- src/vs/editor/common/config/editorOptions.ts | 660 ++++++------------ .../editor/common/controller/cursorCommon.ts | 36 +- .../common/standalone/standaloneEnums.ts | 92 ++- src/vs/editor/common/view/viewEvents.ts | 10 - src/vs/editor/common/viewLayout/viewLayout.ts | 8 +- src/vs/editor/contrib/clipboard/clipboard.ts | 7 +- src/vs/editor/contrib/dnd/dnd.ts | 5 +- src/vs/editor/contrib/find/findModel.ts | 13 +- .../goToDefinition/clickLinkGesture.ts | 7 +- .../editor/contrib/indentation/indentation.ts | 3 +- .../linesOperations/linesOperations.ts | 5 +- src/vs/editor/contrib/links/links.ts | 7 +- .../editor/contrib/multicursor/multicursor.ts | 13 +- .../wordHighlighter/wordHighlighter.ts | 3 +- .../contrib/wordOperations/wordOperations.ts | 16 +- src/vs/editor/editor.api.ts | 8 +- src/vs/monaco.d.ts | 204 +++--- .../workbench/api/browser/mainThreadEditor.ts | 7 +- .../browser/preferencesRenderers.ts | 5 +- .../quickopen/browser/gotoLineHandler.ts | 4 +- 49 files changed, 748 insertions(+), 961 deletions(-) diff --git a/src/vs/editor/browser/config/configuration.ts b/src/vs/editor/browser/config/configuration.ts index cdb50af8be8..8e8a71d3345 100644 --- a/src/vs/editor/browser/config/configuration.ts +++ b/src/vs/editor/browser/config/configuration.ts @@ -11,7 +11,7 @@ import * as platform from 'vs/base/common/platform'; import { CharWidthRequest, CharWidthRequestType, readCharWidths } from 'vs/editor/browser/config/charWidthReader'; import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver'; import { CommonEditorConfiguration, IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import { IDimension } from 'vs/editor/common/editorCommon'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; @@ -320,7 +320,7 @@ export class Configuration extends CommonEditorConfiguration { this._register(CSSBasedConfiguration.INSTANCE.onDidChange(() => this._onCSSBasedConfigurationChanged())); - if (this._validatedOptions.automaticLayout) { + if (this._validatedOptions2.get(EditorOption.automaticLayout)) { this._elementSizeObserver.startObserving(); } diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index f9b2f538465..dd8979daabc 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -113,7 +113,7 @@ export class MouseHandler extends ViewEventHandler { const onMouseWheel = (browserEvent: IMouseWheelEvent) => { this.viewController.emitMouseWheel(browserEvent); - if (!this._context.configuration.editor.viewInfo.mouseWheelZoom) { + if (!this._context.configuration.options.get(EditorOption.mouseWheelZoom)) { return; } const e = new StandardWheelEvent(browserEvent); @@ -354,10 +354,9 @@ class MouseDownOperation extends Disposable { e.detail = this._mouseState.count; const options = this._context.configuration.options; - const readOnly = options.get(EditorOption.readOnly); - if (!readOnly - && this._context.configuration.editor.dragAndDrop + if (!options.get(EditorOption.readOnly) + && options.get(EditorOption.dragAndDrop) && !this._mouseState.altKey // we don't support multiple mouse && e.detail < 2 // only single click on a selection can work && !this._isActive // the mouse is not down yet diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index 347cd523a81..4919390e33b 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -91,12 +91,13 @@ export class TextAreaHandler extends ViewPart { private readonly _viewController: ViewController; private readonly _viewHelper: ITextAreaHandlerHelper; + private _scrollLeft: number; + private _scrollTop: number; + private _accessibilitySupport: AccessibilitySupport; private _contentLeft: number; private _contentWidth: number; private _contentHeight: number; - private _scrollLeft: number; - private _scrollTop: number; private _fontInfo: BareFontInfo; private _lineHeight: number; private _emptySelectionClipboard: boolean; @@ -117,6 +118,8 @@ export class TextAreaHandler extends ViewPart { this._viewController = viewController; this._viewHelper = viewHelper; + this._scrollLeft = 0; + this._scrollTop = 0; const conf = this._context.configuration.editor; const options = this._context.configuration.options; @@ -126,12 +129,10 @@ export class TextAreaHandler extends ViewPart { this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; - this._scrollLeft = 0; - this._scrollTop = 0; this._fontInfo = conf.fontInfo; this._lineHeight = conf.lineHeight; - this._emptySelectionClipboard = conf.emptySelectionClipboard; - this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting; + this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); + this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); this._visibleTextArea = null; this._selections = [new Selection(1, 1, 1, 1)]; @@ -342,7 +343,7 @@ export class TextAreaHandler extends ViewPart { private _getWordBeforePosition(position: Position): string { const lineContent = this._context.model.getLineContent(position.lineNumber); - const wordSeparators = getMapForWordSeparators(this._context.configuration.editor.wordSeparators); + const wordSeparators = getMapForWordSeparators(this._context.configuration.options.get(EditorOption.wordSeparators)); let column = position.column; let distance = 0; @@ -374,32 +375,21 @@ export class TextAreaHandler extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const conf = this._context.configuration.editor; const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + + this._accessibilitySupport = options.get(EditorOption.accessibilitySupport); + this._contentLeft = layoutInfo.contentLeft; + this._contentWidth = layoutInfo.contentWidth; + this._contentHeight = layoutInfo.contentHeight; + this._fontInfo = conf.fontInfo; + this._lineHeight = conf.lineHeight; + this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); + this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); + this.textArea.setAttribute('aria-label', options.get(EditorOption.ariaLabel)); - if (e.fontInfo) { - this._fontInfo = conf.fontInfo; - } - if (e.viewInfo) { - this.textArea.setAttribute('aria-label', options.get(EditorOption.ariaLabel)); - } - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentLeft = layoutInfo.contentLeft; - this._contentWidth = layoutInfo.contentWidth; - this._contentHeight = layoutInfo.contentHeight; - } - if (e.lineHeight) { - this._lineHeight = conf.lineHeight; - } if (e.hasChanged(EditorOption.accessibilitySupport)) { - this._accessibilitySupport = options.get(EditorOption.accessibilitySupport); this._textAreaInput.writeScreenReaderContent('strategy changed'); } - if (e.emptySelectionClipboard) { - this._emptySelectionClipboard = conf.emptySelectionClipboard; - } - if (e.copyWithSyntaxHighlighting) { - this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting; - } return true; } @@ -550,11 +540,10 @@ export class TextAreaHandler extends ViewPart { const options = this._context.configuration.options; - if (this._context.configuration.editor.viewInfo.glyphMargin) { + if (options.get(EditorOption.glyphMargin)) { tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME); } else { - const renderLineNumbers = options.get(EditorOption.renderLineNumbers); - if (renderLineNumbers.renderType !== RenderLineNumbersType.Off) { + if (options.get(EditorOption.lineNumbers).renderType !== RenderLineNumbersType.Off) { tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME); } else { tac.setClassName('monaco-editor-background textAreaCover'); diff --git a/src/vs/editor/browser/view/viewController.ts b/src/vs/editor/browser/view/viewController.ts index 10fb2e1aa6b..610f54266f6 100644 --- a/src/vs/editor/browser/view/viewController.ts +++ b/src/vs/editor/browser/view/viewController.ts @@ -12,6 +12,7 @@ import { Selection } from 'vs/editor/common/core/selection'; import { IConfiguration } from 'vs/editor/common/editorCommon'; import { IViewModel } from 'vs/editor/common/viewModel/viewModel'; import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IMouseDispatchData { position: Position; @@ -107,7 +108,7 @@ export class ViewController { } private _hasMulticursorModifier(data: IMouseDispatchData): boolean { - switch (this.configuration.editor.multiCursorModifier) { + switch (this.configuration.options.get(EditorOption.multiCursorModifier)) { case 'altKey': return data.altKey; case 'ctrlKey': @@ -119,7 +120,7 @@ export class ViewController { } private _hasNonMulticursorModifier(data: IMouseDispatchData): boolean { - switch (this.configuration.editor.multiCursorModifier) { + switch (this.configuration.options.get(EditorOption.multiCursorModifier)) { case 'altKey': return data.ctrlKey || data.metaKey; case 'ctrlKey': diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 2a31441bc86..9f2e96a1a38 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -220,7 +220,7 @@ export class View extends ViewEventHandler { this.domNode.appendChild(this.overflowGuardContainer); this.domNode.appendChild(this.contentWidgets.overflowingContentWidgetsDomNode); - this._setLayout(); + this._applyLayout(); // Pointer handler this.pointerHandler = this._register(new PointerHandler(this._context, viewController, this.createPointerHandlerHelper())); @@ -282,9 +282,10 @@ export class View extends ViewEventHandler { }; } - private _setLayout(): void { + private _applyLayout(): void { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); + this.domNode.setWidth(layoutInfo.width); this.domNode.setHeight(layoutInfo.height); @@ -293,23 +294,18 @@ export class View extends ViewEventHandler { this.linesContent.setWidth(1000000); this.linesContent.setHeight(1000000); - } private getEditorClassName() { const focused = this._textAreaHandler.isFocused() ? ' focused' : ''; - return this._context.configuration.editor.editorClassName + ' ' + getThemeTypeSelector(this._context.theme.type) + focused; + return this._context.configuration.options.get(EditorOption.editorClassName) + ' ' + getThemeTypeSelector(this._context.theme.type) + focused; } // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.editorClassName) { - this.domNode.setClassName(this.getEditorClassName()); - } - if (e.hasChanged(EditorOption.layoutInfo)) { - this._setLayout(); - } + this.domNode.setClassName(this.getEditorClassName()); + this._applyLayout(); return false; } public onFocusChanged(e: viewEvents.ViewFocusChangedEvent): boolean { diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index bf7fed99d46..1145334be17 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -227,12 +227,10 @@ export class ContentViewOverlays extends ViewOverlays { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentWidth = layoutInfo.contentWidth; - } - return super.onConfigurationChanged(e); + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + this._contentWidth = layoutInfo.contentWidth; + return super.onConfigurationChanged(e) || true; } public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { return super.onScrollChanged(e) || e.scrollWidthChanged; @@ -265,18 +263,11 @@ export class MarginViewOverlays extends ViewOverlays { } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - let shouldRender = false; - if (e.fontInfo) { - Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); - shouldRender = true; - } - if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentLeft = layoutInfo.contentLeft; - shouldRender = true; - } - return super.onConfigurationChanged(e) || shouldRender; + Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + this._contentLeft = layoutInfo.contentLeft; + return super.onConfigurationChanged(e) || true; } public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index 74ca7cbd66a..721a7ff2acb 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -212,7 +212,7 @@ class Widget { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._fixedOverflowWidgets = this._context.configuration.editor.viewInfo.fixedOverflowWidgets; + this._fixedOverflowWidgets = options.get(EditorOption.fixedOverflowWidgets); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; this._lineHeight = this._context.configuration.editor.lineHeight; diff --git a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts index 41cb1c2080c..448aff03d52 100644 --- a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts @@ -17,25 +17,26 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; private _lineHeight: number; private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; + private _contentWidth: number; private _selectionIsEmpty: boolean; private _primaryCursorLineNumber: number; private _scrollWidth: number; - private _contentWidth: number; constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); this._lineHeight = this._context.configuration.editor.lineHeight; - this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; + this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); + this._contentWidth = layoutInfo.contentWidth; this._selectionIsEmpty = true; this._primaryCursorLineNumber = 1; this._scrollWidth = 0; - this._contentWidth = layoutInfo.contentWidth; this._context.addEventHandler(this); } @@ -48,17 +49,12 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.viewInfo) { - this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; - } - if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentWidth = layoutInfo.contentWidth; - } + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + + this._lineHeight = this._context.configuration.editor.lineHeight; + this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); + this._contentWidth = layoutInfo.contentWidth; return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts index e6d01e2ebcf..17a473d86b4 100644 --- a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts @@ -17,21 +17,23 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { private readonly _context: ViewContext; private _lineHeight: number; private _renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; + private _contentLeft: number; private _selectionIsEmpty: boolean; private _primaryCursorLineNumber: number; - private _contentLeft: number; constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); + this._lineHeight = this._context.configuration.editor.lineHeight; - this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; + this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); + this._contentLeft = layoutInfo.contentLeft; this._selectionIsEmpty = true; this._primaryCursorLineNumber = 1; - this._contentLeft = layoutInfo.contentLeft; this._context.addEventHandler(this); } @@ -44,17 +46,12 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.viewInfo) { - this._renderLineHighlight = this._context.configuration.editor.viewInfo.renderLineHighlight; - } - if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._context.configuration.options; - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentLeft = layoutInfo.contentLeft; - } + const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + + this._lineHeight = this._context.configuration.editor.lineHeight; + this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); + this._contentLeft = layoutInfo.contentLeft; return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts index a402d430826..7bc4e31bd2e 100644 --- a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts +++ b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts @@ -86,10 +86,12 @@ export class GlyphMarginOverlay extends DedupOverlay { constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); + this._lineHeight = this._context.configuration.editor.lineHeight; - this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; + this._glyphMargin = options.get(EditorOption.glyphMargin); this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; this._renderResult = null; @@ -106,18 +108,12 @@ export class GlyphMarginOverlay extends DedupOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.viewInfo) { - this._glyphMargin = this._context.configuration.editor.viewInfo.glyphMargin; - } - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._glyphMarginLeft = layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = layoutInfo.glyphMarginWidth; - } + this._lineHeight = this._context.configuration.editor.lineHeight; + this._glyphMargin = options.get(EditorOption.glyphMargin); + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; return true; } public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index fb275d96ba3..705700fc6d6 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -29,14 +29,15 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { super(); this._context = context; this._primaryLineNumber = 0; + const options = this._context.configuration.options; + const wrappingInfo = options.get(EditorOption.wrappingInfo); + this._lineHeight = this._context.configuration.editor.lineHeight; this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; - this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; - this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; - const wrappingInfo = options.get(EditorOption.wrappingInfo); - const wrappingColumn = wrappingInfo.wrappingColumn; - this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); + this._enabled = options.get(EditorOption.renderIndentGuides); + this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); + this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); this._renderResult = null; @@ -53,21 +54,13 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.fontInfo) { - this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; - } - if (e.viewInfo) { - this._enabled = this._context.configuration.editor.viewInfo.renderIndentGuides; - this._activeIndentEnabled = this._context.configuration.editor.viewInfo.highlightActiveIndentGuide; - } - if (e.hasChanged(EditorOption.wrappingInfo) || e.fontInfo) { - const wrappingInfo = options.get(EditorOption.wrappingInfo); - const wrappingColumn = wrappingInfo.wrappingColumn; - this._maxIndentLeft = wrappingColumn === -1 ? -1 : (wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); - } + const wrappingInfo = options.get(EditorOption.wrappingInfo); + + this._lineHeight = this._context.configuration.editor.lineHeight; + this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; + this._enabled = options.get(EditorOption.renderIndentGuides); + this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); + this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index 8673e31f153..1d5e6508062 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -44,9 +44,9 @@ export class LineNumbersOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const config = this._context.configuration.editor; this._lineHeight = config.lineHeight; - const renderLineNumbers = options.get(EditorOption.renderLineNumbers); - this._renderLineNumbers = renderLineNumbers.renderType; - this._renderCustomLineNumbers = renderLineNumbers.renderFn; + const lineNumbers = options.get(EditorOption.lineNumbers); + this._renderLineNumbers = lineNumbers.renderType; + this._renderCustomLineNumbers = lineNumbers.renderFn; this._renderFinalNewline = options.get(EditorOption.renderFinalNewline); const layoutInfo = options.get(EditorOption.layoutInfo); this._lineNumbersLeft = layoutInfo.lineNumbersLeft; diff --git a/src/vs/editor/browser/viewParts/lines/viewLine.ts b/src/vs/editor/browser/viewParts/lines/viewLine.ts index 00b684e7ef4..25e861bf9c6 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLine.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLine.ts @@ -16,6 +16,7 @@ import { CharacterMapping, ForeignElementType, RenderLineInput, renderViewLine, import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel'; import { HIGH_CONTRAST, ThemeType } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const canUseFastRenderedViewLine = (function () { if (platform.isNative) { @@ -80,17 +81,18 @@ export class ViewLineOptions { constructor(config: IConfiguration, themeType: ThemeType) { this.themeType = themeType; - this.renderWhitespace = config.editor.viewInfo.renderWhitespace; - this.renderControlCharacters = config.editor.viewInfo.renderControlCharacters; + const options = config.options; + this.renderWhitespace = options.get(EditorOption.renderWhitespace); + this.renderControlCharacters = options.get(EditorOption.renderControlCharacters); this.spaceWidth = config.editor.fontInfo.spaceWidth; this.useMonospaceOptimizations = ( config.editor.fontInfo.isMonospace - && !config.editor.viewInfo.disableMonospaceOptimizations + && !options.get(EditorOption.disableMonospaceOptimizations) ); this.canUseHalfwidthRightwardsArrow = config.editor.fontInfo.canUseHalfwidthRightwardsArrow; this.lineHeight = config.editor.lineHeight; - this.stopRenderingLineAfter = config.editor.viewInfo.stopRenderingLineAfter; - this.fontLigatures = config.editor.viewInfo.fontLigatures; + this.stopRenderingLineAfter = options.get(EditorOption.stopRenderingLineAfter); + this.fontLigatures = options.get(EditorOption.fontLigatures); } public equals(other: ViewLineOptions): boolean { diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 7fff4453ba5..5eaf46c3eea 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -72,7 +72,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, private _typicalHalfwidthCharacterWidth: number; private _isViewportWrapping: boolean; private _revealHorizontalRightPadding: number; - private _scrollOff: number; + private _cursorSurroundingLines: number; private _canUseLayerHinting: boolean; private _viewLineOptions: ViewLineOptions; @@ -97,9 +97,9 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this._lineHeight = conf.editor.lineHeight; this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; this._isViewportWrapping = wrappingInfo.isViewportWrapping; - this._revealHorizontalRightPadding = conf.editor.viewInfo.revealHorizontalRightPadding; - this._scrollOff = conf.editor.viewInfo.cursorSurroundingLines; - this._canUseLayerHinting = conf.editor.canUseLayerHinting; + this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); + this._cursorSurroundingLines = options.get(EditorOption.cursorSurroundingLines); + this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting); this._viewLineOptions = new ViewLineOptions(conf, this._context.theme.type); PartFingerprints.write(this.domNode, PartFingerprint.ViewLines); @@ -144,27 +144,15 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const conf = this._context.configuration; const options = this._context.configuration.options; + const wrappingInfo = options.get(EditorOption.wrappingInfo); - if (e.lineHeight) { - this._lineHeight = conf.editor.lineHeight; - } - if (e.fontInfo) { - this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; - } - if (e.hasChanged(EditorOption.wrappingInfo)) { - const wrappingInfo = options.get(EditorOption.wrappingInfo); - this._isViewportWrapping = wrappingInfo.isViewportWrapping; - } - if (e.viewInfo) { - this._revealHorizontalRightPadding = conf.editor.viewInfo.revealHorizontalRightPadding; - this._scrollOff = conf.editor.viewInfo.cursorSurroundingLines; - } - if (e.canUseLayerHinting) { - this._canUseLayerHinting = conf.editor.canUseLayerHinting; - } - if (e.fontInfo) { - Configuration.applyFontInfo(this.domNode, conf.editor.fontInfo); - } + this._lineHeight = conf.editor.lineHeight; + this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._isViewportWrapping = wrappingInfo.isViewportWrapping; + this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); + this._cursorSurroundingLines = options.get(EditorOption.cursorSurroundingLines); + this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting); + Configuration.applyFontInfo(this.domNode, conf.editor.fontInfo); this._onOptionsMaybeChanged(); @@ -605,7 +593,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, boxStartY = this._context.viewLayout.getVerticalOffsetForLineNumber(range.startLineNumber); boxEndY = this._context.viewLayout.getVerticalOffsetForLineNumber(range.endLineNumber) + this._lineHeight; - const context = Math.min((viewportHeight / this._lineHeight) / 2, this._scrollOff); + const context = Math.min((viewportHeight / this._lineHeight) / 2, this._cursorSurroundingLines); boxStartY -= context * this._lineHeight; boxEndY += Math.max(0, (context - 1)) * this._lineHeight; diff --git a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts index c8ad48eb26f..fc6a255eb83 100644 --- a/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts +++ b/src/vs/editor/browser/viewParts/linesDecorations/linesDecorations.ts @@ -40,11 +40,9 @@ export class LinesDecorationsOverlay extends DedupOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._decorationsLeft = layoutInfo.decorationsLeft; - this._decorationsWidth = layoutInfo.decorationsWidth; - } + const layoutInfo = options.get(EditorOption.layoutInfo); + this._decorationsLeft = layoutInfo.decorationsLeft; + this._decorationsWidth = layoutInfo.decorationsWidth; return true; } public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/margin/margin.ts b/src/vs/editor/browser/viewParts/margin/margin.ts index 2710a194dd0..1208e3c56c9 100644 --- a/src/vs/editor/browser/viewParts/margin/margin.ts +++ b/src/vs/editor/browser/viewParts/margin/margin.ts @@ -28,7 +28,7 @@ export class Margin extends ViewPart { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; + this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting); this._contentLeft = layoutInfo.contentLeft; this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; @@ -57,17 +57,12 @@ export class Margin extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); - if (e.canUseLayerHinting) { - this._canUseLayerHinting = this._context.configuration.editor.canUseLayerHinting; - } - - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentLeft = layoutInfo.contentLeft; - this._glyphMarginLeft = layoutInfo.glyphMarginLeft; - this._glyphMarginWidth = layoutInfo.glyphMarginWidth; - } + this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting); + this._contentLeft = layoutInfo.contentLeft; + this._glyphMarginLeft = layoutInfo.glyphMarginLeft; + this._glyphMarginWidth = layoutInfo.glyphMarginWidth; return true; } diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index 7df0b183c3c..01d3721a179 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -110,11 +110,10 @@ class MinimapOptions { const options = configuration.options; const pixelRatio = configuration.editor.pixelRatio; const layoutInfo = options.get(EditorOption.layoutInfo); - const viewInfo = configuration.editor.viewInfo; const fontInfo = configuration.editor.fontInfo; this.renderMinimap = layoutInfo.renderMinimap | 0; - this.scrollBeyondLastLine = viewInfo.scrollBeyondLastLine; + this.scrollBeyondLastLine = options.get(EditorOption.scrollBeyondLastLine); const minimapOpts = options.get(EditorOption.minimap); this.showSlider = minimapOpts.showSlider; this.pixelRatio = pixelRatio; diff --git a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts index ba9128c06de..925ed44d28a 100644 --- a/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts +++ b/src/vs/editor/browser/viewParts/overlayWidgets/overlayWidgets.ts @@ -65,17 +65,14 @@ export class ViewOverlayWidgets extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; - this._minimapWidth = layoutInfo.minimapWidth; - this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; - this._editorHeight = layoutInfo.height; - this._editorWidth = layoutInfo.width; - return true; - } - return false; + this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth; + this._minimapWidth = layoutInfo.minimapWidth; + this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight; + this._editorHeight = layoutInfo.height; + this._editorWidth = layoutInfo.width; + return true; } // ---- end view event handlers diff --git a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts index 2f02db4df43..7658dfbf33c 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts @@ -46,13 +46,13 @@ class Settings { const options = config.options; this.lineHeight = config.editor.lineHeight; this.pixelRatio = config.editor.pixelRatio; - this.overviewRulerLanes = config.editor.viewInfo.overviewRulerLanes; + this.overviewRulerLanes = options.get(EditorOption.overviewRulerLanes); - this.renderBorder = config.editor.viewInfo.overviewRulerBorder; + this.renderBorder = options.get(EditorOption.overviewRulerBorder); const borderColor = theme.getColor(editorOverviewRulerBorder); this.borderColor = borderColor ? borderColor.toString() : null; - this.hideCursor = config.editor.viewInfo.hideCursorInOverviewRuler; + this.hideCursor = options.get(EditorOption.hideCursorInOverviewRuler); const cursorColor = theme.getColor(editorCursorForeground); this.cursorColor = cursorColor ? cursorColor.transparent(0.7).toString() : null; diff --git a/src/vs/editor/browser/viewParts/rulers/rulers.ts b/src/vs/editor/browser/viewParts/rulers/rulers.ts index 21981080a0e..3c9f9cf6bb5 100644 --- a/src/vs/editor/browser/viewParts/rulers/rulers.ts +++ b/src/vs/editor/browser/viewParts/rulers/rulers.ts @@ -27,7 +27,8 @@ export class Rulers extends ViewPart { this.domNode.setAttribute('aria-hidden', 'true'); this.domNode.setClassName('view-rulers'); this._renderedRulers = []; - this._rulers = this._context.configuration.editor.viewInfo.rulers; + const options = this._context.configuration.options; + this._rulers = options.get(EditorOption.rulers); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; } @@ -38,15 +39,10 @@ export class Rulers extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.viewInfo - || e.hasChanged(EditorOption.layoutInfo) - || e.fontInfo - ) { - this._rulers = this._context.configuration.editor.viewInfo.rulers; - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; - return true; - } - return false; + const options = this._context.configuration.options; + this._rulers = options.get(EditorOption.rulers); + this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + return true; } public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { return e.scrollHeightChanged; diff --git a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts index 7e516f8e221..8adefd837dd 100644 --- a/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts +++ b/src/vs/editor/browser/viewParts/scrollDecoration/scrollDecoration.ts @@ -54,35 +54,26 @@ export class ScrollDecorationViewPart extends ViewPart { return this._domNode; } - private _updateWidth(): boolean { + private _updateWidth(): void { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - let newWidth = 0; + if (layoutInfo.renderMinimap === 0 || (layoutInfo.minimapWidth > 0 && layoutInfo.minimapLeft === 0)) { - newWidth = layoutInfo.width; + this._width = layoutInfo.width; } else { - newWidth = layoutInfo.width - layoutInfo.minimapWidth - layoutInfo.verticalScrollbarWidth; + this._width = layoutInfo.width - layoutInfo.minimapWidth - layoutInfo.verticalScrollbarWidth; } - if (this._width !== newWidth) { - this._width = newWidth; - return true; - } - return false; } // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - let shouldRender = false; - if (e.hasChanged(EditorOption.scrollbar)) { - const options = this._context.configuration.options; - const scrollbar = options.get(EditorOption.scrollbar); - this._useShadows = scrollbar.useShadows; - } - if (e.hasChanged(EditorOption.layoutInfo)) { - shouldRender = this._updateWidth(); - } - return this._updateShouldShow() || shouldRender; + const options = this._context.configuration.options; + const scrollbar = options.get(EditorOption.scrollbar); + this._useShadows = scrollbar.useShadows; + this._updateWidth(); + this._updateShouldShow(); + return true; } public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { this._scrollTop = e.scrollTop; diff --git a/src/vs/editor/browser/viewParts/selections/selections.ts b/src/vs/editor/browser/viewParts/selections/selections.ts index 3ee089a3d94..1c1cd7fdd48 100644 --- a/src/vs/editor/browser/viewParts/selections/selections.ts +++ b/src/vs/editor/browser/viewParts/selections/selections.ts @@ -12,6 +12,7 @@ import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { editorInactiveSelection, editorSelectionBackground, editorSelectionForeground } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const enum CornerStyle { EXTERN, @@ -83,8 +84,9 @@ export class SelectionsOverlay extends DynamicViewOverlay { constructor(context: ViewContext) { super(); this._context = context; + const options = this._context.configuration.options; this._lineHeight = this._context.configuration.editor.lineHeight; - this._roundedSelection = this._context.configuration.editor.viewInfo.roundedSelection; + this._roundedSelection = options.get(EditorOption.roundedSelection); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this._selections = []; this._renderResult = null; @@ -100,15 +102,10 @@ export class SelectionsOverlay extends DynamicViewOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.viewInfo) { - this._roundedSelection = this._context.configuration.editor.viewInfo.roundedSelection; - } - if (e.fontInfo) { - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; - } + const options = this._context.configuration.options; + this._lineHeight = this._context.configuration.editor.lineHeight; + this._roundedSelection = options.get(EditorOption.roundedSelection); + this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { @@ -420,4 +417,4 @@ registerThemingParticipant((theme, collector) => { function abs(n: number): number { return n < 0 ? -n : n; -} \ No newline at end of file +} diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts index 37105276557..491943b8fb6 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts @@ -7,7 +7,7 @@ import * as dom from 'vs/base/browser/dom'; import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import * as strings from 'vs/base/common/strings'; import { Configuration } from 'vs/editor/browser/config/configuration'; -import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions'; +import { TextEditorCursorStyle, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext'; @@ -51,11 +51,12 @@ export class ViewCursor { constructor(context: ViewContext) { this._context = context; + const options = this._context.configuration.options; - this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; + this._cursorStyle = options.get(EditorOption.cursorStyle); this._lineHeight = this._context.configuration.editor.lineHeight; this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; - this._lineCursorWidth = Math.min(this._context.configuration.editor.viewInfo.cursorWidth, this._typicalHalfwidthCharacterWidth); + this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); this._isVisible = true; @@ -97,17 +98,13 @@ export class ViewCursor { } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } - if (e.fontInfo) { - Configuration.applyFontInfo(this._domNode, this._context.configuration.editor.fontInfo); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; - } - if (e.viewInfo) { - this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; - this._lineCursorWidth = Math.min(this._context.configuration.editor.viewInfo.cursorWidth, this._typicalHalfwidthCharacterWidth); - } + const options = this._context.configuration.options; + + this._cursorStyle = options.get(EditorOption.cursorStyle); + this._lineHeight = this._context.configuration.editor.lineHeight; + this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); + Configuration.applyFontInfo(this._domNode, this._context.configuration.editor.fontInfo); return true; } diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts index f9dc4932f76..c60e020b56f 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts @@ -45,9 +45,9 @@ export class ViewCursors extends ViewPart { const options = this._context.configuration.options; this._readOnly = options.get(EditorOption.readOnly); - this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; - this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; - this._cursorSmoothCaretAnimation = this._context.configuration.editor.viewInfo.cursorSmoothCaretAnimation; + this._cursorBlinking = options.get(EditorOption.cursorBlinking); + this._cursorStyle = options.get(EditorOption.cursorStyle); + this._cursorSmoothCaretAnimation = options.get(EditorOption.cursorSmoothCaretAnimation); this._selectionIsEmpty = true; this._isVisible = false; @@ -87,20 +87,15 @@ export class ViewCursors extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - if (e.hasChanged(EditorOption.readOnly)) { - this._readOnly = options.get(EditorOption.readOnly); - } - if (e.viewInfo) { - this._cursorBlinking = this._context.configuration.editor.viewInfo.cursorBlinking; - this._cursorStyle = this._context.configuration.editor.viewInfo.cursorStyle; - this._cursorSmoothCaretAnimation = this._context.configuration.editor.viewInfo.cursorSmoothCaretAnimation; - } + this._readOnly = options.get(EditorOption.readOnly); + this._cursorBlinking = options.get(EditorOption.cursorBlinking); + this._cursorStyle = options.get(EditorOption.cursorStyle); + this._cursorSmoothCaretAnimation = options.get(EditorOption.cursorSmoothCaretAnimation); + + this._updateBlinking(); + this._updateDomClassName(); this._primaryCursor.onConfigurationChanged(e); - this._updateBlinking(); - if (e.viewInfo) { - this._updateDomClassName(); - } for (let i = 0, len = this._secondaryCursors.length; i < len; i++) { this._secondaryCursors[i].onConfigurationChanged(e); } diff --git a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts index ed6976ba9fa..8bac486f4bc 100644 --- a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts +++ b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts @@ -90,16 +90,14 @@ export class ViewZones extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; + const layoutInfo = options.get(EditorOption.layoutInfo); + + this._lineHeight = this._context.configuration.editor.lineHeight; + this._contentWidth = layoutInfo.contentWidth; + this._contentLeft = layoutInfo.contentLeft; if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - return this._recomputeWhitespacesProps(); - } - - if (e.hasChanged(EditorOption.layoutInfo)) { - const layoutInfo = options.get(EditorOption.layoutInfo); - this._contentWidth = layoutInfo.contentWidth; - this._contentLeft = layoutInfo.contentLeft; + this._recomputeWhitespacesProps(); } return true; diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index cdc154e5521..65f10d2f316 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -259,12 +259,12 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._register(this._configuration.onDidChange((e) => { this._onDidChangeConfiguration.fire(e); + const options = this._configuration.options; if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); this._onDidLayoutChange.fire(layoutInfo); } - if (this._configuration.editor.showUnused) { + if (options.get(EditorOption.showUnused)) { this._domElement.classList.add(SHOW_UNUSED_ENABLED_CLASS); } else { this._domElement.classList.remove(SHOW_UNUSED_ENABLED_CLASS); diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index c07f9ec9552..fd704dbd5d2 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -20,7 +20,7 @@ import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffReview } from 'vs/editor/browser/widget/diffReview'; -import { IDiffEditorOptions, IEditorOptions, EDITOR_DEFAULTS, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { IDiffEditorOptions, IEditorOptions, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption, EditorOptions } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -996,7 +996,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE private _adjustOptionsForRightHandSide(options: IDiffEditorOptions): IEditorOptions { let result = this._adjustOptionsForSubEditor(options); - result.revealHorizontalRightPadding = EDITOR_DEFAULTS.viewInfo.revealHorizontalRightPadding + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH; + result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + DiffEditorWidget.ENTIRE_DIFF_OVERVIEW_WIDTH; result.scrollbar!.verticalHasArrows = false; result.extraEditorClassName = 'modified-in-monaco-diff-editor'; return result; @@ -2003,7 +2003,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { let maxCharsPerLine = 0; const originalContent: string[] = []; for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) { - maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorConfiguration, this.modifiedEditorTabSize, lineNumber, decorations, sb)); + maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorConfiguration, this.modifiedEditorOptions, this.modifiedEditorTabSize, lineNumber, decorations, sb)); originalContent.push(this.originalModel.getLineContent(lineNumber)); if (this.renderIndicators) { @@ -2013,7 +2013,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { ]); } } - maxCharsPerLine += this.modifiedEditorConfiguration.viewInfo.scrollBeyondLastColumn; + maxCharsPerLine += this.modifiedEditorOptions.get(EditorOption.scrollBeyondLastColumn); let domNode = document.createElement('div'); domNode.className = 'view-lines line-delete'; @@ -2042,7 +2042,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { }; } - private _renderOriginalLine(count: number, originalModel: ITextModel, config: InternalEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { + private _renderOriginalLine(count: number, originalModel: ITextModel, config: InternalEditorOptions, options: IComputedEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { const lineTokens = originalModel.getLineTokens(lineNumber); const lineContent = lineTokens.getLineContent(); @@ -2060,7 +2060,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, originalModel.mightContainNonBasicASCII()); const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, originalModel.mightContainRTL()); const output = renderViewLine(new RenderLineInput( - (config.fontInfo.isMonospace && !config.viewInfo.disableMonospaceOptimizations), + (config.fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), config.fontInfo.canUseHalfwidthRightwardsArrow, lineContent, false, @@ -2071,10 +2071,10 @@ class InlineViewZonesComputer extends ViewZonesComputer { actualDecorations, tabSize, config.fontInfo.spaceWidth, - config.viewInfo.stopRenderingLineAfter, - config.viewInfo.renderWhitespace, - config.viewInfo.renderControlCharacters, - config.viewInfo.fontLigatures, + options.get(EditorOption.stopRenderingLineAfter), + options.get(EditorOption.renderWhitespace), + options.get(EditorOption.renderControlCharacters), + options.get(EditorOption.fontLigatures), null // Send no selections, original line cannot be selected ), sb); diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index 63eba820ab8..c2b32e4c5ae 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -17,7 +17,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { InternalEditorOptions, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { LineTokens } from 'vs/editor/common/core/lineTokens'; import { Position } from 'vs/editor/common/core/position'; import { ILineChange, ScrollType } from 'vs/editor/common/editorCommon'; @@ -635,8 +635,8 @@ export class DiffReview extends Disposable { private static _renderSection( dest: HTMLElement, diffEntry: DiffEntry, modLine: number, width: number, - originalOpts: editorOptions.InternalEditorOptions, originalOptions: editorOptions.IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, - modifiedOpts: editorOptions.InternalEditorOptions, modifiedOptions: editorOptions.IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions + originalOpts: InternalEditorOptions, originalOptions: IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, + modifiedOpts: InternalEditorOptions, modifiedOptions: IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions ): void { const type = diffEntry.getType(); @@ -667,10 +667,10 @@ export class DiffReview extends Disposable { originalLineEnd - originalLineStart ); - const originalLayoutInfo = originalOptions.get(editorOptions.EditorOption.layoutInfo); + const originalLayoutInfo = originalOptions.get(EditorOption.layoutInfo); const originalLineNumbersWidth = originalLayoutInfo.glyphMarginWidth + originalLayoutInfo.lineNumbersWidth; - const modifiedLayoutInfo = modifiedOptions.get(editorOptions.EditorOption.layoutInfo); + const modifiedLayoutInfo = modifiedOptions.get(EditorOption.layoutInfo); const modifiedLineNumbersWidth = 10 + modifiedLayoutInfo.glyphMarginWidth + modifiedLayoutInfo.lineNumbersWidth; for (let i = 0; i <= cnt; i++) { @@ -721,12 +721,12 @@ export class DiffReview extends Disposable { let lineContent: string; if (modifiedLine !== 0) { cell.insertAdjacentHTML('beforeend', - this._renderLine(modifiedModel, modifiedOpts, modifiedModelOpts.tabSize, modifiedLine) + this._renderLine(modifiedModel, modifiedOpts, modifiedOptions, modifiedModelOpts.tabSize, modifiedLine) ); lineContent = modifiedModel.getLineContent(modifiedLine); } else { cell.insertAdjacentHTML('beforeend', - this._renderLine(originalModel, originalOpts, originalModelOpts.tabSize, originalLine) + this._renderLine(originalModel, originalOpts, originalOptions, originalModelOpts.tabSize, originalLine) ); lineContent = originalModel.getLineContent(originalLine); } @@ -753,7 +753,7 @@ export class DiffReview extends Disposable { } } - private static _renderLine(model: ITextModel, config: editorOptions.InternalEditorOptions, tabSize: number, lineNumber: number): string { + private static _renderLine(model: ITextModel, config: InternalEditorOptions, options: IComputedEditorOptions, tabSize: number, lineNumber: number): string { const lineContent = model.getLineContent(lineNumber); const defaultMetadata = ( @@ -771,7 +771,7 @@ export class DiffReview extends Disposable { const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, model.mightContainNonBasicASCII()); const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, model.mightContainRTL()); const r = renderViewLine(new RenderLineInput( - (config.fontInfo.isMonospace && !config.viewInfo.disableMonospaceOptimizations), + (config.fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), config.fontInfo.canUseHalfwidthRightwardsArrow, lineContent, false, @@ -782,10 +782,10 @@ export class DiffReview extends Disposable { [], tabSize, config.fontInfo.spaceWidth, - config.viewInfo.stopRenderingLineAfter, - config.viewInfo.renderWhitespace, - config.viewInfo.renderControlCharacters, - config.viewInfo.fontLigatures, + options.get(EditorOption.stopRenderingLineAfter), + options.get(EditorOption.renderWhitespace), + options.get(EditorOption.renderControlCharacters), + options.get(EditorOption.fontLigatures), null )); diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 433788372bd..df3551bfebd 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; -import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, blinkingStyleToString, cursorStyleToString } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -129,6 +129,32 @@ function migrateOptions(options: IEditorOptions): void { } else if (lineNumbers === false) { options.lineNumbers = 'off'; } + + let autoClosingBrackets = options.autoClosingBrackets; + if (autoClosingBrackets === false) { + options.autoClosingBrackets = 'never'; + options.autoClosingQuotes = 'never'; + options.autoSurround = 'never'; + } + + let cursorBlinking = options.cursorBlinking; + if (cursorBlinking === 'visible') { + options.cursorBlinking = 'solid'; + } + + let renderWhitespace = options.renderWhitespace; + if (renderWhitespace === true) { + options.renderWhitespace = 'boundary'; + } else if (renderWhitespace === false) { + options.renderWhitespace = 'none'; + } + + let renderLineHighlight = options.renderLineHighlight; + if (renderLineHighlight === true) { + options.renderLineHighlight = 'line'; + } else if (renderLineHighlight === false) { + options.renderLineHighlight = 'none'; + } } export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { @@ -144,7 +170,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed public readonly onDidChange: Event = this._onDidChange.event; private _rawOptions2: RawEditorOptions; - private _validatedOptions2: ValidatedEditorOptions; + protected _validatedOptions2: ValidatedEditorOptions; public options!: ComputedEditorOptions; constructor(isSimpleWidget: boolean, options: IEditorOptions) { @@ -358,7 +384,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.cursorSurroundingLines': { 'type': 'number', - 'default': EDITOR_DEFAULTS.viewInfo.cursorSurroundingLines, + 'default': EditorOptions.cursorSurroundingLines.defaultValue, 'description': nls.localize('cursorSurroundingLines', "Controls the minimal number of visible leading and trailing lines surrounding the cursor. Known as 'scrollOff' or `scrollOffset` in some other editors.") }, 'editor.renderFinalNewline': { @@ -371,12 +397,12 @@ const editorConfiguration: IConfigurationNode = { 'items': { 'type': 'number' }, - 'default': EDITOR_DEFAULTS.viewInfo.rulers, + 'default': EditorOptions.rulers.defaultValue, 'description': nls.localize('rulers', "Render vertical rulers after a certain number of monospace characters. Use multiple values for multiple rulers. No rulers are drawn if array is empty.") }, 'editor.wordSeparators': { 'type': 'string', - 'default': EDITOR_DEFAULTS.wordSeparators, + 'default': EditorOptions.wordSeparators.defaultValue, 'description': nls.localize('wordSeparators', "Characters that will be used as word separators when doing word related navigations or operations.") }, 'editor.tabSize': { @@ -411,22 +437,22 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.roundedSelection': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.roundedSelection, + 'default': EditorOptions.roundedSelection.defaultValue, 'description': nls.localize('roundedSelection', "Controls whether selections should have rounded corners.") }, 'editor.scrollBeyondLastLine': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.scrollBeyondLastLine, + 'default': EditorOptions.scrollBeyondLastLine.defaultValue, 'description': nls.localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") }, 'editor.scrollBeyondLastColumn': { 'type': 'number', - 'default': EDITOR_DEFAULTS.viewInfo.scrollBeyondLastColumn, + 'default': EditorOptions.scrollBeyondLastColumn.defaultValue, 'description': nls.localize('scrollBeyondLastColumn', "Controls the number of extra characters beyond which the editor will scroll horizontally.") }, 'editor.smoothScrolling': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.smoothScrolling, + 'default': EditorOptions.smoothScrolling.defaultValue, 'description': nls.localize('smoothScrolling', "Controls whether the editor will scroll using an animation.") }, 'editor.minimap.enabled': { @@ -573,7 +599,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.multiCursorMergeOverlapping': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.multiCursorMergeOverlapping, + 'default': EditorOptions.multiCursorMergeOverlapping.defaultValue, 'description': nls.localize('multiCursorMergeOverlapping', "Merge multiple cursors when they are overlapping.") }, 'editor.quickSuggestions': { @@ -629,9 +655,8 @@ const editorConfiguration: IConfigurationNode = { nls.localize('editor.autoClosingBrackets.languageDefined', "Use language configurations to determine when to autoclose brackets."), nls.localize('editor.autoClosingBrackets.beforeWhitespace', "Autoclose brackets only when the cursor is to the left of whitespace."), '', - ], - 'default': EDITOR_DEFAULTS.autoClosingBrackets, + 'default': EditorOptions.autoClosingBrackets.defaultValue, 'description': nls.localize('autoClosingBrackets', "Controls whether the editor should automatically close brackets after the user adds an opening bracket.") }, 'editor.autoClosingQuotes': { @@ -643,7 +668,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('editor.autoClosingQuotes.beforeWhitespace', "Autoclose quotes only when the cursor is to the left of whitespace."), '', ], - 'default': EDITOR_DEFAULTS.autoClosingQuotes, + 'default': EditorOptions.autoClosingQuotes.defaultValue, 'description': nls.localize('autoClosingQuotes', "Controls whether the editor should automatically close quotes after the user adds an opening quote.") }, 'editor.autoClosingOvertype': { @@ -654,7 +679,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('editor.autoClosingOvertype.auto', "Type over closing quotes or brackets only if they were automatically inserted."), nls.localize('editor.autoClosingOvertype.never', "Never type over closing quotes or brackets."), ], - 'default': EDITOR_DEFAULTS.autoClosingOvertype, + 'default': EditorOptions.autoClosingOvertype.defaultValue, 'description': nls.localize('autoClosingOvertype', "Controls whether the editor should type over closing quotes or brackets.") }, 'editor.autoSurround': { @@ -666,7 +691,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('editor.autoSurround.quotes', "Surround with quotes but not brackets."), '' ], - 'default': EDITOR_DEFAULTS.autoSurround, + 'default': EditorOptions.autoSurround.defaultValue, 'description': nls.localize('autoSurround', "Controls whether the editor should automatically surround selections.") }, 'editor.formatOnType': { @@ -681,7 +706,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.autoIndent': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.autoIndent, + 'default': EditorOptions.autoIndent.defaultValue, '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.") }, 'editor.suggestOnTriggerCharacters': { @@ -719,12 +744,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.emptySelectionClipboard': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.emptySelectionClipboard, + 'default': EditorOptions.emptySelectionClipboard.defaultValue, 'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.") }, 'editor.copyWithSyntaxHighlighting': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.copyWithSyntaxHighlighting, + 'default': EditorOptions.copyWithSyntaxHighlighting.defaultValue, 'description': nls.localize('copyWithSyntaxHighlighting', "Controls whether syntax highlighting should be copied into the clipboard.") }, 'editor.wordBasedSuggestions': { @@ -963,44 +988,44 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.overviewRulerBorder': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.overviewRulerBorder, + 'default': EditorOptions.overviewRulerBorder.defaultValue, 'description': nls.localize('overviewRulerBorder', "Controls whether a border should be drawn around the overview ruler.") }, 'editor.cursorBlinking': { 'type': 'string', 'enum': ['blink', 'smooth', 'phase', 'expand', 'solid'], - 'default': blinkingStyleToString(EDITOR_DEFAULTS.viewInfo.cursorBlinking), + 'default': EditorOptions.cursorBlinking.defaultValue, 'description': nls.localize('cursorBlinking', "Control the cursor animation style.") }, 'editor.mouseWheelZoom': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.mouseWheelZoom, + 'default': EditorOptions.mouseWheelZoom.defaultValue, 'markdownDescription': nls.localize('mouseWheelZoom', "Zoom the font of the editor when using mouse wheel and holding `Ctrl`.") }, 'editor.cursorSmoothCaretAnimation': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.cursorSmoothCaretAnimation, + 'default': EditorOptions.cursorSmoothCaretAnimation.defaultValue, 'description': nls.localize('cursorSmoothCaretAnimation', "Controls whether the smooth caret animation should be enabled.") }, 'editor.cursorStyle': { 'type': 'string', 'enum': ['block', 'block-outline', 'line', 'line-thin', 'underline', 'underline-thin'], - 'default': cursorStyleToString(EDITOR_DEFAULTS.viewInfo.cursorStyle), + 'default': EditorOptions.cursorStyle.defaultValue, 'description': nls.localize('cursorStyle', "Controls the cursor style.") }, 'editor.cursorWidth': { 'type': 'integer', - 'default': EDITOR_DEFAULTS.viewInfo.cursorWidth, + 'default': EditorOptions.cursorWidth.defaultValue, 'markdownDescription': nls.localize('cursorWidth', "Controls the width of the cursor when `#editor.cursorStyle#` is set to `line`.") }, 'editor.fontLigatures': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.fontLigatures, + 'default': EditorOptions.fontLigatures.defaultValue, 'description': nls.localize('fontLigatures', "Enables/Disables font ligatures.") }, 'editor.hideCursorInOverviewRuler': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.hideCursorInOverviewRuler, + 'default': EditorOptions.hideCursorInOverviewRuler.defaultValue, 'description': nls.localize('hideCursorInOverviewRuler', "Controls whether the cursor should be hidden in the overview ruler.") }, 'editor.renderWhitespace': { @@ -1012,22 +1037,22 @@ const editorConfiguration: IConfigurationNode = { nls.localize('renderWhitespace.selection', "Render whitespace characters only on selected text."), '' ], - default: EDITOR_DEFAULTS.viewInfo.renderWhitespace, + default: EditorOptions.renderWhitespace.defaultValue, description: nls.localize('renderWhitespace', "Controls how the editor should render whitespace characters.") }, 'editor.renderControlCharacters': { 'type': 'boolean', - default: EDITOR_DEFAULTS.viewInfo.renderControlCharacters, + default: EditorOptions.renderControlCharacters.defaultValue, description: nls.localize('renderControlCharacters', "Controls whether the editor should render control characters.") }, 'editor.renderIndentGuides': { 'type': 'boolean', - default: EDITOR_DEFAULTS.viewInfo.renderIndentGuides, + default: EditorOptions.renderIndentGuides.defaultValue, description: nls.localize('renderIndentGuides', "Controls whether the editor should render indent guides.") }, 'editor.highlightActiveIndentGuide': { 'type': 'boolean', - default: EDITOR_DEFAULTS.viewInfo.highlightActiveIndentGuide, + default: EditorOptions.highlightActiveIndentGuide.defaultValue, description: nls.localize('highlightActiveIndentGuide', "Controls whether the editor should highlight the active indent guide.") }, 'editor.renderLineHighlight': { @@ -1039,7 +1064,7 @@ const editorConfiguration: IConfigurationNode = { '', nls.localize('renderLineHighlight.all', "Highlights both the gutter and the current line."), ], - default: EDITOR_DEFAULTS.viewInfo.renderLineHighlight, + default: EditorOptions.renderLineHighlight.defaultValue, description: nls.localize('renderLineHighlight', "Controls how the editor should render the current line highlight.") }, 'editor.codeLens': { @@ -1071,12 +1096,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.glyphMargin': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.viewInfo.glyphMargin, + 'default': EditorOptions.glyphMargin.defaultValue, 'description': nls.localize('glyphMargin', "Controls whether the editor should render the vertical glyph margin. Glyph margin is mostly used for debugging.") }, 'editor.useTabStops': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.useTabStops, + 'default': EditorOptions.useTabStops.defaultValue, 'description': nls.localize('useTabStops', "Inserting and deleting whitespace follows tab stops.") }, 'editor.trimAutoWhitespace': { @@ -1091,7 +1116,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.dragAndDrop': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.dragAndDrop, + 'default': EditorOptions.dragAndDrop.defaultValue, 'description': nls.localize('dragAndDrop', "Controls whether the editor should allow moving selections via drag and drop.") }, 'editor.accessibilitySupport': { @@ -1107,7 +1132,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.showUnused': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.showUnused, + 'default': EditorOptions.showUnused.defaultValue, 'description': nls.localize('showUnused', "Controls fading out of unused code.") }, 'editor.links': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 653d28714e3..d3eeb2ec5c2 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -357,7 +357,7 @@ export interface IEditorOptions { * Control the cursor animation style, possible values are 'blink', 'smooth', 'phase', 'expand' and 'solid'. * Defaults to 'blink'. */ - cursorBlinking?: string; + cursorBlinking?: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid'; /** * Zoom the font in the editor when using the mouse wheel in combination with holding Ctrl. * Defaults to false. @@ -378,7 +378,7 @@ export interface IEditorOptions { * Control the cursor style, either 'block' or 'line'. * Defaults to 'line'. */ - cursorStyle?: string; + cursorStyle?: 'line' | 'block' | 'underline' | 'line-thin' | 'block-outline' | 'underline-thin'; /** * Control the width of the cursor when cursorStyle is set to 'line' */ @@ -729,6 +729,11 @@ export interface IEditorOptions { */ showUnused?: boolean; + /** + * Do not use. + * @internal + */ + editorClassName?: undefined; /** * Do not use. * @internal @@ -836,24 +841,6 @@ export const enum TextEditorCursorBlinkingStyle { */ Solid = 5 } -/** - * @internal - */ -export function blinkingStyleToString(blinkingStyle: TextEditorCursorBlinkingStyle): string { - if (blinkingStyle === TextEditorCursorBlinkingStyle.Blink) { - return 'blink'; - } else if (blinkingStyle === TextEditorCursorBlinkingStyle.Expand) { - return 'expand'; - } else if (blinkingStyle === TextEditorCursorBlinkingStyle.Phase) { - return 'phase'; - } else if (blinkingStyle === TextEditorCursorBlinkingStyle.Smooth) { - return 'smooth'; - } else if (blinkingStyle === TextEditorCursorBlinkingStyle.Solid) { - return 'solid'; - } else { - throw new Error('blinkingStyleToString: Unknown blinkingStyle'); - } -} /** * The style in which the editor's cursor should be rendered. @@ -888,42 +875,38 @@ export enum TextEditorCursorStyle { /** * @internal */ -export function cursorStyleToString(cursorStyle: TextEditorCursorStyle): string { - if (cursorStyle === TextEditorCursorStyle.Line) { - return 'line'; - } else if (cursorStyle === TextEditorCursorStyle.Block) { - return 'block'; - } else if (cursorStyle === TextEditorCursorStyle.Underline) { - return 'underline'; - } else if (cursorStyle === TextEditorCursorStyle.LineThin) { - return 'line-thin'; - } else if (cursorStyle === TextEditorCursorStyle.BlockOutline) { - return 'block-outline'; - } else if (cursorStyle === TextEditorCursorStyle.UnderlineThin) { - return 'underline-thin'; - } else { - throw new Error('cursorStyleToString: Unknown cursorStyle'); +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: string | undefined, defaultValue: TextEditorCursorStyle): TextEditorCursorStyle { - if (typeof cursorStyle !== 'string') { - return defaultValue; +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; } - if (cursorStyle === 'line') { - return TextEditorCursorStyle.Line; - } else if (cursorStyle === 'block') { - return TextEditorCursorStyle.Block; - } else if (cursorStyle === 'underline') { - return TextEditorCursorStyle.Underline; - } else if (cursorStyle === 'line-thin') { - return TextEditorCursorStyle.LineThin; - } else if (cursorStyle === 'block-outline') { - return TextEditorCursorStyle.BlockOutline; - } else if (cursorStyle === 'underline-thin') { - return TextEditorCursorStyle.UnderlineThin; - } - return TextEditorCursorStyle.Line; } export interface InternalEditorFindOptions { @@ -962,35 +945,6 @@ export interface InternalParameterHintOptions { readonly cycle: boolean; } -export interface InternalEditorViewOptions { - readonly extraEditorClassName: string; - readonly disableMonospaceOptimizations: boolean; - readonly rulers: number[]; - readonly cursorSurroundingLines: number; - readonly glyphMargin: boolean; - readonly revealHorizontalRightPadding: number; - readonly roundedSelection: boolean; - readonly overviewRulerLanes: number; - readonly overviewRulerBorder: boolean; - readonly cursorBlinking: TextEditorCursorBlinkingStyle; - readonly mouseWheelZoom: boolean; - readonly cursorSmoothCaretAnimation: boolean; - readonly cursorStyle: TextEditorCursorStyle; - readonly cursorWidth: number; - readonly hideCursorInOverviewRuler: boolean; - readonly scrollBeyondLastLine: boolean; - readonly scrollBeyondLastColumn: number; - readonly smoothScrolling: boolean; - readonly stopRenderingLineAfter: number; - readonly renderWhitespace: 'none' | 'boundary' | 'selection' | 'all'; - readonly renderControlCharacters: boolean; - readonly fontLigatures: boolean; - readonly renderIndentGuides: boolean; - readonly highlightActiveIndentGuide: boolean; - readonly renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; - readonly fixedOverflowWidgets: boolean; -} - export interface EditorContribOptions { readonly hover: InternalEditorHoverOptions; readonly links: boolean; @@ -1029,25 +983,6 @@ export interface EditorContribOptions { * @internal */ export interface IValidatedEditorOptions { - readonly wordSeparators: string; - readonly lineDecorationsWidth: number | string; - readonly mouseStyle: 'text' | 'default' | 'copy'; - readonly disableLayerHinting: boolean; - readonly automaticLayout: boolean; - readonly autoClosingBrackets: EditorAutoClosingStrategy; - readonly autoClosingQuotes: EditorAutoClosingStrategy; - readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy; - readonly autoSurround: EditorAutoSurroundStrategy; - readonly autoIndent: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; - readonly useTabStops: boolean; - readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; - readonly multiCursorMergeOverlapping: boolean; - readonly showUnused: boolean; - - readonly viewInfo: InternalEditorViewOptions; readonly contribInfo: EditorContribOptions; } @@ -1057,76 +992,26 @@ export interface IValidatedEditorOptions { export class InternalEditorOptions { readonly _internalEditorOptionsBrand: void; - readonly canUseLayerHinting: boolean; readonly pixelRatio: number; - readonly editorClassName: string; readonly lineHeight: number; - readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; - readonly multiCursorMergeOverlapping: boolean; - readonly showUnused: boolean; - - // ---- cursor options - readonly wordSeparators: string; - readonly autoClosingBrackets: EditorAutoClosingStrategy; - readonly autoClosingQuotes: EditorAutoClosingStrategy; - readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy; - readonly autoSurround: EditorAutoSurroundStrategy; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; // ---- grouped options readonly fontInfo: FontInfo; - readonly viewInfo: InternalEditorViewOptions; readonly contribInfo: EditorContribOptions; /** * @internal */ constructor(source: { - canUseLayerHinting: boolean; pixelRatio: number; - editorClassName: string; lineHeight: number; - multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; - multiCursorMergeOverlapping: boolean; - wordSeparators: string; - autoClosingBrackets: EditorAutoClosingStrategy; - autoClosingQuotes: EditorAutoClosingStrategy; - autoClosingOvertype: EditorAutoClosingOvertypeStrategy; - autoSurround: EditorAutoSurroundStrategy; - autoIndent: boolean; - useTabStops: boolean; - dragAndDrop: boolean; - emptySelectionClipboard: boolean; - copyWithSyntaxHighlighting: boolean; fontInfo: FontInfo; - viewInfo: InternalEditorViewOptions; contribInfo: EditorContribOptions; - showUnused: boolean; }) { - this.canUseLayerHinting = source.canUseLayerHinting; this.pixelRatio = source.pixelRatio; - this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight | 0; - this.multiCursorModifier = source.multiCursorModifier; - this.multiCursorMergeOverlapping = source.multiCursorMergeOverlapping; - this.wordSeparators = source.wordSeparators; - this.autoClosingBrackets = source.autoClosingBrackets; - this.autoClosingQuotes = source.autoClosingQuotes; - this.autoClosingOvertype = source.autoClosingOvertype; - this.autoSurround = source.autoSurround; - this.autoIndent = source.autoIndent; - this.useTabStops = source.useTabStops; - this.dragAndDrop = source.dragAndDrop; - this.emptySelectionClipboard = source.emptySelectionClipboard; - this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; this.fontInfo = source.fontInfo; - this.viewInfo = source.viewInfo; this.contribInfo = source.contribInfo; - this.showUnused = source.showUnused; } /** @@ -1134,25 +1019,9 @@ export class InternalEditorOptions { */ public equals(other: InternalEditorOptions): boolean { return ( - this.canUseLayerHinting === other.canUseLayerHinting - && this.pixelRatio === other.pixelRatio - && this.editorClassName === other.editorClassName + this.pixelRatio === other.pixelRatio && this.lineHeight === other.lineHeight - && this.multiCursorModifier === other.multiCursorModifier - && this.multiCursorMergeOverlapping === other.multiCursorMergeOverlapping - && this.wordSeparators === other.wordSeparators - && this.autoClosingBrackets === other.autoClosingBrackets - && this.autoClosingQuotes === other.autoClosingQuotes - && this.autoClosingOvertype === other.autoClosingOvertype - && this.autoSurround === other.autoSurround - && this.autoIndent === other.autoIndent - && this.useTabStops === other.useTabStops - && this.dragAndDrop === other.dragAndDrop - && this.showUnused === other.showUnused - && this.emptySelectionClipboard === other.emptySelectionClipboard - && this.copyWithSyntaxHighlighting === other.copyWithSyntaxHighlighting && this.fontInfo.equals(other.fontInfo) - && InternalEditorOptions._equalsViewOptions(this.viewInfo, other.viewInfo) && InternalEditorOptions._equalsContribOptions(this.contribInfo, other.contribInfo) ); } @@ -1168,62 +1037,13 @@ export class InternalEditorOptions { } return changeEvent.get(id); }, - canUseLayerHinting: (this.canUseLayerHinting !== newOpts.canUseLayerHinting), pixelRatio: (this.pixelRatio !== newOpts.pixelRatio), - editorClassName: (this.editorClassName !== newOpts.editorClassName), lineHeight: (this.lineHeight !== newOpts.lineHeight), - multiCursorModifier: (this.multiCursorModifier !== newOpts.multiCursorModifier), - multiCursorMergeOverlapping: (this.multiCursorMergeOverlapping !== newOpts.multiCursorMergeOverlapping), - wordSeparators: (this.wordSeparators !== newOpts.wordSeparators), - autoClosingBrackets: (this.autoClosingBrackets !== newOpts.autoClosingBrackets), - autoClosingQuotes: (this.autoClosingQuotes !== newOpts.autoClosingQuotes), - autoClosingOvertype: (this.autoClosingOvertype !== newOpts.autoClosingOvertype), - autoSurround: (this.autoSurround !== newOpts.autoSurround), - autoIndent: (this.autoIndent !== newOpts.autoIndent), - useTabStops: (this.useTabStops !== newOpts.useTabStops), - dragAndDrop: (this.dragAndDrop !== newOpts.dragAndDrop), - emptySelectionClipboard: (this.emptySelectionClipboard !== newOpts.emptySelectionClipboard), - copyWithSyntaxHighlighting: (this.copyWithSyntaxHighlighting !== newOpts.copyWithSyntaxHighlighting), fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)), - viewInfo: (!InternalEditorOptions._equalsViewOptions(this.viewInfo, newOpts.viewInfo)), contribInfo: (!InternalEditorOptions._equalsContribOptions(this.contribInfo, newOpts.contribInfo)) }; } - /** - * @internal - */ - private static _equalsViewOptions(a: InternalEditorViewOptions, b: InternalEditorViewOptions): boolean { - return ( - a.extraEditorClassName === b.extraEditorClassName - && a.disableMonospaceOptimizations === b.disableMonospaceOptimizations - && arrays.equals(a.rulers, b.rulers) - && a.cursorSurroundingLines === b.cursorSurroundingLines - && a.glyphMargin === b.glyphMargin - && a.revealHorizontalRightPadding === b.revealHorizontalRightPadding - && a.roundedSelection === b.roundedSelection - && a.overviewRulerLanes === b.overviewRulerLanes - && a.overviewRulerBorder === b.overviewRulerBorder - && a.cursorBlinking === b.cursorBlinking - && a.mouseWheelZoom === b.mouseWheelZoom - && a.cursorSmoothCaretAnimation === b.cursorSmoothCaretAnimation - && a.cursorStyle === b.cursorStyle - && a.cursorWidth === b.cursorWidth - && a.hideCursorInOverviewRuler === b.hideCursorInOverviewRuler - && a.scrollBeyondLastLine === b.scrollBeyondLastLine - && a.scrollBeyondLastColumn === b.scrollBeyondLastColumn - && a.smoothScrolling === b.smoothScrolling - && a.stopRenderingLineAfter === b.stopRenderingLineAfter - && a.renderWhitespace === b.renderWhitespace - && a.renderControlCharacters === b.renderControlCharacters - && a.fontLigatures === b.fontLigatures - && a.renderIndentGuides === b.renderIndentGuides - && a.highlightActiveIndentGuide === b.highlightActiveIndentGuide - && a.renderLineHighlight === b.renderLineHighlight - && a.fixedOverflowWidgets === b.fixedOverflowWidgets - ); - } - /** * @internal */ @@ -1347,24 +1167,9 @@ export class InternalEditorOptions { */ export interface IConfigurationChangedEvent { hasChanged(id: EditorOption): boolean; - readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; - readonly editorClassName: boolean; readonly lineHeight: boolean; - readonly multiCursorModifier: boolean; - readonly multiCursorMergeOverlapping: boolean; - readonly wordSeparators: boolean; - readonly autoClosingBrackets: boolean; - readonly autoClosingQuotes: boolean; - readonly autoClosingOvertype: boolean; - readonly autoSurround: boolean; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; readonly fontInfo: boolean; - readonly viewInfo: boolean; readonly contribInfo: boolean; } @@ -1456,10 +1261,7 @@ function _wrappingIndentFromString(wrappingIndent: 'none' | 'same' | 'indent' | } } -function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string | undefined, defaultValue: TextEditorCursorBlinkingStyle): TextEditorCursorBlinkingStyle { - if (typeof cursorBlinkingStyle !== 'string') { - return defaultValue; - } +function _cursorBlinkingStyleFromString(cursorBlinkingStyle: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid'): TextEditorCursorBlinkingStyle { switch (cursorBlinkingStyle) { case 'blink': return TextEditorCursorBlinkingStyle.Blink; @@ -1469,11 +1271,9 @@ function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string | undefined, return TextEditorCursorBlinkingStyle.Phase; case 'expand': return TextEditorCursorBlinkingStyle.Expand; - case 'visible': // maintain compatibility case 'solid': return TextEditorCursorBlinkingStyle.Solid; } - return TextEditorCursorBlinkingStyle.Blink; } function _scrollbarVisibilityFromString(visibility: string | undefined, defaultValue: ScrollbarVisibility): ScrollbarVisibility { @@ -1500,52 +1300,8 @@ export class EditorOptionsValidator { * i.e. since they can be defined by the user, they might be invalid. */ public static validate(opts: IEditorOptions, defaults: IValidatedEditorOptions): IValidatedEditorOptions { - const viewInfo = this._sanitizeViewInfo(opts, defaults.viewInfo); const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo); - - let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey' | undefined = undefined; - if (typeof opts.multiCursorModifier === 'string') { - if (opts.multiCursorModifier === 'ctrlCmd') { - configuredMulticursorModifier = platform.isMacintosh ? 'metaKey' : 'ctrlKey'; - } else { - configuredMulticursorModifier = 'altKey'; - } - } - const multiCursorModifier = _stringSet<'altKey' | 'metaKey' | 'ctrlKey'>(configuredMulticursorModifier, defaults.multiCursorModifier, ['altKey', 'metaKey', 'ctrlKey']); - - let autoClosingBrackets: EditorAutoClosingStrategy; - let autoClosingQuotes: EditorAutoClosingStrategy; - let autoSurround: EditorAutoSurroundStrategy; - if (typeof opts.autoClosingBrackets === 'boolean' && opts.autoClosingBrackets === false) { - // backwards compatibility: disable all on boolean false - autoClosingBrackets = 'never'; - autoClosingQuotes = 'never'; - autoSurround = 'never'; - } else { - autoClosingBrackets = _stringSet(opts.autoClosingBrackets, defaults.autoClosingBrackets, ['always', 'languageDefined', 'beforeWhitespace', 'never']); - autoClosingQuotes = _stringSet(opts.autoClosingQuotes, defaults.autoClosingQuotes, ['always', 'languageDefined', 'beforeWhitespace', 'never']); - autoSurround = _stringSet(opts.autoSurround, defaults.autoSurround, ['languageDefined', 'brackets', 'quotes', 'never']); - } - return { - wordSeparators: _string(opts.wordSeparators, defaults.wordSeparators), - lineDecorationsWidth: (typeof opts.lineDecorationsWidth === 'undefined' ? defaults.lineDecorationsWidth : opts.lineDecorationsWidth), - mouseStyle: _stringSet<'text' | 'default' | 'copy'>(opts.mouseStyle, defaults.mouseStyle, ['text', 'default', 'copy']), - disableLayerHinting: _boolean(opts.disableLayerHinting, defaults.disableLayerHinting), - automaticLayout: _boolean(opts.automaticLayout, defaults.automaticLayout), - autoClosingBrackets, - autoClosingQuotes, - autoClosingOvertype: _stringSet(opts.autoClosingOvertype, defaults.autoClosingOvertype, ['always', 'auto', 'never']), - autoSurround, - autoIndent: _boolean(opts.autoIndent, defaults.autoIndent), - dragAndDrop: _boolean(opts.dragAndDrop, defaults.dragAndDrop), - emptySelectionClipboard: _boolean(opts.emptySelectionClipboard, defaults.emptySelectionClipboard), - copyWithSyntaxHighlighting: _boolean(opts.copyWithSyntaxHighlighting, defaults.copyWithSyntaxHighlighting), - useTabStops: _boolean(opts.useTabStops, defaults.useTabStops), - multiCursorModifier: multiCursorModifier, - multiCursorMergeOverlapping: _boolean(opts.multiCursorMergeOverlapping, defaults.multiCursorMergeOverlapping), - showUnused: _boolean(opts.showUnused, defaults.showUnused), - viewInfo: viewInfo, contribInfo: contribInfo, }; } @@ -1624,71 +1380,6 @@ export class EditorOptionsValidator { } } - private static _sanitizeViewInfo(opts: IEditorOptions, defaults: InternalEditorViewOptions): InternalEditorViewOptions { - - let rulers: number[] = []; - if (Array.isArray(opts.rulers)) { - for (let i = 0, len = opts.rulers.length; i < len; i++) { - rulers.push(_clampedInt(opts.rulers[i], 0, 0, 10000)); - } - rulers.sort(); - } - - const fontLigatures = _boolean(opts.fontLigatures, defaults.fontLigatures); - const disableMonospaceOptimizations = _boolean(opts.disableMonospaceOptimizations, defaults.disableMonospaceOptimizations) || fontLigatures; - - let renderWhitespace = opts.renderWhitespace; - { - // Compatibility with old true or false values - if (renderWhitespace === true) { - renderWhitespace = 'boundary'; - } else if (renderWhitespace === false) { - renderWhitespace = 'none'; - } - renderWhitespace = _stringSet<'none' | 'boundary' | 'selection' | 'all'>(renderWhitespace, defaults.renderWhitespace, ['none', 'boundary', 'selection', 'all']); - } - - let renderLineHighlight = opts.renderLineHighlight; - { - // Compatibility with old true or false values - if (renderLineHighlight === true) { - renderLineHighlight = 'line'; - } else if (renderLineHighlight === false) { - renderLineHighlight = 'none'; - } - renderLineHighlight = _stringSet<'none' | 'gutter' | 'line' | 'all'>(renderLineHighlight, defaults.renderLineHighlight, ['none', 'gutter', 'line', 'all']); - } - - return { - extraEditorClassName: _string(opts.extraEditorClassName, defaults.extraEditorClassName), - disableMonospaceOptimizations: disableMonospaceOptimizations, - rulers: rulers, - cursorSurroundingLines: _clampedInt(opts.cursorSurroundingLines, defaults.cursorWidth, 0, Number.MAX_VALUE), - glyphMargin: _boolean(opts.glyphMargin, defaults.glyphMargin), - revealHorizontalRightPadding: _clampedInt(opts.revealHorizontalRightPadding, defaults.revealHorizontalRightPadding, 0, 1000), - roundedSelection: _boolean(opts.roundedSelection, defaults.roundedSelection), - overviewRulerLanes: _clampedInt(opts.overviewRulerLanes, defaults.overviewRulerLanes, 0, 3), - overviewRulerBorder: _boolean(opts.overviewRulerBorder, defaults.overviewRulerBorder), - cursorBlinking: _cursorBlinkingStyleFromString(opts.cursorBlinking, defaults.cursorBlinking), - mouseWheelZoom: _boolean(opts.mouseWheelZoom, defaults.mouseWheelZoom), - cursorSmoothCaretAnimation: _boolean(opts.cursorSmoothCaretAnimation, defaults.cursorSmoothCaretAnimation), - cursorStyle: _cursorStyleFromString(opts.cursorStyle, defaults.cursorStyle), - cursorWidth: _clampedInt(opts.cursorWidth, defaults.cursorWidth, 0, Number.MAX_VALUE), - hideCursorInOverviewRuler: _boolean(opts.hideCursorInOverviewRuler, defaults.hideCursorInOverviewRuler), - scrollBeyondLastLine: _boolean(opts.scrollBeyondLastLine, defaults.scrollBeyondLastLine), - scrollBeyondLastColumn: _clampedInt(opts.scrollBeyondLastColumn, defaults.scrollBeyondLastColumn, 0, Constants.MAX_SAFE_SMALL_INTEGER), - smoothScrolling: _boolean(opts.smoothScrolling, defaults.smoothScrolling), - stopRenderingLineAfter: _clampedInt(opts.stopRenderingLineAfter, defaults.stopRenderingLineAfter, -1, Constants.MAX_SAFE_SMALL_INTEGER), - renderWhitespace: renderWhitespace, - renderControlCharacters: _boolean(opts.renderControlCharacters, defaults.renderControlCharacters), - fontLigatures: fontLigatures, - renderIndentGuides: _boolean(opts.renderIndentGuides, defaults.renderIndentGuides), - highlightActiveIndentGuide: _boolean(opts.highlightActiveIndentGuide, defaults.highlightActiveIndentGuide), - renderLineHighlight: renderLineHighlight, - fixedOverflowWidgets: _boolean(opts.fixedOverflowWidgets, defaults.fixedOverflowWidgets), - }; - } - private static _sanitizeContribInfo(opts: IEditorOptions, defaults: EditorContribOptions): EditorContribOptions { let quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; if (typeof opts.quickSuggestions === 'object') { @@ -1741,44 +1432,11 @@ export class EditorOptionsValidator { export class InternalEditorOptionsFactory { public static createInternalEditorOptions(env: IEnvironmentalOptions, opts: IValidatedEditorOptions) { - - let className = 'monaco-editor'; - if (opts.viewInfo.extraEditorClassName) { - className += ' ' + opts.viewInfo.extraEditorClassName; - } - if (env.extraEditorClassName) { - className += ' ' + env.extraEditorClassName; - } - if (opts.viewInfo.fontLigatures) { - className += ' enable-ligatures'; - } - if (opts.mouseStyle === 'default') { - className += ' mouse-default'; - } else if (opts.mouseStyle === 'copy') { - className += ' mouse-copy'; - } - return new InternalEditorOptions({ - canUseLayerHinting: opts.disableLayerHinting ? false : true, pixelRatio: env.pixelRatio, - editorClassName: className, lineHeight: env.fontInfo.lineHeight, - multiCursorModifier: opts.multiCursorModifier, - multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping, - wordSeparators: opts.wordSeparators, - autoClosingBrackets: opts.autoClosingBrackets, - autoClosingQuotes: opts.autoClosingQuotes, - autoClosingOvertype: opts.autoClosingOvertype, - autoSurround: opts.autoSurround, - autoIndent: opts.autoIndent, - useTabStops: opts.useTabStops, - dragAndDrop: opts.dragAndDrop, - emptySelectionClipboard: opts.emptySelectionClipboard && env.emptySelectionClipboard, - copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting, fontInfo: env.fontInfo, - viewInfo: opts.viewInfo, contribInfo: opts.contribInfo, - showUnused: opts.showUnused, }); } } @@ -1849,53 +1507,6 @@ export const EDITOR_MODEL_DEFAULTS = { * @internal */ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { - wordSeparators: USUAL_WORD_SEPARATORS, - lineDecorationsWidth: 10, - mouseStyle: 'text', - disableLayerHinting: false, - automaticLayout: false, - autoClosingBrackets: 'languageDefined', - autoClosingQuotes: 'languageDefined', - autoClosingOvertype: 'auto', - autoSurround: 'languageDefined', - autoIndent: true, - dragAndDrop: true, - emptySelectionClipboard: true, - copyWithSyntaxHighlighting: true, - useTabStops: true, - multiCursorModifier: 'altKey', - multiCursorMergeOverlapping: true, - showUnused: true, - - viewInfo: { - extraEditorClassName: '', - disableMonospaceOptimizations: false, - rulers: [], - cursorSurroundingLines: 0, - glyphMargin: true, - revealHorizontalRightPadding: 30, - roundedSelection: true, - overviewRulerLanes: 2, - overviewRulerBorder: true, - cursorBlinking: TextEditorCursorBlinkingStyle.Blink, - mouseWheelZoom: false, - cursorSmoothCaretAnimation: false, - cursorStyle: TextEditorCursorStyle.Line, - cursorWidth: 0, - hideCursorInOverviewRuler: false, - scrollBeyondLastLine: true, - scrollBeyondLastColumn: 5, - smoothScrolling: false, - stopRenderingLineAfter: 10000, - renderWhitespace: 'none', - renderControlCharacters: false, - fontLigatures: false, - renderIndentGuides: true, - highlightActiveIndentGuide: true, - renderLineHighlight: 'line', - fixedOverflowWidgets: false, - }, - contribInfo: { hover: { enabled: true, @@ -1977,6 +1588,9 @@ export class ValidatedEditorOptions { public _read(option: EditorOption): T { return this._values[option]; } + public get(id: T): FindComputedEditorOptionValueById { + return this._values[id]; + } public _write(option: EditorOption, value: T): void { this._values[option] = value; } @@ -2264,6 +1878,30 @@ class EditorAccessibilitySupportOption> extends BaseEditorOption { + public validate(input: number[] | undefined): number[] { + if (Array.isArray(input)) { + let rulers: number[] = []; + for (let value in input) { + rulers.push(_clampedInt(value, 0, 0, 10000)); + } + rulers.sort(); + return rulers; + } + return this.defaultValue; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number[]): number[] { + return value; + } + public equals(a: number[], b: number[]): boolean { + return arrays.equals(a, b); + } +} + +//#endregion + //#region ariaLabel class EditorAriaLabel> extends BaseEditorOption { @@ -2281,6 +1919,47 @@ class EditorAriaLabel> extends BaseEditorOption { + public validate(input: boolean | undefined): boolean { + return _boolean(input, this.defaultValue); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { + return (value || options.get(EditorOption.folding)); + } +} + +//#endregion + +//#region editorClassName + +class EditorClassName> extends BaseEditorOption { + public validate(input: undefined): undefined { + return undefined; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): string { + 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 + //#region tabFocusMode class EditorTabFocusMode> extends BaseEditorOption { @@ -2295,6 +1974,16 @@ class EditorTabFocusMode> extends EditorBooleanOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { + return value && env.emptySelectionClipboard; + } +} + +//#endregion + //#region scrollbar export interface InternalEditorScrollbarOptions { @@ -2492,7 +2181,7 @@ export class EditorLayoutInfoComputer x)), + autoClosingOvertype: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingOvertype, 'autoClosingOvertype', 'auto', ['always', 'auto', 'never'], x => x)), + autoClosingQuotes: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingQuotes, 'autoClosingQuotes', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], x => x)), + autoIndent: registerEditorOption(new EditorBooleanOption(EditorOption.autoIndent, 'autoIndent', true)), + automaticLayout: registerEditorOption(new EditorBooleanOption(EditorOption.automaticLayout, 'automaticLayout', false)), + autoSurround: registerEditorOption(new EditorEnumOption(EditorOption.autoSurround, 'autoSurround', 'languageDefined', ['languageDefined', 'quotes', 'brackets', 'never'], x => x)), + copyWithSyntaxHighlighting: registerEditorOption(new EditorBooleanOption(EditorOption.copyWithSyntaxHighlighting, 'copyWithSyntaxHighlighting', true)), + cursorBlinking: registerEditorOption(new EditorEnumOption(EditorOption.cursorBlinking, 'cursorBlinking', 'blink', ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString)), + cursorSmoothCaretAnimation: registerEditorOption(new EditorBooleanOption(EditorOption.cursorSmoothCaretAnimation, 'cursorSmoothCaretAnimation', false)), + cursorStyle: registerEditorOption(new EditorEnumOption(EditorOption.cursorStyle, 'cursorStyle', 'line', ['line', 'block', 'underline', 'line-thin', 'block-outline', 'underline-thin'], _cursorStyleFromString)), + cursorSurroundingLines: registerEditorOption(new EditorIntOption(EditorOption.cursorSurroundingLines, 'cursorSurroundingLines', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)), + cursorWidth: registerEditorOption(new EditorIntOption(EditorOption.cursorWidth, 'cursorWidth', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)), + disableLayerHinting: registerEditorOption(new EditorBooleanOption(EditorOption.disableLayerHinting, 'disableLayerHinting', false)), + dragAndDrop: registerEditorOption(new EditorBooleanOption(EditorOption.dragAndDrop, 'dragAndDrop', true)), + emptySelectionClipboard: registerEditorOption(new EditorEmptySelectionClipboard(EditorOption.emptySelectionClipboard, 'emptySelectionClipboard', true)), + extraEditorClassName: registerEditorOption(new EditorStringOption(EditorOption.extraEditorClassName, 'extraEditorClassName', '')), fastScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))), + fixedOverflowWidgets: registerEditorOption(new EditorBooleanOption(EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false)), folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), + fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), + hideCursorInOverviewRuler: registerEditorOption(new EditorBooleanOption(EditorOption.hideCursorInOverviewRuler, 'hideCursorInOverviewRuler', false)), + highlightActiveIndentGuide: registerEditorOption(new EditorBooleanOption(EditorOption.highlightActiveIndentGuide, 'highlightActiveIndentGuide', true)), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), minimap: registerEditorOption(new EditorMinimapOption(EditorOption.minimap, 'minimap', { enabled: true, @@ -2831,10 +2589,22 @@ export const EditorOptions = { renderCharacters: true, maxColumn: 120, })), + mouseStyle: registerEditorOption(new EditorEnumOption(EditorOption.mouseStyle, 'mouseStyle', 'text', ['text', 'default', 'copy'], x => x)), mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), + mouseWheelZoom: registerEditorOption(new EditorBooleanOption(EditorOption.mouseWheelZoom, 'mouseWheelZoom', false)), + multiCursorMergeOverlapping: registerEditorOption(new EditorBooleanOption(EditorOption.multiCursorMergeOverlapping, 'multiCursorMergeOverlapping', true)), + multiCursorModifier: registerEditorOption(new EditorEnumOption(EditorOption.multiCursorModifier, 'multiCursorModifier', 'alt', ['ctrlCmd', 'alt'], _multiCursorModifierFromString)), + overviewRulerBorder: registerEditorOption(new EditorBooleanOption(EditorOption.overviewRulerBorder, 'overviewRulerBorder', true)), + overviewRulerLanes: registerEditorOption(new EditorIntOption(EditorOption.overviewRulerLanes, 'overviewRulerLanes', 2, 0, 3)), readOnly: registerEditorOption(new EditorBooleanOption(EditorOption.readOnly, 'readOnly', false)), + renderControlCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.renderControlCharacters, 'renderControlCharacters', false)), + renderIndentGuides: registerEditorOption(new EditorBooleanOption(EditorOption.renderIndentGuides, 'renderIndentGuides', true)), renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOption.renderFinalNewline, 'renderFinalNewline', true)), - renderLineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.renderLineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), + renderLineHighlight: registerEditorOption(new EditorEnumOption(EditorOption.renderLineHighlight, 'renderLineHighlight', 'line', ['none', 'gutter', 'line', 'all'], x => x)), + renderWhitespace: registerEditorOption(new EditorEnumOption(EditorOption.renderWhitespace, 'renderWhitespace', 'none', ['none', 'boundary', 'selection', 'all'], x => x)), + revealHorizontalRightPadding: registerEditorOption(new EditorIntOption(EditorOption.revealHorizontalRightPadding, 'revealHorizontalRightPadding', 30, 0, 1000)), + roundedSelection: registerEditorOption(new EditorBooleanOption(EditorOption.roundedSelection, 'roundedSelection', true)), + rulers: registerEditorOption(new EditorRulers(EditorOption.rulers, 'rulers', [])), scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOption.scrollbar, 'scrollbar', { vertical: ScrollbarVisibility.Auto, horizontal: ScrollbarVisibility.Auto, @@ -2848,22 +2618,40 @@ export const EditorOptions = { verticalSliderSize: 14, handleMouseWheel: true, })), + scrollBeyondLastColumn: registerEditorOption(new EditorIntOption(EditorOption.scrollBeyondLastColumn, 'scrollBeyondLastColumn', 5, 0, Constants.MAX_SAFE_SMALL_INTEGER)), + scrollBeyondLastLine: registerEditorOption(new EditorBooleanOption(EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true)), selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), - tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), + showUnused: registerEditorOption(new EditorBooleanOption(EditorOption.showUnused, 'showUnused', true)), + smoothScrolling: registerEditorOption(new EditorBooleanOption(EditorOption.smoothScrolling, 'smoothScrolling', false)), + stopRenderingLineAfter: registerEditorOption(new EditorIntOption(EditorOption.stopRenderingLineAfter, 'stopRenderingLineAfter', 10000, -1, Constants.MAX_SAFE_SMALL_INTEGER)), + useTabStops: registerEditorOption(new EditorBooleanOption(EditorOption.useTabStops, 'useTabStops', true)), + wordSeparators: registerEditorOption(new EditorStringOption(EditorOption.wordSeparators, 'wordSeparators', USUAL_WORD_SEPARATORS)), wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), - wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'tabFocusMode', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), + wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOption.wordWrapMinified, 'wordWrapMinified', true)), wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), // Leave these at the end! - layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.renderLineNumbers])), + ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOption.accessibilitySupport])), + disableMonospaceOptimizations: registerEditorOption(new EditorDisableMonospaceOptimizations(EditorOption.disableMonospaceOptimizations, 'disableMonospaceOptimizations', false, [EditorOption.fontLigatures])), + editorClassName: registerEditorOption(new EditorClassName(EditorOption.editorClassName, 'editorClassName', undefined, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])), + tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), + layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers])), wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, 'wrappingInfo', undefined, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), }; +// const tmp: { [key: string]: IEditorOption; } = EditorOptions; +// for (const key of Object.keys(tmp)) { +// const option = tmp[key]; +// if (key !== option.name) { +// throw new Error(`mismatch - ${key} - ${option.name}`); +// } +// } + export type EditorOptionsType = typeof EditorOptions; export type FindEditorOptionsKeyById = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType]; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index e4de9b731c1..d5162df16c7 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -113,14 +113,14 @@ export class CursorConfiguration { public static shouldRecreate(e: IConfigurationChangedEvent): boolean { return ( e.hasChanged(EditorOption.layoutInfo) - || e.wordSeparators - || e.emptySelectionClipboard - || e.multiCursorMergeOverlapping - || e.autoClosingBrackets - || e.autoClosingQuotes - || e.autoClosingOvertype - || e.autoSurround - || e.useTabStops + || e.hasChanged(EditorOption.wordSeparators) + || e.hasChanged(EditorOption.emptySelectionClipboard) + || e.hasChanged(EditorOption.multiCursorMergeOverlapping) + || e.hasChanged(EditorOption.autoClosingBrackets) + || e.hasChanged(EditorOption.autoClosingQuotes) + || e.hasChanged(EditorOption.autoClosingOvertype) + || e.hasChanged(EditorOption.autoSurround) + || e.hasChanged(EditorOption.useTabStops) || e.lineHeight || e.hasChanged(EditorOption.readOnly) ); @@ -143,16 +143,16 @@ export class CursorConfiguration { this.insertSpaces = modelOptions.insertSpaces; this.pageSize = Math.max(1, Math.floor(layoutInfo.height / c.fontInfo.lineHeight) - 2); this.lineHeight = c.lineHeight; - this.useTabStops = c.useTabStops; - this.wordSeparators = c.wordSeparators; - this.emptySelectionClipboard = c.emptySelectionClipboard; - this.copyWithSyntaxHighlighting = c.copyWithSyntaxHighlighting; - this.multiCursorMergeOverlapping = c.multiCursorMergeOverlapping; - this.autoClosingBrackets = c.autoClosingBrackets; - this.autoClosingQuotes = c.autoClosingQuotes; - this.autoClosingOvertype = c.autoClosingOvertype; - this.autoSurround = c.autoSurround; - this.autoIndent = c.autoIndent; + this.useTabStops = options.get(EditorOption.useTabStops); + this.wordSeparators = options.get(EditorOption.wordSeparators); + this.emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); + this.copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); + this.multiCursorMergeOverlapping = options.get(EditorOption.multiCursorMergeOverlapping); + this.autoClosingBrackets = options.get(EditorOption.autoClosingBrackets); + this.autoClosingQuotes = options.get(EditorOption.autoClosingQuotes); + this.autoClosingOvertype = options.get(EditorOption.autoClosingOvertype); + this.autoSurround = options.get(EditorOption.autoSurround); + this.autoIndent = options.get(EditorOption.autoIndent); this.autoClosingPairsOpen2 = new Map(); this.autoClosingPairsClose2 = new Map(); diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 4027972d75e..27c45cf7c94 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -441,31 +441,73 @@ export enum RenderLineNumbersType { export enum EditorOption { accessibilitySupport = 0, - ariaLabel = 1, - fastScrollSensitivity = 2, - folding = 3, - glyphMargin = 4, - inDiffEditor = 5, - lineDecorationsWidth = 6, - lineNumbersMinChars = 7, - minimap = 8, - mouseWheelScrollSensitivity = 9, - readOnly = 10, - renderFinalNewline = 11, - renderLineNumbers = 12, - scrollbar = 13, - selectionClipboard = 14, - selectOnLineNumbers = 15, - tabFocusMode = 16, - wordWrap = 17, - wordWrapBreakAfterCharacters = 18, - wordWrapBreakBeforeCharacters = 19, - wordWrapBreakObtrusiveCharacters = 20, - wordWrapColumn = 21, - wordWrapMinified = 22, - wrappingIndent = 23, - layoutInfo = 24, - wrappingInfo = 25 + autoClosingBrackets = 1, + autoClosingOvertype = 2, + autoClosingQuotes = 3, + autoIndent = 4, + automaticLayout = 5, + autoSurround = 6, + copyWithSyntaxHighlighting = 7, + cursorBlinking = 8, + cursorSmoothCaretAnimation = 9, + cursorStyle = 10, + cursorSurroundingLines = 11, + cursorWidth = 12, + disableLayerHinting = 13, + dragAndDrop = 14, + emptySelectionClipboard = 15, + extraEditorClassName = 16, + fastScrollSensitivity = 17, + fixedOverflowWidgets = 18, + folding = 19, + fontLigatures = 20, + glyphMargin = 21, + hideCursorInOverviewRuler = 22, + highlightActiveIndentGuide = 23, + inDiffEditor = 24, + lineDecorationsWidth = 25, + lineNumbers = 26, + lineNumbersMinChars = 27, + minimap = 28, + mouseStyle = 29, + mouseWheelScrollSensitivity = 30, + mouseWheelZoom = 31, + multiCursorMergeOverlapping = 32, + multiCursorModifier = 33, + overviewRulerBorder = 34, + overviewRulerLanes = 35, + readOnly = 36, + renderControlCharacters = 37, + renderIndentGuides = 38, + renderFinalNewline = 39, + renderLineHighlight = 40, + renderWhitespace = 41, + revealHorizontalRightPadding = 42, + roundedSelection = 43, + rulers = 44, + scrollbar = 45, + scrollBeyondLastColumn = 46, + scrollBeyondLastLine = 47, + selectionClipboard = 48, + selectOnLineNumbers = 49, + showUnused = 50, + smoothScrolling = 51, + stopRenderingLineAfter = 52, + useTabStops = 53, + wordSeparators = 54, + wordWrap = 55, + wordWrapBreakAfterCharacters = 56, + wordWrapBreakBeforeCharacters = 57, + wordWrapBreakObtrusiveCharacters = 58, + wordWrapColumn = 59, + wordWrapMinified = 60, + wrappingIndent = 61, + ariaLabel = 62, + disableMonospaceOptimizations = 63, + editorClassName = 64, + tabFocusMode = 65, + layoutInfo = 66, + wrappingInfo = 67 } /** diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index a3da3dfa94c..1416bd34077 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -35,25 +35,15 @@ export class ViewConfigurationChangedEvent { public readonly type = ViewEventType.ViewConfigurationChanged; public readonly _source: IConfigurationChangedEvent; - public readonly canUseLayerHinting: boolean; public readonly pixelRatio: boolean; - public readonly editorClassName: boolean; public readonly lineHeight: boolean; - public readonly emptySelectionClipboard: boolean; - public readonly copyWithSyntaxHighlighting: boolean; public readonly fontInfo: boolean; - public readonly viewInfo: boolean; constructor(source: IConfigurationChangedEvent) { this._source = source; - this.canUseLayerHinting = source.canUseLayerHinting; this.pixelRatio = source.pixelRatio; - this.editorClassName = source.editorClassName; this.lineHeight = source.lineHeight; - this.emptySelectionClipboard = source.emptySelectionClipboard; - this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting; this.fontInfo = source.fontInfo; - this.viewInfo = source.viewInfo; } public hasChanged(id: EditorOption): boolean { diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 6950cb302a8..952406baa27 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -53,7 +53,7 @@ export class ViewLayout extends Disposable implements IViewLayout { } private _configureSmoothScrollDuration(): void { - this.scrollable.setSmoothScrollDuration(this._configuration.editor.viewInfo.smoothScrolling ? SMOOTH_SCROLLING_TIME : 0); + this.scrollable.setSmoothScrollDuration(this._configuration.options.get(EditorOption.smoothScrolling) ? SMOOTH_SCROLLING_TIME : 0); } // ---- begin view event handlers @@ -70,7 +70,7 @@ export class ViewLayout extends Disposable implements IViewLayout { height: layoutInfo.contentHeight }); } - if (e.viewInfo) { + if (e.hasChanged(EditorOption.smoothScrolling)) { this._configureSmoothScrollDuration(); } this._updateHeight(); @@ -105,7 +105,7 @@ export class ViewLayout extends Disposable implements IViewLayout { const scrollDimensions = this.scrollable.getScrollDimensions(); let result = this._linesLayout.getLinesTotalHeight(); - if (this._configuration.editor.viewInfo.scrollBeyondLastLine) { + if (this._configuration.options.get(EditorOption.scrollBeyondLastLine)) { result += scrollDimensions.height - this._configuration.editor.lineHeight; } else { result += this._getHorizontalScrollbarHeight(scrollDimensions); @@ -149,7 +149,7 @@ export class ViewLayout extends Disposable implements IViewLayout { const wrappingInfo = options.get(EditorOption.wrappingInfo); let isViewportWrapping = wrappingInfo.isViewportWrapping; if (!isViewportWrapping) { - const extraHorizontalSpace = this._configuration.editor.viewInfo.scrollBeyondLastColumn * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + const extraHorizontalSpace = options.get(EditorOption.scrollBeyondLastColumn) * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; const whitespaceMinWidth = this._linesLayout.getWhitespaceMinWidth(); return Math.max(maxLineWidth + extraHorizontalSpace, viewportWidth, whitespaceMinWidth); } diff --git a/src/vs/editor/contrib/clipboard/clipboard.ts b/src/vs/editor/contrib/clipboard/clipboard.ts index c0929f47d00..df241dc8643 100644 --- a/src/vs/editor/contrib/clipboard/clipboard.ts +++ b/src/vs/editor/contrib/clipboard/clipboard.ts @@ -16,6 +16,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { MenuId } from 'vs/platform/actions/common/actions'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const CLIPBOARD_CONTEXT_MENU_GROUP = '9_cutcopypaste'; @@ -94,7 +95,7 @@ class ExecCommandCutAction extends ExecCommandAction { return; } - const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; + const emptySelectionClipboard = editor.getOption(EditorOption.emptySelectionClipboard); if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { return; @@ -143,7 +144,7 @@ class ExecCommandCopyAction extends ExecCommandAction { return; } - const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; + const emptySelectionClipboard = editor.getOption(EditorOption.emptySelectionClipboard); if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { return; @@ -209,7 +210,7 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction { return; } - const emptySelectionClipboard = editor.getConfiguration().emptySelectionClipboard; + const emptySelectionClipboard = editor.getOption(EditorOption.emptySelectionClipboard); if (!emptySelectionClipboard && editor.getSelection().isEmpty()) { return; diff --git a/src/vs/editor/contrib/dnd/dnd.ts b/src/vs/editor/contrib/dnd/dnd.ts index 70b3551b532..bbf3df37d01 100644 --- a/src/vs/editor/contrib/dnd/dnd.ts +++ b/src/vs/editor/contrib/dnd/dnd.ts @@ -19,6 +19,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; import { IModelDeltaDecoration } from 'vs/editor/common/model'; import { IMouseEvent } from 'vs/base/browser/mouseEvent'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; function hasTriggerModifier(e: IKeyboardEvent | IMouseEvent): boolean { if (isMacintosh) { @@ -67,7 +68,7 @@ export class DragAndDropController extends Disposable implements editorCommon.IE } private onEditorKeyDown(e: IKeyboardEvent): void { - if (!this._editor.getConfiguration().dragAndDrop) { + if (!this._editor.getOption(EditorOption.dragAndDrop)) { return; } @@ -83,7 +84,7 @@ export class DragAndDropController extends Disposable implements editorCommon.IE } private onEditorKeyUp(e: IKeyboardEvent): void { - if (!this._editor.getConfiguration().dragAndDrop) { + if (!this._editor.getOption(EditorOption.dragAndDrop)) { return; } diff --git a/src/vs/editor/contrib/find/findModel.ts b/src/vs/editor/contrib/find/findModel.ts index faca23f0a55..c25fd810bad 100644 --- a/src/vs/editor/contrib/find/findModel.ts +++ b/src/vs/editor/contrib/find/findModel.ts @@ -22,6 +22,7 @@ import { ReplaceAllCommand } from 'vs/editor/contrib/find/replaceAllCommand'; import { ReplacePattern, parseReplaceString } from 'vs/editor/contrib/find/replacePattern'; import { ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IKeybindings } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const CONTEXT_FIND_WIDGET_VISIBLE = new RawContextKey('findWidgetVisible', false); export const CONTEXT_FIND_WIDGET_NOT_VISIBLE: ContextKeyExpr = CONTEXT_FIND_WIDGET_VISIBLE.toNegated(); @@ -287,12 +288,12 @@ export class FindModelBoundToEditorModel { let position = new Position(lineNumber, column); - let prevMatch = model.findPreviousMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false); + let prevMatch = model.findPreviousMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false); if (prevMatch && prevMatch.range.isEmpty() && prevMatch.range.getStartPosition().equals(position)) { // Looks like we're stuck at this position, unacceptable! position = this._prevSearchPosition(position); - prevMatch = model.findPreviousMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false); + prevMatch = model.findPreviousMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false); } if (!prevMatch) { @@ -379,12 +380,12 @@ export class FindModelBoundToEditorModel { let position = new Position(lineNumber, column); - let nextMatch = model.findNextMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null, captureMatches); + let nextMatch = model.findNextMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, captureMatches); if (forceMove && nextMatch && nextMatch.range.isEmpty() && nextMatch.range.getStartPosition().equals(position)) { // Looks like we're stuck at this position, unacceptable! position = this._nextSearchPosition(position); - nextMatch = model.findNextMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null, captureMatches); + nextMatch = model.findNextMatch(this._state.searchString, position, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, captureMatches); } if (!nextMatch) { @@ -438,7 +439,7 @@ export class FindModelBoundToEditorModel { private _findMatches(findScope: Range | null, captureMatches: boolean, limitResultCount: number): FindMatch[] { let searchRange = FindModelBoundToEditorModel._getSearchRange(this._editor.getModel(), findScope); - return this._editor.getModel().findMatches(this._state.searchString, searchRange, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null, captureMatches, limitResultCount); + return this._editor.getModel().findMatches(this._state.searchString, searchRange, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, captureMatches, limitResultCount); } public replaceAll(): void { @@ -459,7 +460,7 @@ export class FindModelBoundToEditorModel { } private _largeReplaceAll(): void { - const searchParams = new SearchParams(this._state.searchString, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getConfiguration().wordSeparators : null); + const searchParams = new SearchParams(this._state.searchString, this._state.isRegex, this._state.matchCase, this._state.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null); const searchData = searchParams.parseSearchRequest(); if (!searchData) { return; diff --git a/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts b/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts index 3b72a01a35c..f23c13dcd38 100644 --- a/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts +++ b/src/vs/editor/contrib/goToDefinition/clickLinkGesture.ts @@ -12,6 +12,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { Event, Emitter } from 'vs/base/common/event'; import * as platform from 'vs/base/common/platform'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; function hasModifier(e: { ctrlKey: boolean; shiftKey: boolean; altKey: boolean; metaKey: boolean }, modifier: 'ctrlKey' | 'shiftKey' | 'altKey' | 'metaKey'): boolean { return !!e[modifier]; @@ -116,14 +117,14 @@ export class ClickLinkGesture extends Disposable { super(); this._editor = editor; - this._opts = createOptions(this._editor.getConfiguration().multiCursorModifier); + this._opts = createOptions(this._editor.getOption(EditorOption.multiCursorModifier)); this.lastMouseMoveEvent = null; this.hasTriggerKeyOnMouseDown = false; this._register(this._editor.onDidChangeConfiguration((e) => { - if (e.multiCursorModifier) { - const newOpts = createOptions(this._editor.getConfiguration().multiCursorModifier); + if (e.hasChanged(EditorOption.multiCursorModifier)) { + const newOpts = createOptions(this._editor.getOption(EditorOption.multiCursorModifier)); if (this._opts.equals(newOpts)) { return; } diff --git a/src/vs/editor/contrib/indentation/indentation.ts b/src/vs/editor/contrib/indentation/indentation.ts index fd9fcee54ea..cc2c6904bfa 100644 --- a/src/vs/editor/contrib/indentation/indentation.ts +++ b/src/vs/editor/contrib/indentation/indentation.ts @@ -22,6 +22,7 @@ import { IndentConsts } from 'vs/editor/common/modes/supports/indentRules'; import { IModelService } from 'vs/editor/common/services/modelService'; import * as indentUtils from 'vs/editor/contrib/indentation/indentUtils'; import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export function getReindentEditOperations(model: ITextModel, startLineNumber: number, endLineNumber: number, inheritedIndent?: string): IIdentifiedSingleEditOperation[] { if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) { @@ -443,7 +444,7 @@ export class AutoIndentOnPaste implements IEditorContribution { this.callOnModel = dispose(this.callOnModel); // we are disabled - if (!this.editor.getConfiguration().autoIndent || this.editor.getConfiguration().contribInfo.formatOnPaste) { + if (!this.editor.getOption(EditorOption.autoIndent) || this.editor.getConfiguration().contribInfo.formatOnPaste) { return; } diff --git a/src/vs/editor/contrib/linesOperations/linesOperations.ts b/src/vs/editor/contrib/linesOperations/linesOperations.ts index 9fb95158f25..7f1d517236a 100644 --- a/src/vs/editor/contrib/linesOperations/linesOperations.ts +++ b/src/vs/editor/contrib/linesOperations/linesOperations.ts @@ -23,6 +23,7 @@ import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/moveLinesCom import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/sortLinesCommand'; import { MenuId } from 'vs/platform/actions/common/actions'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; // copy lines @@ -111,7 +112,7 @@ abstract class AbstractMoveLinesAction extends EditorAction { let commands: ICommand[] = []; let selections = editor.getSelections() || []; - let autoIndent = editor.getConfiguration().autoIndent; + const autoIndent = editor.getOption(EditorOption.autoIndent); for (const selection of selections) { commands.push(new MoveLinesCommand(selection, this.down, autoIndent)); @@ -886,7 +887,7 @@ export abstract class AbstractCaseAction extends EditorAction { return; } - let wordSeparators = editor.getConfiguration().wordSeparators; + let wordSeparators = editor.getOption(EditorOption.wordSeparators); let commands: ICommand[] = []; diff --git a/src/vs/editor/contrib/links/links.ts b/src/vs/editor/contrib/links/links.ts index f9f19e5211c..237ced230c0 100644 --- a/src/vs/editor/contrib/links/links.ts +++ b/src/vs/editor/contrib/links/links.ts @@ -24,6 +24,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { IOpenerService } from 'vs/platform/opener/common/opener'; import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; function getHoverMessage(link: Link, useMetaKey: boolean): MarkdownString { const executeCmd = link.url && /^command:/i.test(link.url.toString()); @@ -218,7 +219,7 @@ class LinkDetector implements editorCommon.IEditorContribution { } private updateDecorations(links: Link[]): void { - const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey'); + const useMetaKey = (this.editor.getOption(EditorOption.multiCursorModifier) === 'altKey'); let oldDecorations: string[] = []; let keys = Object.keys(this.currentOccurrences); for (let i = 0, len = keys.length; i < len; i++) { @@ -246,7 +247,7 @@ class LinkDetector implements editorCommon.IEditorContribution { } private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey: ClickLinkKeyboardEvent | null): void { - const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey'); + const useMetaKey = (this.editor.getOption(EditorOption.multiCursorModifier) === 'altKey'); if (this.isEnabled(mouseEvent, withKey)) { this.cleanUpActiveLinkDecoration(); // always remove previous link decoration as their can only be one const occurrence = this.getLinkOccurrence(mouseEvent.target.position); @@ -262,7 +263,7 @@ class LinkDetector implements editorCommon.IEditorContribution { } private cleanUpActiveLinkDecoration(): void { - const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey'); + const useMetaKey = (this.editor.getOption(EditorOption.multiCursorModifier) === 'altKey'); if (this.activeLinkDecorationId) { const occurrence = this.currentOccurrences[this.activeLinkDecorationId]; if (occurrence) { diff --git a/src/vs/editor/contrib/multicursor/multicursor.ts b/src/vs/editor/contrib/multicursor/multicursor.ts index ec0925af31a..4da9f349005 100644 --- a/src/vs/editor/contrib/multicursor/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/multicursor.ts @@ -26,6 +26,7 @@ import { MenuId } from 'vs/platform/actions/common/actions'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { overviewRulerSelectionHighlightForeground } from 'vs/platform/theme/common/colorRegistry'; import { themeColorFromId } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class InsertCursorAbove extends EditorAction { @@ -350,7 +351,7 @@ export class MultiCursorSession { const allSelections = this._editor.getSelections(); const lastAddedSelection = allSelections[allSelections.length - 1]; - const nextMatch = this._editor.getModel().findNextMatch(this.searchText, lastAddedSelection.getEndPosition(), false, this.matchCase, this.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false); + const nextMatch = this._editor.getModel().findNextMatch(this.searchText, lastAddedSelection.getEndPosition(), false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false); if (!nextMatch) { return null; @@ -401,7 +402,7 @@ export class MultiCursorSession { const allSelections = this._editor.getSelections(); const lastAddedSelection = allSelections[allSelections.length - 1]; - const previousMatch = this._editor.getModel().findPreviousMatch(this.searchText, lastAddedSelection.getStartPosition(), false, this.matchCase, this.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false); + const previousMatch = this._editor.getModel().findPreviousMatch(this.searchText, lastAddedSelection.getStartPosition(), false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false); if (!previousMatch) { return null; @@ -416,7 +417,7 @@ export class MultiCursorSession { this.findController.highlightFindOptions(); - return this._editor.getModel().findMatches(this.searchText, true, false, this.matchCase, this.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false, Constants.MAX_SAFE_SMALL_INTEGER); + return this._editor.getModel().findMatches(this.searchText, true, false, this.matchCase, this.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER); } } @@ -593,7 +594,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito // - and we're searching for a regex if (findState.isRevealed && findState.searchString.length > 0 && findState.isRegex) { - matches = this._editor.getModel().findMatches(findState.searchString, true, findState.isRegex, findState.matchCase, findState.wholeWord ? this._editor.getConfiguration().wordSeparators : null, false, Constants.MAX_SAFE_SMALL_INTEGER); + matches = this._editor.getModel().findMatches(findState.searchString, true, findState.isRegex, findState.matchCase, findState.wholeWord ? this._editor.getOption(EditorOption.wordSeparators) : null, false, Constants.MAX_SAFE_SMALL_INTEGER); } else { @@ -928,7 +929,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut } } - return new SelectionHighlighterState(r.searchText, r.matchCase, r.wholeWord ? editor.getConfiguration().wordSeparators : null); + return new SelectionHighlighterState(r.searchText, r.matchCase, r.wholeWord ? editor.getOption(EditorOption.wordSeparators) : null); } private _setState(state: SelectionHighlighterState | null): void { @@ -1053,4 +1054,4 @@ registerEditorAction(MoveSelectionToPreviousFindMatchAction); registerEditorAction(SelectHighlightsAction); registerEditorAction(CompatChangeAll); registerEditorAction(InsertCursorAtEndOfLineSelected); -registerEditorAction(InsertCursorAtTopOfLineSelected); \ No newline at end of file +registerEditorAction(InsertCursorAtTopOfLineSelected); diff --git a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts index 4fd4f5d2db0..4e05c3ff8a9 100644 --- a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts @@ -26,6 +26,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { activeContrastBorder, editorSelectionHighlight, editorSelectionHighlightBorder, overviewRulerSelectionHighlightForeground, registerColor } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant, themeColorFromId } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const editorWordHighlight = registerColor('editor.wordHighlightBackground', { dark: '#575757B8', light: '#57575740', hc: null }, nls.localize('wordHighlight', 'Background color of a symbol during read-access, like reading a variable. The color must not be opaque so as not to hide underlying decorations.'), true); export const editorWordHighlightStrong = registerColor('editor.wordHighlightStrongBackground', { dark: '#004972B8', light: '#0e639c40', hc: null }, nls.localize('wordHighlightStrong', 'Background color of a symbol during write-access, like writing to a variable. The color must not be opaque so as not to hide underlying decorations.'), true); @@ -371,7 +372,7 @@ class WordHighlighter { let myRequestId = ++this.workerRequestTokenId; this.workerRequestCompleted = false; - this.workerRequest = computeOccurencesAtPosition(this.model, this.editor.getSelection(), this.editor.getConfiguration().wordSeparators); + this.workerRequest = computeOccurencesAtPosition(this.model, this.editor.getSelection(), this.editor.getOption(EditorOption.wordSeparators)); this.workerRequest.result.then(data => { if (myRequestId === this.workerRequestTokenId) { diff --git a/src/vs/editor/contrib/wordOperations/wordOperations.ts b/src/vs/editor/contrib/wordOperations/wordOperations.ts index a0e5e226cdd..5e77d1c0607 100644 --- a/src/vs/editor/contrib/wordOperations/wordOperations.ts +++ b/src/vs/editor/contrib/wordOperations/wordOperations.ts @@ -20,7 +20,7 @@ import { ITextModel } from 'vs/editor/common/model'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/common/accessibility'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; -import { EDITOR_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { EditorOption, EditorOptions } from 'vs/editor/common/config/editorOptions'; export interface MoveWordOptions extends ICommandOptions { inSelectionMode: boolean; @@ -42,8 +42,7 @@ export abstract class MoveWordCommand extends EditorCommand { if (!editor.hasModel()) { return; } - const config = editor.getConfiguration(); - const wordSeparators = getMapForWordSeparators(config.wordSeparators); + const wordSeparators = getMapForWordSeparators(editor.getOption(EditorOption.wordSeparators)); const model = editor.getModel(); const selections = editor.getSelections(); @@ -190,7 +189,7 @@ export class CursorWordAccessibilityLeft extends WordLeftCommand { } protected _move(_: WordCharacterClassifier, model: ITextModel, position: Position, wordNavigationType: WordNavigationType): Position { - return super._move(getMapForWordSeparators(EDITOR_DEFAULTS.wordSeparators), model, position, wordNavigationType); + return super._move(getMapForWordSeparators(EditorOptions.wordSeparators.defaultValue), model, position, wordNavigationType); } } @@ -211,7 +210,7 @@ export class CursorWordAccessibilityLeftSelect extends WordLeftCommand { } protected _move(_: WordCharacterClassifier, model: ITextModel, position: Position, wordNavigationType: WordNavigationType): Position { - return super._move(getMapForWordSeparators(EDITOR_DEFAULTS.wordSeparators), model, position, wordNavigationType); + return super._move(getMapForWordSeparators(EditorOptions.wordSeparators.defaultValue), model, position, wordNavigationType); } } @@ -310,7 +309,7 @@ export class CursorWordAccessibilityRight extends WordRightCommand { } protected _move(_: WordCharacterClassifier, model: ITextModel, position: Position, wordNavigationType: WordNavigationType): Position { - return super._move(getMapForWordSeparators(EDITOR_DEFAULTS.wordSeparators), model, position, wordNavigationType); + return super._move(getMapForWordSeparators(EditorOptions.wordSeparators.defaultValue), model, position, wordNavigationType); } } @@ -331,7 +330,7 @@ export class CursorWordAccessibilityRightSelect extends WordRightCommand { } protected _move(_: WordCharacterClassifier, model: ITextModel, position: Position, wordNavigationType: WordNavigationType): Position { - return super._move(getMapForWordSeparators(EDITOR_DEFAULTS.wordSeparators), model, position, wordNavigationType); + return super._move(getMapForWordSeparators(EditorOptions.wordSeparators.defaultValue), model, position, wordNavigationType); } } @@ -354,8 +353,7 @@ export abstract class DeleteWordCommand extends EditorCommand { if (!editor.hasModel()) { return; } - const config = editor.getConfiguration(); - const wordSeparators = getMapForWordSeparators(config.wordSeparators); + const wordSeparators = getMapForWordSeparators(editor.getOption(EditorOption.wordSeparators)); const model = editor.getModel(); const selections = editor.getSelections(); diff --git a/src/vs/editor/editor.api.ts b/src/vs/editor/editor.api.ts index e535b3e4456..a4e36c33fe0 100644 --- a/src/vs/editor/editor.api.ts +++ b/src/vs/editor/editor.api.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { EDITOR_DEFAULTS, WrappingIndent } from 'vs/editor/common/config/editorOptions'; +import { EditorOptions } from 'vs/editor/common/config/editorOptions'; import { createMonacoBaseAPI } from 'vs/editor/common/standalone/standaloneBase'; import { createMonacoEditorAPI } from 'vs/editor/standalone/browser/standaloneEditor'; import { createMonacoLanguagesAPI } from 'vs/editor/standalone/browser/standaloneLanguages'; @@ -11,9 +11,9 @@ import { createMonacoLanguagesAPI } from 'vs/editor/standalone/browser/standalon const global: any = self; // Set defaults for standalone editor -(EDITOR_DEFAULTS).wrappingIndent = WrappingIndent.None; -(EDITOR_DEFAULTS.viewInfo).glyphMargin = false; -(EDITOR_DEFAULTS).autoIndent = false; +(EditorOptions.wrappingIndent).defaultValue = 'none'; +(EditorOptions.glyphMargin).defaultValue = false; +(EditorOptions.autoIndent).defaultValue = false; const api = createMonacoBaseAPI(); api.editor = createMonacoEditorAPI(); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 304261d9342..c74ca442fdd 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2746,7 +2746,7 @@ declare namespace monaco.editor { * Control the cursor animation style, possible values are 'blink', 'smooth', 'phase', 'expand' and 'solid'. * Defaults to 'blink'. */ - cursorBlinking?: string; + cursorBlinking?: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid'; /** * Zoom the font in the editor when using the mouse wheel in combination with holding Ctrl. * Defaults to false. @@ -2761,7 +2761,7 @@ declare namespace monaco.editor { * Control the cursor style, either 'block' or 'line'. * Defaults to 'line'. */ - cursorStyle?: string; + cursorStyle?: 'line' | 'block' | 'underline' | 'line-thin' | 'block-outline' | 'underline-thin'; /** * Control the width of the cursor when cursorStyle is set to 'line' */ @@ -3269,35 +3269,6 @@ declare namespace monaco.editor { readonly cycle: boolean; } - export interface InternalEditorViewOptions { - readonly extraEditorClassName: string; - readonly disableMonospaceOptimizations: boolean; - readonly rulers: number[]; - readonly cursorSurroundingLines: number; - readonly glyphMargin: boolean; - readonly revealHorizontalRightPadding: number; - readonly roundedSelection: boolean; - readonly overviewRulerLanes: number; - readonly overviewRulerBorder: boolean; - readonly cursorBlinking: TextEditorCursorBlinkingStyle; - readonly mouseWheelZoom: boolean; - readonly cursorSmoothCaretAnimation: boolean; - readonly cursorStyle: TextEditorCursorStyle; - readonly cursorWidth: number; - readonly hideCursorInOverviewRuler: boolean; - readonly scrollBeyondLastLine: boolean; - readonly scrollBeyondLastColumn: number; - readonly smoothScrolling: boolean; - readonly stopRenderingLineAfter: number; - readonly renderWhitespace: 'none' | 'boundary' | 'selection' | 'all'; - readonly renderControlCharacters: boolean; - readonly fontLigatures: boolean; - readonly renderIndentGuides: boolean; - readonly highlightActiveIndentGuide: boolean; - readonly renderLineHighlight: 'none' | 'gutter' | 'line' | 'all'; - readonly fixedOverflowWidgets: boolean; - } - export interface EditorContribOptions { readonly hover: InternalEditorHoverOptions; readonly links: boolean; @@ -3339,25 +3310,9 @@ declare namespace monaco.editor { */ export class InternalEditorOptions { readonly _internalEditorOptionsBrand: void; - readonly canUseLayerHinting: boolean; readonly pixelRatio: number; - readonly editorClassName: string; readonly lineHeight: number; - readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; - readonly multiCursorMergeOverlapping: boolean; - readonly showUnused: boolean; - readonly wordSeparators: string; - readonly autoClosingBrackets: EditorAutoClosingStrategy; - readonly autoClosingQuotes: EditorAutoClosingStrategy; - readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy; - readonly autoSurround: EditorAutoSurroundStrategy; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; readonly fontInfo: FontInfo; - readonly viewInfo: InternalEditorViewOptions; readonly contribInfo: EditorContribOptions; } @@ -3366,24 +3321,9 @@ declare namespace monaco.editor { */ export interface IConfigurationChangedEvent { hasChanged(id: EditorOption): boolean; - readonly canUseLayerHinting: boolean; readonly pixelRatio: boolean; - readonly editorClassName: boolean; readonly lineHeight: boolean; - readonly multiCursorModifier: boolean; - readonly multiCursorMergeOverlapping: boolean; - readonly wordSeparators: boolean; - readonly autoClosingBrackets: boolean; - readonly autoClosingQuotes: boolean; - readonly autoClosingOvertype: boolean; - readonly autoSurround: boolean; - readonly autoIndent: boolean; - readonly useTabStops: boolean; - readonly dragAndDrop: boolean; - readonly emptySelectionClipboard: boolean; - readonly copyWithSyntaxHighlighting: boolean; readonly fontInfo: boolean; - readonly viewInfo: boolean; readonly contribInfo: boolean; } @@ -3595,51 +3535,131 @@ declare namespace monaco.editor { export enum EditorOption { accessibilitySupport = 0, - ariaLabel = 1, - fastScrollSensitivity = 2, - folding = 3, - glyphMargin = 4, - inDiffEditor = 5, - lineDecorationsWidth = 6, - lineNumbersMinChars = 7, - minimap = 8, - mouseWheelScrollSensitivity = 9, - readOnly = 10, - renderFinalNewline = 11, - renderLineNumbers = 12, - scrollbar = 13, - selectionClipboard = 14, - selectOnLineNumbers = 15, - tabFocusMode = 16, - wordWrap = 17, - wordWrapBreakAfterCharacters = 18, - wordWrapBreakBeforeCharacters = 19, - wordWrapBreakObtrusiveCharacters = 20, - wordWrapColumn = 21, - wordWrapMinified = 22, - wrappingIndent = 23, - layoutInfo = 24, - wrappingInfo = 25 + autoClosingBrackets = 1, + autoClosingOvertype = 2, + autoClosingQuotes = 3, + autoIndent = 4, + automaticLayout = 5, + autoSurround = 6, + copyWithSyntaxHighlighting = 7, + cursorBlinking = 8, + cursorSmoothCaretAnimation = 9, + cursorStyle = 10, + cursorSurroundingLines = 11, + cursorWidth = 12, + disableLayerHinting = 13, + dragAndDrop = 14, + emptySelectionClipboard = 15, + extraEditorClassName = 16, + fastScrollSensitivity = 17, + fixedOverflowWidgets = 18, + folding = 19, + fontLigatures = 20, + glyphMargin = 21, + hideCursorInOverviewRuler = 22, + highlightActiveIndentGuide = 23, + inDiffEditor = 24, + lineDecorationsWidth = 25, + lineNumbers = 26, + lineNumbersMinChars = 27, + minimap = 28, + mouseStyle = 29, + mouseWheelScrollSensitivity = 30, + mouseWheelZoom = 31, + multiCursorMergeOverlapping = 32, + multiCursorModifier = 33, + overviewRulerBorder = 34, + overviewRulerLanes = 35, + readOnly = 36, + renderControlCharacters = 37, + renderIndentGuides = 38, + renderFinalNewline = 39, + renderLineHighlight = 40, + renderWhitespace = 41, + revealHorizontalRightPadding = 42, + roundedSelection = 43, + rulers = 44, + scrollbar = 45, + scrollBeyondLastColumn = 46, + scrollBeyondLastLine = 47, + selectionClipboard = 48, + selectOnLineNumbers = 49, + showUnused = 50, + smoothScrolling = 51, + stopRenderingLineAfter = 52, + useTabStops = 53, + wordSeparators = 54, + wordWrap = 55, + wordWrapBreakAfterCharacters = 56, + wordWrapBreakBeforeCharacters = 57, + wordWrapBreakObtrusiveCharacters = 58, + wordWrapColumn = 59, + wordWrapMinified = 60, + wrappingIndent = 61, + ariaLabel = 62, + disableMonospaceOptimizations = 63, + editorClassName = 64, + tabFocusMode = 65, + layoutInfo = 66, + wrappingInfo = 67 } export const EditorOptions: { accessibilitySupport: any; - ariaLabel: any; + autoClosingBrackets: any; + autoClosingOvertype: any; + autoClosingQuotes: any; + autoIndent: any; + automaticLayout: any; + autoSurround: any; + copyWithSyntaxHighlighting: any; + cursorBlinking: any; + cursorSmoothCaretAnimation: any; + cursorStyle: any; + cursorSurroundingLines: any; + cursorWidth: any; + disableLayerHinting: any; + dragAndDrop: any; + emptySelectionClipboard: any; + extraEditorClassName: any; fastScrollSensitivity: any; + fixedOverflowWidgets: any; folding: any; + fontLigatures: any; glyphMargin: any; + hideCursorInOverviewRuler: any; + highlightActiveIndentGuide: any; inDiffEditor: any; lineDecorationsWidth: IEditorOption; + lineNumbers: any; lineNumbersMinChars: any; minimap: any; + mouseStyle: any; mouseWheelScrollSensitivity: any; + mouseWheelZoom: any; + multiCursorMergeOverlapping: any; + multiCursorModifier: any; + overviewRulerBorder: any; + overviewRulerLanes: any; readOnly: any; + renderControlCharacters: any; + renderIndentGuides: any; renderFinalNewline: any; - renderLineNumbers: any; + renderLineHighlight: any; + renderWhitespace: any; + revealHorizontalRightPadding: any; + roundedSelection: any; + rulers: any; scrollbar: any; + scrollBeyondLastColumn: any; + scrollBeyondLastLine: any; selectionClipboard: any; selectOnLineNumbers: any; - tabFocusMode: any; + showUnused: any; + smoothScrolling: any; + stopRenderingLineAfter: any; + useTabStops: any; + wordSeparators: any; wordWrap: any; wordWrapBreakAfterCharacters: any; wordWrapBreakBeforeCharacters: any; @@ -3647,6 +3667,10 @@ declare namespace monaco.editor { wordWrapColumn: any; wordWrapMinified: any; wrappingIndent: any; + ariaLabel: any; + disableMonospaceOptimizations: any; + editorClassName: any; + tabFocusMode: any; layoutInfo: any; wrappingInfo: any; }; diff --git a/src/vs/workbench/api/browser/mainThreadEditor.ts b/src/vs/workbench/api/browser/mainThreadEditor.ts index 2d210bb3feb..520801babe6 100644 --- a/src/vs/workbench/api/browser/mainThreadEditor.ts +++ b/src/vs/workbench/api/browser/mainThreadEditor.ts @@ -58,11 +58,10 @@ export class MainThreadTextEditorProperties { let cursorStyle: TextEditorCursorStyle; let lineNumbers: RenderLineNumbersType; if (codeEditor) { - const codeEditorOpts = codeEditor.getConfiguration(); const options = codeEditor.getOptions(); - const renderLineNumbers = options.get(EditorOption.renderLineNumbers); - cursorStyle = codeEditorOpts.viewInfo.cursorStyle; - lineNumbers = renderLineNumbers.renderType; + const lineNumbersOpts = options.get(EditorOption.lineNumbers); + cursorStyle = options.get(EditorOption.cursorStyle); + lineNumbers = lineNumbersOpts.renderType; } else if (previousProperties) { cursorStyle = previousProperties.options.cursorStyle; lineNumbers = previousProperties.options.lineNumbers; diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts index ccede6e64c6..94a0f2cd235 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts @@ -31,6 +31,7 @@ import { IFilterResult, IPreferencesEditorModel, IPreferencesService, ISetting, import { DefaultSettingsEditorModel, SettingsEditorModel, WorkspaceConfigurationEditorModel } from 'vs/workbench/services/preferences/common/preferencesModels'; import { IMarkerService, IMarkerData, MarkerSeverity, MarkerTag } from 'vs/platform/markers/common/markers'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IPreferencesRenderer extends IDisposable { readonly preferencesModel: IPreferencesEditorModel; @@ -690,7 +691,7 @@ class EditSettingRenderer extends Disposable { } private onConfigurationChanged(): void { - if (!this.editor.getConfiguration().viewInfo.glyphMargin) { + if (!this.editor.getOption(EditorOption.glyphMargin)) { this.editPreferenceWidgetForCursorPosition.hide(); this.editPreferenceWidgetForMouseMove.hide(); } @@ -740,7 +741,7 @@ class EditSettingRenderer extends Disposable { private showEditPreferencesWidget(editPreferencesWidget: EditPreferenceWidget, settings: IIndexedSetting[]) { const line = settings[0].valueRange.startLineNumber; - if (this.editor.getConfiguration().viewInfo.glyphMargin && this.marginFreeFromOtherDecorations(line)) { + if (this.editor.getOption(EditorOption.glyphMargin) && this.marginFreeFromOtherDecorations(line)) { editPreferencesWidget.show(line, nls.localize('editTtile', "Edit"), settings); const editPreferenceWidgetToHide = editPreferencesWidget === this.editPreferenceWidgetForCursorPosition ? this.editPreferenceWidgetForMouseMove : this.editPreferenceWidgetForCursorPosition; editPreferenceWidgetToHide.hide(); diff --git a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts index 5a0e888e931..59ef23bc2e1 100644 --- a/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/gotoLineHandler.ts @@ -51,8 +51,8 @@ export class GotoLineAction extends QuickOpenAction { if (isCodeEditor(activeTextEditorWidget)) { const options = activeTextEditorWidget.getOptions(); - const renderLineNumbers = options.get(EditorOption.renderLineNumbers); - if (renderLineNumbers.renderType === RenderLineNumbersType.Relative) { + const lineNumbers = options.get(EditorOption.lineNumbers); + if (lineNumbers.renderType === RenderLineNumbersType.Relative) { activeTextEditorWidget.updateOptions({ lineNumbers: 'on' }); From 802826e02a33b699d5c7f53dc1c5c69da44ffeed Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 3 Sep 2019 23:10:32 +0200 Subject: [PATCH 010/109] Move more editor options --- .../common/config/commonEditorConfig.ts | 35 ++-- src/vs/editor/common/config/editorOptions.ts | 141 +++++++------ .../common/standalone/standaloneEnums.ts | 151 +++++++------- .../bracketMatching/bracketMatching.ts | 7 +- .../contrib/codeAction/lightBulbWidget.ts | 6 +- .../contrib/codelens/codelensController.ts | 5 +- .../contrib/colorPicker/colorDetector.ts | 3 +- .../editor/contrib/contextmenu/contextmenu.ts | 5 +- src/vs/editor/contrib/format/formatActions.ts | 5 +- .../editor/contrib/indentation/indentation.ts | 2 +- src/vs/editor/contrib/links/links.ts | 4 +- .../editor/contrib/multicursor/multicursor.ts | 4 +- .../suggest/suggestCommitCharacters.ts | 3 +- .../contrib/suggest/suggestController.ts | 5 +- src/vs/editor/contrib/suggest/suggestModel.ts | 4 +- .../wordHighlighter/wordHighlighter.ts | 4 +- src/vs/monaco.d.ts | 187 ++++++++++-------- 17 files changed, 308 insertions(+), 263 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index df3551bfebd..3e48ce0e7b8 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -155,6 +155,13 @@ function migrateOptions(options: IEditorOptions): void { } else if (renderLineHighlight === false) { options.renderLineHighlight = 'none'; } + + let acceptSuggestionOnEnter = options.acceptSuggestionOnEnter; + if (acceptSuggestionOnEnter === true) { + options.acceptSuggestionOnEnter = 'on'; + } else if (acceptSuggestionOnEnter === false) { + options.acceptSuggestionOnEnter = 'off'; + } } export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { @@ -633,7 +640,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.quickSuggestionsDelay': { 'type': 'integer', - 'default': EDITOR_DEFAULTS.contribInfo.quickSuggestionsDelay, + 'default': EditorOptions.quickSuggestionsDelay.defaultValue, 'minimum': 0, 'description': nls.localize('quickSuggestionsDelay', "Controls the delay in milliseconds after which quick suggestions will show up.") }, @@ -696,12 +703,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.formatOnType': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.formatOnType, + 'default': EditorOptions.formatOnType.defaultValue, 'description': nls.localize('formatOnType', "Controls whether the editor should automatically format the line after typing.") }, 'editor.formatOnPaste': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.formatOnPaste, + 'default': EditorOptions.formatOnPaste.defaultValue, '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.") }, 'editor.autoIndent': { @@ -711,13 +718,13 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.suggestOnTriggerCharacters': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.suggestOnTriggerCharacters, + 'default': EditorOptions.suggestOnTriggerCharacters.defaultValue, 'description': nls.localize('suggestOnTriggerCharacters', "Controls whether suggestions should automatically show up when typing trigger characters.") }, 'editor.acceptSuggestionOnEnter': { 'type': 'string', 'enum': ['on', 'smart', 'off'], - 'default': EDITOR_DEFAULTS.contribInfo.acceptSuggestionOnEnter, + 'default': EditorOptions.acceptSuggestionOnEnter.defaultValue, 'markdownEnumDescriptions': [ '', nls.localize('acceptSuggestionOnEnterSmart', "Only accept a suggestion with `Enter` when it makes a textual change."), @@ -727,7 +734,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.acceptSuggestionOnCommitCharacter': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.acceptSuggestionOnCommitCharacter, + 'default': EditorOptions.acceptSuggestionOnCommitCharacter.defaultValue, '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.") }, 'editor.snippetSuggestions': { @@ -754,7 +761,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.wordBasedSuggestions': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.wordBasedSuggestions, + 'default': EditorOptions.wordBasedSuggestions.defaultValue, 'description': nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document.") }, 'editor.suggestSelection': { @@ -973,12 +980,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.selectionHighlight': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.selectionHighlight, + 'default': EditorOptions.selectionHighlight.defaultValue, 'description': nls.localize('selectionHighlight', "Controls whether the editor should highlight matches similar to the selection.") }, 'editor.occurrencesHighlight': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.occurrencesHighlight, + 'default': EditorOptions.occurrencesHighlight.defaultValue, 'description': nls.localize('occurrencesHighlight', "Controls whether the editor should highlight semantic symbol occurrences.") }, 'editor.overviewRulerLanes': { @@ -1069,7 +1076,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.codeLens': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.codeLens, + 'default': EditorOptions.codeLens.defaultValue, 'description': nls.localize('codeLens', "Controls whether the editor shows CodeLens.") }, 'editor.folding': { @@ -1091,7 +1098,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.matchBrackets': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.matchBrackets, + 'default': EditorOptions.matchBrackets.defaultValue, 'description': nls.localize('matchBrackets', "Highlight matching brackets when one of them is selected.") }, 'editor.glyphMargin': { @@ -1137,17 +1144,17 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.links': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.links, + 'default': EditorOptions.links.defaultValue, 'description': nls.localize('links', "Controls whether the editor should detect links and make them clickable.") }, 'editor.colorDecorators': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.colorDecorators, + 'default': EditorOptions.colorDecorators.defaultValue, 'description': nls.localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") }, 'editor.lightbulb.enabled': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.lightbulbEnabled, + 'default': EditorOptions.lightbulb.defaultValue.enabled, 'description': nls.localize('codeActions', "Enables the code action lightbulb in the editor.") }, 'editor.maxTokenizationLineLength': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index d3eeb2ec5c2..6d3ba78ade0 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -533,7 +533,7 @@ export interface IEditorOptions { quickSuggestions?: boolean | { other: boolean, comments: boolean, strings: boolean }; /** * Quick suggestions show delay (in ms) - * Defaults to 500 (ms) + * Defaults to 10 (ms) */ quickSuggestionsDelay?: number; /** @@ -588,7 +588,7 @@ export interface IEditorOptions { * Accept suggestions on ENTER. * Defaults to 'on'. */ - acceptSuggestionOnEnter?: boolean | 'on' | 'smart' | 'off'; + acceptSuggestionOnEnter?: 'on' | 'smart' | 'off'; /** * Accept suggestions on provider defined characters. * Defaults to true. @@ -947,32 +947,17 @@ export interface InternalParameterHintOptions { export interface EditorContribOptions { readonly hover: InternalEditorHoverOptions; - readonly links: boolean; - readonly contextmenu: boolean; readonly quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; - readonly quickSuggestionsDelay: number; readonly parameterHints: InternalParameterHintOptions; - readonly formatOnType: boolean; - readonly formatOnPaste: boolean; - readonly suggestOnTriggerCharacters: boolean; - readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; - readonly acceptSuggestionOnCommitCharacter: boolean; - readonly wordBasedSuggestions: boolean; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestFontSize: number; readonly suggestLineHeight: number; readonly tabCompletion: 'on' | 'off' | 'onlySnippets'; readonly suggest: InternalSuggestOptions; readonly gotoLocation: InternalGoToLocationOptions; - readonly selectionHighlight: boolean; - readonly occurrencesHighlight: boolean; - readonly codeLens: boolean; readonly foldingStrategy: 'auto' | 'indentation'; readonly showFoldingControls: 'always' | 'mouseover'; - readonly matchBrackets: boolean; readonly find: InternalEditorFindOptions; - readonly colorDecorators: boolean; - readonly lightbulbEnabled: boolean; readonly codeActionsOnSave: ICodeActionsOnSaveOptions; readonly codeActionsOnSaveTimeout: number; } @@ -1113,34 +1098,19 @@ export class InternalEditorOptions { private static _equalsContribOptions(a: EditorContribOptions, b: EditorContribOptions): boolean { return ( this._equalsHoverOptions(a.hover, b.hover) - && a.links === b.links - && a.contextmenu === b.contextmenu && InternalEditorOptions._equalsQuickSuggestions(a.quickSuggestions, b.quickSuggestions) - && a.quickSuggestionsDelay === b.quickSuggestionsDelay && this._equalsParameterHintOptions(a.parameterHints, b.parameterHints) - && a.formatOnType === b.formatOnType - && a.formatOnPaste === b.formatOnPaste - && a.suggestOnTriggerCharacters === b.suggestOnTriggerCharacters - && a.acceptSuggestionOnEnter === b.acceptSuggestionOnEnter - && a.acceptSuggestionOnCommitCharacter === b.acceptSuggestionOnCommitCharacter - && a.wordBasedSuggestions === b.wordBasedSuggestions && a.suggestSelection === b.suggestSelection && a.suggestFontSize === b.suggestFontSize && a.suggestLineHeight === b.suggestLineHeight && a.tabCompletion === b.tabCompletion && this._equalsSuggestOptions(a.suggest, b.suggest) && InternalEditorOptions._equalsGotoLocationOptions(a.gotoLocation, b.gotoLocation) - && a.selectionHighlight === b.selectionHighlight - && a.occurrencesHighlight === b.occurrencesHighlight - && a.codeLens === b.codeLens && a.foldingStrategy === b.foldingStrategy && a.showFoldingControls === b.showFoldingControls - && a.matchBrackets === b.matchBrackets && this._equalFindOptions(a.find, b.find) - && a.colorDecorators === b.colorDecorators && objects.equals(a.codeActionsOnSave, b.codeActionsOnSave) && a.codeActionsOnSaveTimeout === b.codeActionsOnSaveTimeout - && a.lightbulbEnabled === b.lightbulbEnabled ); } @@ -1387,39 +1357,20 @@ export class EditorOptionsValidator { } else { quickSuggestions = _boolean(opts.quickSuggestions, defaults.quickSuggestions); } - // Compatibility support for acceptSuggestionOnEnter - if (typeof opts.acceptSuggestionOnEnter === 'boolean') { - opts.acceptSuggestionOnEnter = opts.acceptSuggestionOnEnter ? 'on' : 'off'; - } const find = this._sanitizeFindOpts(opts.find, defaults.find); return { hover: this._sanitizeHoverOpts(opts.hover, defaults.hover), - links: _boolean(opts.links, defaults.links), - contextmenu: _boolean(opts.contextmenu, defaults.contextmenu), quickSuggestions: quickSuggestions, - quickSuggestionsDelay: _clampedInt(opts.quickSuggestionsDelay, defaults.quickSuggestionsDelay, Constants.MIN_SAFE_SMALL_INTEGER, Constants.MAX_SAFE_SMALL_INTEGER), parameterHints: this._sanitizeParameterHintOpts(opts.parameterHints, defaults.parameterHints), - formatOnType: _boolean(opts.formatOnType, defaults.formatOnType), - formatOnPaste: _boolean(opts.formatOnPaste, defaults.formatOnPaste), - suggestOnTriggerCharacters: _boolean(opts.suggestOnTriggerCharacters, defaults.suggestOnTriggerCharacters), - acceptSuggestionOnEnter: _stringSet<'on' | 'smart' | 'off'>(opts.acceptSuggestionOnEnter, defaults.acceptSuggestionOnEnter, ['on', 'smart', 'off']), - acceptSuggestionOnCommitCharacter: _boolean(opts.acceptSuggestionOnCommitCharacter, defaults.acceptSuggestionOnCommitCharacter), - wordBasedSuggestions: _boolean(opts.wordBasedSuggestions, defaults.wordBasedSuggestions), suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 0, 1000), tabCompletion: this._sanitizeTabCompletionOpts(opts.tabCompletion, defaults.tabCompletion), suggest: this._sanitizeSuggestOpts(opts, defaults.suggest), gotoLocation: this._sanitizeGotoLocationOpts(opts, defaults.gotoLocation), - selectionHighlight: _boolean(opts.selectionHighlight, defaults.selectionHighlight), - occurrencesHighlight: _boolean(opts.occurrencesHighlight, defaults.occurrencesHighlight), - codeLens: _boolean(opts.codeLens, defaults.codeLens), foldingStrategy: _stringSet<'auto' | 'indentation'>(opts.foldingStrategy, defaults.foldingStrategy, ['auto', 'indentation']), showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']), - matchBrackets: _boolean(opts.matchBrackets, defaults.matchBrackets), find: find, - colorDecorators: _boolean(opts.colorDecorators, defaults.colorDecorators), - lightbulbEnabled: _boolean(opts.lightbulb ? opts.lightbulb.enabled : false, defaults.lightbulbEnabled), codeActionsOnSave: _booleanMap(opts.codeActionsOnSave, {}), codeActionsOnSaveTimeout: _clampedInt(opts.codeActionsOnSaveTimeout, defaults.codeActionsOnSaveTimeout, 1, 10000) }; @@ -1513,20 +1464,15 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { delay: 300, sticky: true }, - links: true, - contextmenu: true, - quickSuggestions: { other: true, comments: false, strings: false }, - quickSuggestionsDelay: 10, + quickSuggestions: { + other: true, + comments: false, + strings: false + }, parameterHints: { enabled: true, cycle: false }, - formatOnType: false, - formatOnPaste: false, - suggestOnTriggerCharacters: true, - acceptSuggestionOnEnter: 'on', - acceptSuggestionOnCommitCharacter: true, - wordBasedSuggestions: true, suggestSelection: 'recentlyUsed', suggestFontSize: 0, suggestLineHeight: 0, @@ -1544,20 +1490,14 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { gotoLocation: { multiple: 'peek' }, - selectionHighlight: true, - occurrencesHighlight: true, - codeLens: true, foldingStrategy: 'auto', showFoldingControls: 'mouseover', - matchBrackets: true, find: { seedSearchStringFromSelection: true, autoFindInSelection: false, globalFindClipboard: false, addExtraSpaceOnTop: true }, - colorDecorators: true, - lightbulbEnabled: true, codeActionsOnSave: {}, codeActionsOnSaveTimeout: 750 }, @@ -1829,7 +1769,7 @@ export interface InternalEditorMinimapOptions { readonly maxColumn: number; } -class EditorMinimapOption> extends BaseEditorOption { +class EditorMinimap> extends BaseEditorOption { public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -1974,7 +1914,7 @@ class EditorTabFocusMode> extends EditorBooleanOption { public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { @@ -1984,6 +1924,31 @@ class EditorEmptySelectionClipboard; + +class EditorLightbulb> extends BaseEditorOption { + public validate(input: IEditorLightbulbOptions | undefined): ValidEditorLightbulbOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: ValidEditorLightbulbOptions): ValidEditorLightbulbOptions { + return value; + } + public equals(a: ValidEditorLightbulbOptions, b: ValidEditorLightbulbOptions): boolean { + return ( + a.enabled === b.enabled + ); + } +} + +//#endregion + //#region scrollbar export interface InternalEditorScrollbarOptions { @@ -2000,7 +1965,7 @@ export interface InternalEditorScrollbarOptions { readonly verticalSliderSize: number; } -class EditorScrollbarOption> extends BaseEditorOption { +class EditorScrollbar> extends BaseEditorOption { public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { if (typeof input !== 'object') { return this.defaultValue; @@ -2482,6 +2447,8 @@ function _multiCursorModifierFromString(multiCursorModifier: 'ctrlCmd' | 'alt'): } export const enum EditorOption { + acceptSuggestionOnCommitCharacter, + acceptSuggestionOnEnter, accessibilitySupport, autoClosingBrackets, autoClosingOvertype, @@ -2489,6 +2456,9 @@ export const enum EditorOption { autoIndent, automaticLayout, autoSurround, + codeLens, + colorDecorators, + contextmenu, copyWithSyntaxHighlighting, cursorBlinking, cursorSmoothCaretAnimation, @@ -2503,21 +2473,28 @@ export const enum EditorOption { fixedOverflowWidgets, folding, fontLigatures, + formatOnPaste, + formatOnType, glyphMargin, hideCursorInOverviewRuler, highlightActiveIndentGuide, inDiffEditor, + lightbulb, lineDecorationsWidth, lineNumbers, lineNumbersMinChars, + links, + matchBrackets, minimap, mouseStyle, mouseWheelScrollSensitivity, mouseWheelZoom, multiCursorMergeOverlapping, multiCursorModifier, + occurrencesHighlight, overviewRulerBorder, overviewRulerLanes, + quickSuggestionsDelay, readOnly, renderControlCharacters, renderIndentGuides, @@ -2531,11 +2508,14 @@ export const enum EditorOption { scrollBeyondLastColumn, scrollBeyondLastLine, selectionClipboard, + selectionHighlight, selectOnLineNumbers, showUnused, smoothScrolling, stopRenderingLineAfter, + suggestOnTriggerCharacters, useTabStops, + wordBasedSuggestions, wordSeparators, wordWrap, wordWrapBreakAfterCharacters, @@ -2554,6 +2534,8 @@ export const enum EditorOption { } export const EditorOptions = { + acceptSuggestionOnCommitCharacter: registerEditorOption(new EditorBooleanOption(EditorOption.acceptSuggestionOnCommitCharacter, 'acceptSuggestionOnCommitCharacter', true)), + acceptSuggestionOnEnter: registerEditorOption(new EditorEnumOption(EditorOption.acceptSuggestionOnEnter, 'acceptSuggestionOnEnter', 'on', ['on', 'smart', 'off'], x => x)), accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOption.accessibilitySupport, 'accessibilitySupport', 'auto')), autoClosingBrackets: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingBrackets, 'autoClosingBrackets', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], x => x)), autoClosingOvertype: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingOvertype, 'autoClosingOvertype', 'auto', ['always', 'auto', 'never'], x => x)), @@ -2561,6 +2543,9 @@ export const EditorOptions = { autoIndent: registerEditorOption(new EditorBooleanOption(EditorOption.autoIndent, 'autoIndent', true)), automaticLayout: registerEditorOption(new EditorBooleanOption(EditorOption.automaticLayout, 'automaticLayout', false)), autoSurround: registerEditorOption(new EditorEnumOption(EditorOption.autoSurround, 'autoSurround', 'languageDefined', ['languageDefined', 'quotes', 'brackets', 'never'], x => x)), + codeLens: registerEditorOption(new EditorBooleanOption(EditorOption.codeLens, 'codeLens', true)), + colorDecorators: registerEditorOption(new EditorBooleanOption(EditorOption.colorDecorators, 'colorDecorators', true)), + contextmenu: registerEditorOption(new EditorBooleanOption(EditorOption.contextmenu, 'contextmenu', true)), copyWithSyntaxHighlighting: registerEditorOption(new EditorBooleanOption(EditorOption.copyWithSyntaxHighlighting, 'copyWithSyntaxHighlighting', true)), cursorBlinking: registerEditorOption(new EditorEnumOption(EditorOption.cursorBlinking, 'cursorBlinking', 'blink', ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString)), cursorSmoothCaretAnimation: registerEditorOption(new EditorBooleanOption(EditorOption.cursorSmoothCaretAnimation, 'cursorSmoothCaretAnimation', false)), @@ -2575,14 +2560,21 @@ export const EditorOptions = { fixedOverflowWidgets: registerEditorOption(new EditorBooleanOption(EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false)), folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), + formatOnPaste: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnPaste, 'formatOnPaste', false)), + formatOnType: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnType, 'formatOnType', false)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), hideCursorInOverviewRuler: registerEditorOption(new EditorBooleanOption(EditorOption.hideCursorInOverviewRuler, 'hideCursorInOverviewRuler', false)), highlightActiveIndentGuide: registerEditorOption(new EditorBooleanOption(EditorOption.highlightActiveIndentGuide, 'highlightActiveIndentGuide', true)), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), + lightbulb: registerEditorOption(new EditorLightbulb(EditorOption.lightbulb, 'lightbulb', { + enabled: true + })), lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), lineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), - minimap: registerEditorOption(new EditorMinimapOption(EditorOption.minimap, 'minimap', { + links: registerEditorOption(new EditorBooleanOption(EditorOption.links, 'links', true)), + matchBrackets: registerEditorOption(new EditorBooleanOption(EditorOption.matchBrackets, 'matchBrackets', true)), + minimap: registerEditorOption(new EditorMinimap(EditorOption.minimap, 'minimap', { enabled: true, side: 'right', showSlider: 'mouseover', @@ -2594,8 +2586,10 @@ export const EditorOptions = { mouseWheelZoom: registerEditorOption(new EditorBooleanOption(EditorOption.mouseWheelZoom, 'mouseWheelZoom', false)), multiCursorMergeOverlapping: registerEditorOption(new EditorBooleanOption(EditorOption.multiCursorMergeOverlapping, 'multiCursorMergeOverlapping', true)), multiCursorModifier: registerEditorOption(new EditorEnumOption(EditorOption.multiCursorModifier, 'multiCursorModifier', 'alt', ['ctrlCmd', 'alt'], _multiCursorModifierFromString)), + occurrencesHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.occurrencesHighlight, 'occurrencesHighlight', true)), overviewRulerBorder: registerEditorOption(new EditorBooleanOption(EditorOption.overviewRulerBorder, 'overviewRulerBorder', true)), overviewRulerLanes: registerEditorOption(new EditorIntOption(EditorOption.overviewRulerLanes, 'overviewRulerLanes', 2, 0, 3)), + quickSuggestionsDelay: registerEditorOption(new EditorIntOption(EditorOption.quickSuggestionsDelay, 'quickSuggestionsDelay', 10, 0, Constants.MAX_SAFE_SMALL_INTEGER)), readOnly: registerEditorOption(new EditorBooleanOption(EditorOption.readOnly, 'readOnly', false)), renderControlCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.renderControlCharacters, 'renderControlCharacters', false)), renderIndentGuides: registerEditorOption(new EditorBooleanOption(EditorOption.renderIndentGuides, 'renderIndentGuides', true)), @@ -2605,7 +2599,7 @@ export const EditorOptions = { revealHorizontalRightPadding: registerEditorOption(new EditorIntOption(EditorOption.revealHorizontalRightPadding, 'revealHorizontalRightPadding', 30, 0, 1000)), roundedSelection: registerEditorOption(new EditorBooleanOption(EditorOption.roundedSelection, 'roundedSelection', true)), rulers: registerEditorOption(new EditorRulers(EditorOption.rulers, 'rulers', [])), - scrollbar: registerEditorOption(new EditorScrollbarOption(EditorOption.scrollbar, 'scrollbar', { + scrollbar: registerEditorOption(new EditorScrollbar(EditorOption.scrollbar, 'scrollbar', { vertical: ScrollbarVisibility.Auto, horizontal: ScrollbarVisibility.Auto, arrowSize: 11, @@ -2621,11 +2615,14 @@ export const EditorOptions = { scrollBeyondLastColumn: registerEditorOption(new EditorIntOption(EditorOption.scrollBeyondLastColumn, 'scrollBeyondLastColumn', 5, 0, Constants.MAX_SAFE_SMALL_INTEGER)), scrollBeyondLastLine: registerEditorOption(new EditorBooleanOption(EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true)), selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), + selectionHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.selectionHighlight, 'selectionHighlight', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), showUnused: registerEditorOption(new EditorBooleanOption(EditorOption.showUnused, 'showUnused', true)), smoothScrolling: registerEditorOption(new EditorBooleanOption(EditorOption.smoothScrolling, 'smoothScrolling', false)), stopRenderingLineAfter: registerEditorOption(new EditorIntOption(EditorOption.stopRenderingLineAfter, 'stopRenderingLineAfter', 10000, -1, Constants.MAX_SAFE_SMALL_INTEGER)), + suggestOnTriggerCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.suggestOnTriggerCharacters, 'suggestOnTriggerCharacters', true)), useTabStops: registerEditorOption(new EditorBooleanOption(EditorOption.useTabStops, 'useTabStops', true)), + wordBasedSuggestions: registerEditorOption(new EditorBooleanOption(EditorOption.wordBasedSuggestions, 'wordBasedSuggestions', true)), wordSeparators: registerEditorOption(new EditorStringOption(EditorOption.wordSeparators, 'wordSeparators', USUAL_WORD_SEPARATORS)), wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], x => x)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 27c45cf7c94..8393a6c1ec6 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -440,74 +440,89 @@ export enum RenderLineNumbersType { } export enum EditorOption { - accessibilitySupport = 0, - autoClosingBrackets = 1, - autoClosingOvertype = 2, - autoClosingQuotes = 3, - autoIndent = 4, - automaticLayout = 5, - autoSurround = 6, - copyWithSyntaxHighlighting = 7, - cursorBlinking = 8, - cursorSmoothCaretAnimation = 9, - cursorStyle = 10, - cursorSurroundingLines = 11, - cursorWidth = 12, - disableLayerHinting = 13, - dragAndDrop = 14, - emptySelectionClipboard = 15, - extraEditorClassName = 16, - fastScrollSensitivity = 17, - fixedOverflowWidgets = 18, - folding = 19, - fontLigatures = 20, - glyphMargin = 21, - hideCursorInOverviewRuler = 22, - highlightActiveIndentGuide = 23, - inDiffEditor = 24, - lineDecorationsWidth = 25, - lineNumbers = 26, - lineNumbersMinChars = 27, - minimap = 28, - mouseStyle = 29, - mouseWheelScrollSensitivity = 30, - mouseWheelZoom = 31, - multiCursorMergeOverlapping = 32, - multiCursorModifier = 33, - overviewRulerBorder = 34, - overviewRulerLanes = 35, - readOnly = 36, - renderControlCharacters = 37, - renderIndentGuides = 38, - renderFinalNewline = 39, - renderLineHighlight = 40, - renderWhitespace = 41, - revealHorizontalRightPadding = 42, - roundedSelection = 43, - rulers = 44, - scrollbar = 45, - scrollBeyondLastColumn = 46, - scrollBeyondLastLine = 47, - selectionClipboard = 48, - selectOnLineNumbers = 49, - showUnused = 50, - smoothScrolling = 51, - stopRenderingLineAfter = 52, - useTabStops = 53, - wordSeparators = 54, - wordWrap = 55, - wordWrapBreakAfterCharacters = 56, - wordWrapBreakBeforeCharacters = 57, - wordWrapBreakObtrusiveCharacters = 58, - wordWrapColumn = 59, - wordWrapMinified = 60, - wrappingIndent = 61, - ariaLabel = 62, - disableMonospaceOptimizations = 63, - editorClassName = 64, - tabFocusMode = 65, - layoutInfo = 66, - wrappingInfo = 67 + acceptSuggestionOnCommitCharacter = 0, + acceptSuggestionOnEnter = 1, + accessibilitySupport = 2, + autoClosingBrackets = 3, + autoClosingOvertype = 4, + autoClosingQuotes = 5, + autoIndent = 6, + automaticLayout = 7, + autoSurround = 8, + codeLens = 9, + colorDecorators = 10, + contextmenu = 11, + copyWithSyntaxHighlighting = 12, + cursorBlinking = 13, + cursorSmoothCaretAnimation = 14, + cursorStyle = 15, + cursorSurroundingLines = 16, + cursorWidth = 17, + disableLayerHinting = 18, + dragAndDrop = 19, + emptySelectionClipboard = 20, + extraEditorClassName = 21, + fastScrollSensitivity = 22, + fixedOverflowWidgets = 23, + folding = 24, + fontLigatures = 25, + formatOnPaste = 26, + formatOnType = 27, + glyphMargin = 28, + hideCursorInOverviewRuler = 29, + highlightActiveIndentGuide = 30, + inDiffEditor = 31, + lightbulb = 32, + lineDecorationsWidth = 33, + lineNumbers = 34, + lineNumbersMinChars = 35, + links = 36, + matchBrackets = 37, + minimap = 38, + mouseStyle = 39, + mouseWheelScrollSensitivity = 40, + mouseWheelZoom = 41, + multiCursorMergeOverlapping = 42, + multiCursorModifier = 43, + occurrencesHighlight = 44, + overviewRulerBorder = 45, + overviewRulerLanes = 46, + quickSuggestionsDelay = 47, + readOnly = 48, + renderControlCharacters = 49, + renderIndentGuides = 50, + renderFinalNewline = 51, + renderLineHighlight = 52, + renderWhitespace = 53, + revealHorizontalRightPadding = 54, + roundedSelection = 55, + rulers = 56, + scrollbar = 57, + scrollBeyondLastColumn = 58, + scrollBeyondLastLine = 59, + selectionClipboard = 60, + selectionHighlight = 61, + selectOnLineNumbers = 62, + showUnused = 63, + smoothScrolling = 64, + stopRenderingLineAfter = 65, + suggestOnTriggerCharacters = 66, + useTabStops = 67, + wordBasedSuggestions = 68, + wordSeparators = 69, + wordWrap = 70, + wordWrapBreakAfterCharacters = 71, + wordWrapBreakBeforeCharacters = 72, + wordWrapBreakObtrusiveCharacters = 73, + wordWrapColumn = 74, + wordWrapMinified = 75, + wrappingIndent = 76, + ariaLabel = 77, + disableMonospaceOptimizations = 78, + editorClassName = 79, + tabFocusMode = 80, + layoutInfo = 81, + wrappingInfo = 82 } /** diff --git a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts index 675fa71bd8c..44d7bb7613a 100644 --- a/src/vs/editor/contrib/bracketMatching/bracketMatching.ts +++ b/src/vs/editor/contrib/bracketMatching/bracketMatching.ts @@ -22,6 +22,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { registerColor } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant, themeColorFromId } from 'vs/platform/theme/common/themeService'; import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const overviewRulerBracketMatchForeground = registerColor('editorOverviewRuler.bracketMatchForeground', { dark: '#A0A0A0', light: '#A0A0A0', hc: '#A0A0A0' }, nls.localize('overviewRulerBracketMatchForeground', 'Overview ruler marker color for matching brackets.')); @@ -104,7 +105,7 @@ export class BracketMatchingController extends Disposable implements editorCommo this._lastVersionId = 0; this._decorations = []; this._updateBracketsSoon = this._register(new RunOnceScheduler(() => this._updateBrackets(), 50)); - this._matchBrackets = this._editor.getConfiguration().contribInfo.matchBrackets; + this._matchBrackets = this._editor.getOption(EditorOption.matchBrackets); this._updateBracketsSoon.schedule(); this._register(editor.onDidChangeCursorPosition((e) => { @@ -130,7 +131,7 @@ export class BracketMatchingController extends Disposable implements editorCommo this._updateBracketsSoon.schedule(); })); this._register(editor.onDidChangeConfiguration((e) => { - this._matchBrackets = this._editor.getConfiguration().contribInfo.matchBrackets; + this._matchBrackets = this._editor.getOption(EditorOption.matchBrackets); if (!this._matchBrackets && this._decorations.length > 0) { // Remove existing decorations if bracket matching is off this._decorations = this._editor.deltaDecorations(this._decorations, []); @@ -332,4 +333,4 @@ MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, { title: nls.localize({ key: 'miGoToBracket', comment: ['&& denotes a mnemonic'] }, "Go to &&Bracket") }, order: 2 -}); \ No newline at end of file +}); diff --git a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts index 8575f354d5c..a43dabec6f0 100644 --- a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts +++ b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts @@ -14,6 +14,7 @@ import { TextModel } from 'vs/editor/common/model/textModel'; import { CodeActionSet } from 'vs/editor/contrib/codeAction/codeAction'; import * as nls from 'vs/nls'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; namespace LightBulbState { @@ -106,7 +107,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget { })); this._register(this._editor.onDidChangeConfiguration(e => { // hide when told to do so - if (e.contribInfo && !this._editor.getConfiguration().contribInfo.lightbulbEnabled) { + if (e.contribInfo && !this._editor.getOption(EditorOption.lightbulb).enabled) { this.hide(); } })); @@ -138,7 +139,8 @@ export class LightBulbWidget extends Disposable implements IContentWidget { } const config = this._editor.getConfiguration(); - if (!config.contribInfo.lightbulbEnabled) { + const options = this._editor.getOptions(); + if (!options.get(EditorOption.lightbulb).enabled) { return this.hide(); } diff --git a/src/vs/editor/contrib/codelens/codelensController.ts b/src/vs/editor/contrib/codelens/codelensController.ts index 726133c3f7f..72e341842a8 100644 --- a/src/vs/editor/contrib/codelens/codelensController.ts +++ b/src/vs/editor/contrib/codelens/codelensController.ts @@ -17,6 +17,7 @@ import { CodeLensWidget, CodeLensHelper } from 'vs/editor/contrib/codelens/codel import { ICommandService } from 'vs/platform/commands/common/commands'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { ICodeLensCache } from 'vs/editor/contrib/codelens/codeLensCache'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class CodeLensContribution implements editorCommon.IEditorContribution { @@ -40,13 +41,13 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { @INotificationService private readonly _notificationService: INotificationService, @ICodeLensCache private readonly _codeLensCache: ICodeLensCache ) { - this._isEnabled = this._editor.getConfiguration().contribInfo.codeLens; + this._isEnabled = this._editor.getOption(EditorOption.codeLens); this._globalToDispose.add(this._editor.onDidChangeModel(() => this._onModelChange())); this._globalToDispose.add(this._editor.onDidChangeModelLanguage(() => this._onModelChange())); this._globalToDispose.add(this._editor.onDidChangeConfiguration(() => { const prevIsEnabled = this._isEnabled; - this._isEnabled = this._editor.getConfiguration().contribInfo.codeLens; + this._isEnabled = this._editor.getOption(EditorOption.codeLens); if (prevIsEnabled !== this._isEnabled) { this._onModelChange(); } diff --git a/src/vs/editor/contrib/colorPicker/colorDetector.ts b/src/vs/editor/contrib/colorPicker/colorDetector.ts index 0ccf498c009..c1460b7650d 100644 --- a/src/vs/editor/contrib/colorPicker/colorDetector.ts +++ b/src/vs/editor/contrib/colorPicker/colorDetector.ts @@ -19,6 +19,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel'; import { ColorProviderRegistry } from 'vs/editor/common/modes'; import { IColorData, getColors } from 'vs/editor/contrib/colorPicker/color'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const MAX_DECORATORS = 500; @@ -84,7 +85,7 @@ export class ColorDetector extends Disposable implements IEditorContribution { } } - return this._editor.getConfiguration().contribInfo.colorDecorators; + return this._editor.getOption(EditorOption.colorDecorators); } getId(): string { diff --git a/src/vs/editor/contrib/contextmenu/contextmenu.ts b/src/vs/editor/contrib/contextmenu/contextmenu.ts index 2209b38da7f..65fbdef07bb 100644 --- a/src/vs/editor/contrib/contextmenu/contextmenu.ts +++ b/src/vs/editor/contrib/contextmenu/contextmenu.ts @@ -22,6 +22,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { ITextModel } from 'vs/editor/common/model'; import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class ContextMenuController implements IEditorContribution { @@ -66,7 +67,7 @@ export class ContextMenuController implements IEditorContribution { return; } - if (!this._editor.getConfiguration().contribInfo.contextmenu) { + if (!this._editor.getOption(EditorOption.contextmenu)) { this._editor.focus(); // Ensure the cursor is at the position of the mouse click if (e.target.position && !this._editor.getSelection().containsPosition(e.target.position)) { @@ -104,7 +105,7 @@ export class ContextMenuController implements IEditorContribution { } public showContextMenu(anchor?: IAnchor | null): void { - if (!this._editor.getConfiguration().contribInfo.contextmenu) { + if (!this._editor.getOption(EditorOption.contextmenu)) { return; // Context menu is turned off through configuration } if (!this._editor.hasModel()) { diff --git a/src/vs/editor/contrib/format/formatActions.ts b/src/vs/editor/contrib/format/formatActions.ts index 8b2798a496d..1af6506e0d8 100644 --- a/src/vs/editor/contrib/format/formatActions.ts +++ b/src/vs/editor/contrib/format/formatActions.ts @@ -24,6 +24,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { onUnexpectedError } from 'vs/base/common/errors'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class FormatOnType implements editorCommon.IEditorContribution { @@ -59,7 +60,7 @@ class FormatOnType implements editorCommon.IEditorContribution { this._callOnModel.clear(); // we are disabled - if (!this._editor.getConfiguration().contribInfo.formatOnType) { + if (!this._editor.getOption(EditorOption.formatOnType)) { return; } @@ -184,7 +185,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution { this._callOnModel.clear(); // we are disabled - if (!this.editor.getConfiguration().contribInfo.formatOnPaste) { + if (!this.editor.getOption(EditorOption.formatOnPaste)) { return; } diff --git a/src/vs/editor/contrib/indentation/indentation.ts b/src/vs/editor/contrib/indentation/indentation.ts index cc2c6904bfa..bbd4f5e563d 100644 --- a/src/vs/editor/contrib/indentation/indentation.ts +++ b/src/vs/editor/contrib/indentation/indentation.ts @@ -444,7 +444,7 @@ export class AutoIndentOnPaste implements IEditorContribution { this.callOnModel = dispose(this.callOnModel); // we are disabled - if (!this.editor.getOption(EditorOption.autoIndent) || this.editor.getConfiguration().contribInfo.formatOnPaste) { + if (!this.editor.getOption(EditorOption.autoIndent) || this.editor.getOption(EditorOption.formatOnPaste)) { return; } diff --git a/src/vs/editor/contrib/links/links.ts b/src/vs/editor/contrib/links/links.ts index 237ced230c0..1eee5898a96 100644 --- a/src/vs/editor/contrib/links/links.ts +++ b/src/vs/editor/contrib/links/links.ts @@ -140,9 +140,9 @@ class LinkDetector implements editorCommon.IEditorContribution { this.cleanUpActiveLinkDecoration(); })); - this.enabled = editor.getConfiguration().contribInfo.links; + this.enabled = editor.getOption(EditorOption.links); this.listenersToRemove.add(editor.onDidChangeConfiguration((e) => { - let enabled = editor.getConfiguration().contribInfo.links; + const enabled = editor.getOption(EditorOption.links); if (this.enabled === enabled) { // No change in our configuration option return; diff --git a/src/vs/editor/contrib/multicursor/multicursor.ts b/src/vs/editor/contrib/multicursor/multicursor.ts index 4da9f349005..028ddab538c 100644 --- a/src/vs/editor/contrib/multicursor/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/multicursor.ts @@ -809,13 +809,13 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut constructor(editor: ICodeEditor) { super(); this.editor = editor; - this._isEnabled = editor.getConfiguration().contribInfo.selectionHighlight; + this._isEnabled = editor.getOption(EditorOption.selectionHighlight); this.decorations = []; this.updateSoon = this._register(new RunOnceScheduler(() => this._update(), 300)); this.state = null; this._register(editor.onDidChangeConfiguration((e) => { - this._isEnabled = editor.getConfiguration().contribInfo.selectionHighlight; + this._isEnabled = editor.getOption(EditorOption.selectionHighlight); })); this._register(editor.onDidChangeCursorSelection((e: ICursorSelectionChangedEvent) => { diff --git a/src/vs/editor/contrib/suggest/suggestCommitCharacters.ts b/src/vs/editor/contrib/suggest/suggestCommitCharacters.ts index 20a7656532a..3831500a4f8 100644 --- a/src/vs/editor/contrib/suggest/suggestCommitCharacters.ts +++ b/src/vs/editor/contrib/suggest/suggestCommitCharacters.ts @@ -8,6 +8,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ISelectedSuggestion, SuggestWidget } from './suggestWidget'; import { CharacterSet } from 'vs/editor/common/core/characterClassifier'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class CommitCharacterController { @@ -27,7 +28,7 @@ export class CommitCharacterController { this._disposables.add(editor.onWillType(text => { if (this._active) { const ch = text.charCodeAt(text.length - 1); - if (this._active.acceptCharacters.has(ch) && editor.getConfiguration().contribInfo.acceptSuggestionOnCommitCharacter) { + if (this._active.acceptCharacters.has(ch) && editor.getOption(EditorOption.acceptSuggestionOnCommitCharacter)) { accept(this._active.item); } } diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index a86c5148d2c..e8bc0699c82 100644 --- a/src/vs/editor/contrib/suggest/suggestController.ts +++ b/src/vs/editor/contrib/suggest/suggestController.ts @@ -35,6 +35,7 @@ import { isObject } from 'vs/base/common/types'; import { CommitCharacterController } from './suggestCommitCharacters'; import { IPosition } from 'vs/editor/common/core/position'; import { TrackedRangeStickiness, ITextModel } from 'vs/editor/common/model'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const _sticky = false; // for development purposes only @@ -129,7 +130,7 @@ export class SuggestController implements IEditorContribution { const endColumn = position.column; let value = true; if ( - this._editor.getConfiguration().contribInfo.acceptSuggestionOnEnter === 'smart' + this._editor.getOption(EditorOption.acceptSuggestionOnEnter) === 'smart' && this._model.state === State.Auto && !item.completion.command && !item.completion.additionalTextEdits @@ -182,7 +183,7 @@ export class SuggestController implements IEditorContribution { // Manage the acceptSuggestionsOnEnter context key let acceptSuggestionsOnEnter = SuggestContext.AcceptSuggestionsOnEnter.bindTo(_contextKeyService); let updateFromConfig = () => { - const { acceptSuggestionOnEnter } = this._editor.getConfiguration().contribInfo; + const acceptSuggestionOnEnter = this._editor.getOption(EditorOption.acceptSuggestionOnEnter); acceptSuggestionsOnEnter.set(acceptSuggestionOnEnter === 'on' || acceptSuggestionOnEnter === 'smart'); }; this._toDispose.add(this._editor.onDidChangeConfiguration(() => updateFromConfig())); diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index 174f87f6a0c..0d0bbe19f4d 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -173,7 +173,7 @@ export class SuggestModel implements IDisposable { // --- handle configuration & precondition changes private _updateQuickSuggest(): void { - this._quickSuggestDelay = this._editor.getConfiguration().contribInfo.quickSuggestionsDelay; + this._quickSuggestDelay = this._editor.getOption(EditorOption.quickSuggestionsDelay); if (isNaN(this._quickSuggestDelay) || (!this._quickSuggestDelay && this._quickSuggestDelay !== 0) || this._quickSuggestDelay < 0) { this._quickSuggestDelay = 10; @@ -186,7 +186,7 @@ export class SuggestModel implements IDisposable { if (this._editor.getOption(EditorOption.readOnly) || !this._editor.hasModel() - || !this._editor.getConfiguration().contribInfo.suggestOnTriggerCharacters) { + || !this._editor.getOption(EditorOption.suggestOnTriggerCharacters)) { return; } diff --git a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts index 4e05c3ff8a9..11cbf87647c 100644 --- a/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts +++ b/src/vs/editor/contrib/wordHighlighter/wordHighlighter.ts @@ -182,7 +182,7 @@ class WordHighlighter { this.editor = editor; this._hasWordHighlights = ctxHasWordHighlights.bindTo(contextKeyService); this._ignorePositionChangeEvent = false; - this.occurrencesHighlight = this.editor.getConfiguration().contribInfo.occurrencesHighlight; + this.occurrencesHighlight = this.editor.getOption(EditorOption.occurrencesHighlight); this.model = this.editor.getModel(); this.toUnhook.add(editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => { @@ -203,7 +203,7 @@ class WordHighlighter { this._stopAll(); })); this.toUnhook.add(editor.onDidChangeConfiguration((e) => { - let newValue = this.editor.getConfiguration().contribInfo.occurrencesHighlight; + let newValue = this.editor.getOption(EditorOption.occurrencesHighlight); if (this.occurrencesHighlight !== newValue) { this.occurrencesHighlight = newValue; this._stopAll(); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index c74ca442fdd..2307b5caedb 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2919,7 +2919,7 @@ declare namespace monaco.editor { }; /** * Quick suggestions show delay (in ms) - * Defaults to 500 (ms) + * Defaults to 10 (ms) */ quickSuggestionsDelay?: number; /** @@ -2974,7 +2974,7 @@ declare namespace monaco.editor { * Accept suggestions on ENTER. * Defaults to 'on'. */ - acceptSuggestionOnEnter?: boolean | 'on' | 'smart' | 'off'; + acceptSuggestionOnEnter?: 'on' | 'smart' | 'off'; /** * Accept suggestions on provider defined characters. * Defaults to true. @@ -3271,36 +3271,21 @@ declare namespace monaco.editor { export interface EditorContribOptions { readonly hover: InternalEditorHoverOptions; - readonly links: boolean; - readonly contextmenu: boolean; readonly quickSuggestions: boolean | { other: boolean; comments: boolean; strings: boolean; }; - readonly quickSuggestionsDelay: number; readonly parameterHints: InternalParameterHintOptions; - readonly formatOnType: boolean; - readonly formatOnPaste: boolean; - readonly suggestOnTriggerCharacters: boolean; - readonly acceptSuggestionOnEnter: 'on' | 'smart' | 'off'; - readonly acceptSuggestionOnCommitCharacter: boolean; - readonly wordBasedSuggestions: boolean; readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; readonly suggestFontSize: number; readonly suggestLineHeight: number; readonly tabCompletion: 'on' | 'off' | 'onlySnippets'; readonly suggest: InternalSuggestOptions; readonly gotoLocation: InternalGoToLocationOptions; - readonly selectionHighlight: boolean; - readonly occurrencesHighlight: boolean; - readonly codeLens: boolean; readonly foldingStrategy: 'auto' | 'indentation'; readonly showFoldingControls: 'always' | 'mouseover'; - readonly matchBrackets: boolean; readonly find: InternalEditorFindOptions; - readonly colorDecorators: boolean; - readonly lightbulbEnabled: boolean; readonly codeActionsOnSave: ICodeActionsOnSaveOptions; readonly codeActionsOnSaveTimeout: number; } @@ -3400,6 +3385,8 @@ declare namespace monaco.editor { readonly maxColumn: number; } + export type ValidEditorLightbulbOptions = Required; + export interface InternalEditorScrollbarOptions { readonly arrowSize: number; readonly vertical: ScrollbarVisibility; @@ -3534,77 +3521,94 @@ declare namespace monaco.editor { } export enum EditorOption { - accessibilitySupport = 0, - autoClosingBrackets = 1, - autoClosingOvertype = 2, - autoClosingQuotes = 3, - autoIndent = 4, - automaticLayout = 5, - autoSurround = 6, - copyWithSyntaxHighlighting = 7, - cursorBlinking = 8, - cursorSmoothCaretAnimation = 9, - cursorStyle = 10, - cursorSurroundingLines = 11, - cursorWidth = 12, - disableLayerHinting = 13, - dragAndDrop = 14, - emptySelectionClipboard = 15, - extraEditorClassName = 16, - fastScrollSensitivity = 17, - fixedOverflowWidgets = 18, - folding = 19, - fontLigatures = 20, - glyphMargin = 21, - hideCursorInOverviewRuler = 22, - highlightActiveIndentGuide = 23, - inDiffEditor = 24, - lineDecorationsWidth = 25, - lineNumbers = 26, - lineNumbersMinChars = 27, - minimap = 28, - mouseStyle = 29, - mouseWheelScrollSensitivity = 30, - mouseWheelZoom = 31, - multiCursorMergeOverlapping = 32, - multiCursorModifier = 33, - overviewRulerBorder = 34, - overviewRulerLanes = 35, - readOnly = 36, - renderControlCharacters = 37, - renderIndentGuides = 38, - renderFinalNewline = 39, - renderLineHighlight = 40, - renderWhitespace = 41, - revealHorizontalRightPadding = 42, - roundedSelection = 43, - rulers = 44, - scrollbar = 45, - scrollBeyondLastColumn = 46, - scrollBeyondLastLine = 47, - selectionClipboard = 48, - selectOnLineNumbers = 49, - showUnused = 50, - smoothScrolling = 51, - stopRenderingLineAfter = 52, - useTabStops = 53, - wordSeparators = 54, - wordWrap = 55, - wordWrapBreakAfterCharacters = 56, - wordWrapBreakBeforeCharacters = 57, - wordWrapBreakObtrusiveCharacters = 58, - wordWrapColumn = 59, - wordWrapMinified = 60, - wrappingIndent = 61, - ariaLabel = 62, - disableMonospaceOptimizations = 63, - editorClassName = 64, - tabFocusMode = 65, - layoutInfo = 66, - wrappingInfo = 67 + acceptSuggestionOnCommitCharacter = 0, + acceptSuggestionOnEnter = 1, + accessibilitySupport = 2, + autoClosingBrackets = 3, + autoClosingOvertype = 4, + autoClosingQuotes = 5, + autoIndent = 6, + automaticLayout = 7, + autoSurround = 8, + codeLens = 9, + colorDecorators = 10, + contextmenu = 11, + copyWithSyntaxHighlighting = 12, + cursorBlinking = 13, + cursorSmoothCaretAnimation = 14, + cursorStyle = 15, + cursorSurroundingLines = 16, + cursorWidth = 17, + disableLayerHinting = 18, + dragAndDrop = 19, + emptySelectionClipboard = 20, + extraEditorClassName = 21, + fastScrollSensitivity = 22, + fixedOverflowWidgets = 23, + folding = 24, + fontLigatures = 25, + formatOnPaste = 26, + formatOnType = 27, + glyphMargin = 28, + hideCursorInOverviewRuler = 29, + highlightActiveIndentGuide = 30, + inDiffEditor = 31, + lightbulb = 32, + lineDecorationsWidth = 33, + lineNumbers = 34, + lineNumbersMinChars = 35, + links = 36, + matchBrackets = 37, + minimap = 38, + mouseStyle = 39, + mouseWheelScrollSensitivity = 40, + mouseWheelZoom = 41, + multiCursorMergeOverlapping = 42, + multiCursorModifier = 43, + occurrencesHighlight = 44, + overviewRulerBorder = 45, + overviewRulerLanes = 46, + quickSuggestionsDelay = 47, + readOnly = 48, + renderControlCharacters = 49, + renderIndentGuides = 50, + renderFinalNewline = 51, + renderLineHighlight = 52, + renderWhitespace = 53, + revealHorizontalRightPadding = 54, + roundedSelection = 55, + rulers = 56, + scrollbar = 57, + scrollBeyondLastColumn = 58, + scrollBeyondLastLine = 59, + selectionClipboard = 60, + selectionHighlight = 61, + selectOnLineNumbers = 62, + showUnused = 63, + smoothScrolling = 64, + stopRenderingLineAfter = 65, + suggestOnTriggerCharacters = 66, + useTabStops = 67, + wordBasedSuggestions = 68, + wordSeparators = 69, + wordWrap = 70, + wordWrapBreakAfterCharacters = 71, + wordWrapBreakBeforeCharacters = 72, + wordWrapBreakObtrusiveCharacters = 73, + wordWrapColumn = 74, + wordWrapMinified = 75, + wrappingIndent = 76, + ariaLabel = 77, + disableMonospaceOptimizations = 78, + editorClassName = 79, + tabFocusMode = 80, + layoutInfo = 81, + wrappingInfo = 82 } export const EditorOptions: { + acceptSuggestionOnCommitCharacter: any; + acceptSuggestionOnEnter: any; accessibilitySupport: any; autoClosingBrackets: any; autoClosingOvertype: any; @@ -3612,6 +3616,9 @@ declare namespace monaco.editor { autoIndent: any; automaticLayout: any; autoSurround: any; + codeLens: any; + colorDecorators: any; + contextmenu: any; copyWithSyntaxHighlighting: any; cursorBlinking: any; cursorSmoothCaretAnimation: any; @@ -3626,21 +3633,28 @@ declare namespace monaco.editor { fixedOverflowWidgets: any; folding: any; fontLigatures: any; + formatOnPaste: any; + formatOnType: any; glyphMargin: any; hideCursorInOverviewRuler: any; highlightActiveIndentGuide: any; inDiffEditor: any; + lightbulb: any; lineDecorationsWidth: IEditorOption; lineNumbers: any; lineNumbersMinChars: any; + links: any; + matchBrackets: any; minimap: any; mouseStyle: any; mouseWheelScrollSensitivity: any; mouseWheelZoom: any; multiCursorMergeOverlapping: any; multiCursorModifier: any; + occurrencesHighlight: any; overviewRulerBorder: any; overviewRulerLanes: any; + quickSuggestionsDelay: any; readOnly: any; renderControlCharacters: any; renderIndentGuides: any; @@ -3654,11 +3668,14 @@ declare namespace monaco.editor { scrollBeyondLastColumn: any; scrollBeyondLastLine: any; selectionClipboard: any; + selectionHighlight: any; selectOnLineNumbers: any; showUnused: any; smoothScrolling: any; stopRenderingLineAfter: any; + suggestOnTriggerCharacters: any; useTabStops: any; + wordBasedSuggestions: any; wordSeparators: any; wordWrap: any; wordWrapBreakAfterCharacters: any; From 2adf01f2af44d27520775c9c1c89e457766ed847 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 11:13:42 +0200 Subject: [PATCH 011/109] Convert more editor options --- .../common/config/commonEditorConfig.ts | 77 +- src/vs/editor/common/config/editorOptions.ts | 692 ++++++++---------- .../services/editorWorkerServiceImpl.ts | 3 +- .../common/standalone/standaloneEnums.ts | 132 ++-- .../contrib/codeAction/lightBulbWidget.ts | 2 +- .../editor/contrib/contextmenu/contextmenu.ts | 2 +- src/vs/editor/contrib/find/findController.ts | 20 +- src/vs/editor/contrib/find/findWidget.ts | 14 +- src/vs/editor/contrib/folding/folding.ts | 10 +- .../goToDefinition/goToDefinitionCommands.ts | 3 +- src/vs/editor/contrib/hover/hover.ts | 5 +- .../editor/contrib/hover/modesContentHover.ts | 5 +- .../parameterHints/parameterHintsModel.ts | 7 +- .../editor/contrib/suggest/completionModel.ts | 4 +- src/vs/editor/contrib/suggest/suggestModel.ts | 16 +- .../editor/contrib/suggest/suggestWidget.ts | 25 +- .../suggest/test/completionModel.test.ts | 31 +- .../editor/contrib/suggest/wordContextKey.ts | 5 +- src/vs/editor/contrib/suggest/wordDistance.ts | 3 +- .../common/config/commonEditorConfig.test.ts | 4 +- src/vs/monaco.d.ts | 264 ++++--- .../api/browser/mainThreadSaveParticipant.ts | 5 +- .../contrib/snippets/browser/tabCompletion.ts | 5 +- 23 files changed, 649 insertions(+), 685 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 3e48ce0e7b8..686808bbd1c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; -import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, IValidatedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, EditorOptionsValidator, EDITOR_DEFAULTS, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -116,59 +116,76 @@ export class EditorConfiguration2 { * Compatibility with old options */ function migrateOptions(options: IEditorOptions): void { - let wordWrap = options.wordWrap; + const wordWrap = options.wordWrap; if (wordWrap === true) { options.wordWrap = 'on'; } else if (wordWrap === false) { options.wordWrap = 'off'; } - let lineNumbers = options.lineNumbers; + const lineNumbers = options.lineNumbers; if (lineNumbers === true) { options.lineNumbers = 'on'; } else if (lineNumbers === false) { options.lineNumbers = 'off'; } - let autoClosingBrackets = options.autoClosingBrackets; + const autoClosingBrackets = options.autoClosingBrackets; if (autoClosingBrackets === false) { options.autoClosingBrackets = 'never'; options.autoClosingQuotes = 'never'; options.autoSurround = 'never'; } - let cursorBlinking = options.cursorBlinking; + const cursorBlinking = options.cursorBlinking; if (cursorBlinking === 'visible') { options.cursorBlinking = 'solid'; } - let renderWhitespace = options.renderWhitespace; + const renderWhitespace = options.renderWhitespace; if (renderWhitespace === true) { options.renderWhitespace = 'boundary'; } else if (renderWhitespace === false) { options.renderWhitespace = 'none'; } - let renderLineHighlight = options.renderLineHighlight; + const renderLineHighlight = options.renderLineHighlight; if (renderLineHighlight === true) { options.renderLineHighlight = 'line'; } else if (renderLineHighlight === false) { options.renderLineHighlight = 'none'; } - let acceptSuggestionOnEnter = options.acceptSuggestionOnEnter; + const acceptSuggestionOnEnter = options.acceptSuggestionOnEnter; if (acceptSuggestionOnEnter === true) { options.acceptSuggestionOnEnter = 'on'; } else if (acceptSuggestionOnEnter === false) { options.acceptSuggestionOnEnter = 'off'; } + + const tabCompletion = options.tabCompletion; + if (tabCompletion === false) { + options.tabCompletion = 'off'; + } else if (tabCompletion === true) { + options.tabCompletion = 'onlySnippets'; + } + + const hover = options.hover; + if (hover === true) { + options.hover = { + enabled: true + }; + } else if (hover === false) { + options.hover = { + enabled: false + }; + } } export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { public readonly isSimpleWidget: boolean; protected _rawOptions: IEditorOptions; - protected _validatedOptions: IValidatedEditorOptions; public editor!: InternalEditorOptions; private _isDominatedByLongLines: boolean; private _lineNumbersDigitCount: number; @@ -194,8 +211,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._rawOptions.hover = objects.mixin({}, this._rawOptions.hover || {}); this._rawOptions.parameterHints = objects.mixin({}, this._rawOptions.parameterHints || {}); - this._validatedOptions = EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); - this._rawOptions2 = EditorConfiguration2.readOptions(options); this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); @@ -237,7 +252,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed } private _computeInternalOptions(): [InternalEditorOptions, ComputedEditorOptions] { - const opts = this._validatedOptions; const partialEnv = this._getEnvConfiguration(); const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, partialEnv.zoomLevel, this.isSimpleWidget); const env: IEnvironmentalOptions = { @@ -252,7 +266,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; - const r = InternalEditorOptionsFactory.createInternalEditorOptions(env, opts); + const r = InternalEditorOptionsFactory.createInternalEditorOptions(env); const r2 = EditorConfiguration2.computeOptions(this._validatedOptions2, env); return [r, r2]; } @@ -308,7 +322,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed this._rawOptions = objects.mixin(this._rawOptions, newOptions || {}); this._rawOptions2 = EditorConfiguration2.mixOptions(this._rawOptions2, newOptions); - this._validatedOptions = EditorOptionsValidator.validate(this._rawOptions, EDITOR_DEFAULTS); this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); this._recomputeOptions(); @@ -491,32 +504,32 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.hover.enabled': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.hover.enabled, + 'default': EditorOptions.hover.defaultValue.enabled, 'description': nls.localize('hover.enabled', "Controls whether the hover is shown.") }, 'editor.hover.delay': { 'type': 'number', - 'default': EDITOR_DEFAULTS.contribInfo.hover.delay, + 'default': EditorOptions.hover.defaultValue.delay, 'description': nls.localize('hover.delay', "Controls the delay in milliseconds after which the hover is shown.") }, 'editor.hover.sticky': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.hover.sticky, + 'default': EditorOptions.hover.defaultValue.sticky, 'description': nls.localize('hover.sticky', "Controls whether the hover should remain visible when mouse is moved over it.") }, 'editor.find.seedSearchStringFromSelection': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.find.seedSearchStringFromSelection, + 'default': EditorOptions.find.defaultValue.seedSearchStringFromSelection, 'description': nls.localize('find.seedSearchStringFromSelection', "Controls whether the search string in the Find Widget is seeded from the editor selection.") }, 'editor.find.autoFindInSelection': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.find.autoFindInSelection, + 'default': EditorOptions.find.defaultValue.autoFindInSelection, 'description': nls.localize('find.autoFindInSelection', "Controls whether the find operation is carried out on selected text or the entire file in the editor.") }, 'editor.find.globalFindClipboard': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.find.globalFindClipboard, + 'default': EditorOptions.find.defaultValue.globalFindClipboard, 'description': nls.localize('find.globalFindClipboard', "Controls whether the Find Widget should read or modify the shared find clipboard on macOS."), 'included': platform.isMacintosh }, @@ -635,7 +648,7 @@ const editorConfiguration: IConfigurationNode = { } } ], - 'default': EDITOR_DEFAULTS.contribInfo.quickSuggestions, + 'default': EditorOptions.quickSuggestions.defaultValue, 'description': nls.localize('quickSuggestions', "Controls whether suggestions should automatically show up while typing.") }, 'editor.quickSuggestionsDelay': { @@ -646,12 +659,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.parameterHints.enabled': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.parameterHints.enabled, + 'default': EditorOptions.parameterHints.defaultValue.enabled, 'description': nls.localize('parameterHints.enabled', "Enables a pop-up that shows parameter documentation and type information as you type.") }, 'editor.parameterHints.cycle': { 'type': 'boolean', - 'default': EDITOR_DEFAULTS.contribInfo.parameterHints.cycle, + 'default': EditorOptions.parameterHints.defaultValue.cycle, 'description': nls.localize('parameterHints.cycle', "Controls whether the parameter hints menu cycles or closes when reaching the end of the list.") }, 'editor.autoClosingBrackets': { @@ -746,7 +759,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('snippetSuggestions.inline', "Show snippets suggestions with other suggestions."), nls.localize('snippetSuggestions.none', "Do not show snippet suggestions."), ], - 'default': EDITOR_DEFAULTS.contribInfo.suggest.snippets, + 'default': EditorOptions.snippetSuggestions.defaultValue, 'description': nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.") }, 'editor.emptySelectionClipboard': { @@ -761,7 +774,7 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.wordBasedSuggestions': { 'type': 'boolean', - 'default': EditorOptions.wordBasedSuggestions.defaultValue, + 'default': true, 'description': nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document.") }, 'editor.suggestSelection': { @@ -820,12 +833,12 @@ const editorConfiguration: IConfigurationNode = { }, 'editor.suggest.showIcons': { type: 'boolean', - default: EDITOR_DEFAULTS.contribInfo.suggest.showIcons, + default: EditorOptions.suggest.defaultValue.showIcons, description: nls.localize('suggest.showIcons', "Controls whether to show or hide icons in suggestions.") }, 'editor.suggest.maxVisibleSuggestions': { type: 'number', - default: EDITOR_DEFAULTS.contribInfo.suggest.maxVisibleSuggestions, + default: EditorOptions.suggest.defaultValue.maxVisibleSuggestions, minimum: 1, maximum: 15, description: nls.localize('suggest.maxVisibleSuggestions', "Controls how many suggestions IntelliSense will show before showing a scrollbar (maximum 15).") @@ -971,7 +984,7 @@ const editorConfiguration: IConfigurationNode = { description: nls.localize('editor.gotoLocation.multiple', "Controls the behavior of 'Go To' commands, like Go To Definition, when multiple target locations exist."), type: 'string', enum: ['peek', 'gotoAndPeek', 'goto'], - default: EDITOR_DEFAULTS.contribInfo.gotoLocation.multiple, + default: EditorOptions.gotoLocation.defaultValue.multiple, enumDescriptions: [ nls.localize('editor.gotoLocation.multiple.peek', 'Show peek view of the results (default)'), nls.localize('editor.gotoLocation.multiple.gotoAndPeek', 'Go to the primary result and show a peek view'), @@ -1087,13 +1100,13 @@ const editorConfiguration: IConfigurationNode = { 'editor.foldingStrategy': { 'type': 'string', 'enum': ['auto', 'indentation'], - 'default': EDITOR_DEFAULTS.contribInfo.foldingStrategy, + 'default': EditorOptions.foldingStrategy.defaultValue, 'markdownDescription': nls.localize('foldingStrategy', "Controls the strategy for computing folding ranges. `auto` uses a language specific folding strategy, if available. `indentation` uses the indentation based folding strategy.") }, 'editor.showFoldingControls': { 'type': 'string', 'enum': ['always', 'mouseover'], - 'default': EDITOR_DEFAULTS.contribInfo.showFoldingControls, + 'default': EditorOptions.showFoldingControls.defaultValue, 'description': nls.localize('showFoldingControls', "Controls whether the fold controls on the gutter are automatically hidden.") }, 'editor.matchBrackets': { @@ -1177,12 +1190,12 @@ const editorConfiguration: IConfigurationNode = { 'additionalProperties': { 'type': 'boolean' }, - 'default': EDITOR_DEFAULTS.contribInfo.codeActionsOnSave, + 'default': {}, 'description': nls.localize('codeActionsOnSave', "Code action kinds to be run on save.") }, 'editor.codeActionsOnSaveTimeout': { 'type': 'number', - 'default': EDITOR_DEFAULTS.contribInfo.codeActionsOnSaveTimeout, + 'default': 750, 'description': nls.localize('codeActionsOnSaveTimeout', "Timeout in milliseconds after which the code actions that are run on save are cancelled.") }, 'editor.selectionClipboard': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 09af97936c7..873bb5575e7 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -217,7 +217,7 @@ export interface ISuggestOptions { /** * Max suggestions to show in suggestions. Defaults to 12. */ - maxVisibleSuggestions?: boolean; + maxVisibleSuggestions?: number; /** * Names of suggestion types to filter. */ @@ -231,11 +231,10 @@ export interface IGotoLocationOptions { multiple?: 'peek' | 'gotoAndPeek' | 'goto'; } -/** - * Configuration map for codeActionsOnSave - */ -export interface ICodeActionsOnSaveOptions { - [kind: string]: boolean; +export interface IQuickSuggestionsOptions { + other: boolean; + comments: boolean; + strings: boolean; } /** @@ -528,7 +527,7 @@ export interface IEditorOptions { * Enable quick suggestions (shadow suggestions) * Defaults to true. */ - quickSuggestions?: boolean | { other: boolean, comments: boolean, strings: boolean }; + quickSuggestions?: boolean | IQuickSuggestionsOptions; /** * Quick suggestions show delay (in ms) * Defaults to 10 (ms) @@ -604,10 +603,6 @@ export interface IEditorOptions { * Syntax highlighting is copied. */ copyWithSyntaxHighlighting?: boolean; - /** - * Enable word based suggestions. Defaults to 'true' - */ - wordBasedSuggestions?: boolean; /** * The history mode for suggestions. */ @@ -625,7 +620,7 @@ export interface IEditorOptions { /** * Enable tab completion. */ - tabCompletion?: boolean | 'on' | 'off' | 'onlySnippets'; + tabCompletion?: 'on' | 'off' | 'onlySnippets'; /** * Enable selection highlight. * Defaults to true. @@ -645,10 +640,6 @@ export interface IEditorOptions { * Control the behavior and rendering of the code action lightbulb. */ lightbulb?: IEditorLightbulbOptions; - /** - * Code action kinds to be run on save. - */ - codeActionsOnSave?: ICodeActionsOnSaveOptions; /** * Timeout for running code actions on save. */ @@ -903,68 +894,6 @@ function _cursorStyleFromString(cursorStyle: 'line' | 'block' | 'underline' | 'l } } -export interface InternalEditorFindOptions { - readonly seedSearchStringFromSelection: boolean; - readonly autoFindInSelection: boolean; - readonly addExtraSpaceOnTop: boolean; - /** - * @internal - */ - readonly globalFindClipboard: boolean; -} - -export interface InternalEditorHoverOptions { - readonly enabled: boolean; - readonly delay: number; - readonly sticky: boolean; -} - -export interface InternalGoToLocationOptions { - readonly multiple: 'peek' | 'gotoAndPeek' | 'goto'; -} - -export interface InternalSuggestOptions { - readonly filterGraceful: boolean; - readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; - readonly snippetsPreventQuickSuggestions: boolean; - readonly localityBonus: boolean; - readonly shareSuggestSelections: boolean; - readonly showIcons: boolean; - readonly maxVisibleSuggestions: number; - readonly filteredTypes: Record; -} - -export interface InternalParameterHintOptions { - readonly enabled: boolean; - readonly cycle: boolean; -} - -export interface EditorContribOptions { - readonly hover: InternalEditorHoverOptions; - readonly quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; - readonly parameterHints: InternalParameterHintOptions; - readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; - readonly suggestFontSize: number; - readonly suggestLineHeight: number; - readonly tabCompletion: 'on' | 'off' | 'onlySnippets'; - readonly suggest: InternalSuggestOptions; - readonly gotoLocation: InternalGoToLocationOptions; - readonly foldingStrategy: 'auto' | 'indentation'; - readonly showFoldingControls: 'always' | 'mouseover'; - readonly find: InternalEditorFindOptions; - readonly codeActionsOnSave: ICodeActionsOnSaveOptions; - readonly codeActionsOnSaveTimeout: number; -} - -/** - * Validated configuration options for the editor. - * This is a 1 to 1 validated/parsed version of IEditorOptions merged on top of the defaults. - * @internal - */ -export interface IValidatedEditorOptions { - readonly contribInfo: EditorContribOptions; -} - /** * Internal configuration options (transformed or computed) for the editor. */ @@ -976,7 +905,6 @@ export class InternalEditorOptions { // ---- grouped options readonly fontInfo: FontInfo; - readonly contribInfo: EditorContribOptions; /** * @internal @@ -985,12 +913,10 @@ export class InternalEditorOptions { pixelRatio: number; lineHeight: number; fontInfo: FontInfo; - contribInfo: EditorContribOptions; }) { this.pixelRatio = source.pixelRatio; this.lineHeight = source.lineHeight | 0; this.fontInfo = source.fontInfo; - this.contribInfo = source.contribInfo; } /** @@ -1001,7 +927,6 @@ export class InternalEditorOptions { this.pixelRatio === other.pixelRatio && this.lineHeight === other.lineHeight && this.fontInfo.equals(other.fontInfo) - && InternalEditorOptions._equalsContribOptions(this.contribInfo, other.contribInfo) ); } @@ -1019,111 +944,8 @@ export class InternalEditorOptions { pixelRatio: (this.pixelRatio !== newOpts.pixelRatio), lineHeight: (this.lineHeight !== newOpts.lineHeight), fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)), - contribInfo: (!InternalEditorOptions._equalsContribOptions(this.contribInfo, newOpts.contribInfo)) }; } - - /** - * @internal - */ - private static _equalFindOptions(a: InternalEditorFindOptions, b: InternalEditorFindOptions): boolean { - return ( - a.seedSearchStringFromSelection === b.seedSearchStringFromSelection - && a.autoFindInSelection === b.autoFindInSelection - && a.globalFindClipboard === b.globalFindClipboard - && a.addExtraSpaceOnTop === b.addExtraSpaceOnTop - ); - } - - /** - * @internal - */ - private static _equalsParameterHintOptions(a: InternalParameterHintOptions, b: InternalParameterHintOptions): boolean { - return ( - a.enabled === b.enabled - && a.cycle === b.cycle - ); - } - - /** - * @internal - */ - private static _equalsHoverOptions(a: InternalEditorHoverOptions, b: InternalEditorHoverOptions): boolean { - return ( - a.enabled === b.enabled - && a.delay === b.delay - && a.sticky === b.sticky - ); - } - - /** - * @internal - */ - private static _equalsSuggestOptions(a: InternalSuggestOptions, b: InternalSuggestOptions): any { - if (a === b) { - return true; - } else if (!a || !b) { - return false; - } else { - return a.filterGraceful === b.filterGraceful - && a.snippets === b.snippets - && a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions - && a.localityBonus === b.localityBonus - && a.shareSuggestSelections === b.shareSuggestSelections - && a.showIcons === b.showIcons - && a.maxVisibleSuggestions === b.maxVisibleSuggestions - && objects.equals(a.filteredTypes, b.filteredTypes); - } - } - - private static _equalsGotoLocationOptions(a: InternalGoToLocationOptions | undefined, b: InternalGoToLocationOptions | undefined): boolean { - if (a === b) { - return true; - } else if (!a || !b) { - return false; - } else { - return a.multiple === b.multiple; - } - } - - /** - * @internal - */ - private static _equalsContribOptions(a: EditorContribOptions, b: EditorContribOptions): boolean { - return ( - this._equalsHoverOptions(a.hover, b.hover) - && InternalEditorOptions._equalsQuickSuggestions(a.quickSuggestions, b.quickSuggestions) - && this._equalsParameterHintOptions(a.parameterHints, b.parameterHints) - && a.suggestSelection === b.suggestSelection - && a.suggestFontSize === b.suggestFontSize - && a.suggestLineHeight === b.suggestLineHeight - && a.tabCompletion === b.tabCompletion - && this._equalsSuggestOptions(a.suggest, b.suggest) - && InternalEditorOptions._equalsGotoLocationOptions(a.gotoLocation, b.gotoLocation) - && a.foldingStrategy === b.foldingStrategy - && a.showFoldingControls === b.showFoldingControls - && this._equalFindOptions(a.find, b.find) - && objects.equals(a.codeActionsOnSave, b.codeActionsOnSave) - && a.codeActionsOnSaveTimeout === b.codeActionsOnSaveTimeout - ); - } - - private static _equalsQuickSuggestions(a: boolean | { other: boolean, comments: boolean, strings: boolean }, b: boolean | { other: boolean, comments: boolean, strings: boolean }): boolean { - if (typeof a === 'boolean') { - if (typeof b !== 'boolean') { - return false; - } - return a === b; - } - if (typeof b === 'boolean') { - return false; - } - return ( - a.comments === b.comments - && a.other === b.other - && a.strings === b.strings - ); - } } /** @@ -1134,7 +956,6 @@ export interface IConfigurationChangedEvent { readonly pixelRatio: boolean; readonly lineHeight: boolean; readonly fontInfo: boolean; - readonly contribInfo: boolean; } export interface IEnvironmentalOptions { @@ -1150,7 +971,7 @@ export interface IEnvironmentalOptions { readonly accessibilitySupport: AccessibilitySupport; } -function _boolean(value: any, defaultValue: T): boolean | T { +function _boolean(value: any, defaultValue: boolean): boolean { if (typeof value === 'undefined') { return defaultValue; } @@ -1161,21 +982,6 @@ function _boolean(value: any, defaultValue: T): boolean | T { return Boolean(value); } -function _booleanMap(value: { [key: string]: boolean } | undefined, defaultValue: { [key: string]: boolean }): { [key: string]: boolean } { - if (!value) { - return defaultValue; - } - - const out = Object.create(null); - for (const k of Object.keys(value)) { - const v = value[k]; - if (typeof v === 'boolean') { - out[k] = v; - } - } - return out; -} - function _string(value: any, defaultValue: string): string { if (typeof value !== 'string') { return defaultValue; @@ -1254,134 +1060,16 @@ function _scrollbarVisibilityFromString(visibility: string | undefined, defaultV } } -/** - * @internal - */ -export class EditorOptionsValidator { - - /** - * Validate raw editor options. - * i.e. since they can be defined by the user, they might be invalid. - */ - public static validate(opts: IEditorOptions, defaults: IValidatedEditorOptions): IValidatedEditorOptions { - const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo); - return { - contribInfo: contribInfo, - }; - } - - private static _sanitizeFindOpts(opts: IEditorFindOptions | undefined, defaults: InternalEditorFindOptions): InternalEditorFindOptions { - if (typeof opts !== 'object') { - return defaults; - } - - return { - seedSearchStringFromSelection: _boolean(opts.seedSearchStringFromSelection, defaults.seedSearchStringFromSelection), - autoFindInSelection: _boolean(opts.autoFindInSelection, defaults.autoFindInSelection), - globalFindClipboard: _boolean(opts.globalFindClipboard, defaults.globalFindClipboard), - addExtraSpaceOnTop: _boolean(opts.addExtraSpaceOnTop, defaults.addExtraSpaceOnTop) - }; - } - - private static _sanitizeParameterHintOpts(opts: IEditorParameterHintOptions | undefined, defaults: InternalParameterHintOptions): InternalParameterHintOptions { - if (typeof opts !== 'object') { - return defaults; - } - - return { - enabled: _boolean(opts.enabled, defaults.enabled), - cycle: _boolean(opts.cycle, defaults.cycle) - }; - } - - private static _sanitizeHoverOpts(_opts: boolean | IEditorHoverOptions | undefined, defaults: InternalEditorHoverOptions): InternalEditorHoverOptions { - let opts: IEditorHoverOptions; - if (typeof _opts === 'boolean') { - opts = { - enabled: _opts - }; - } else if (typeof _opts === 'object') { - opts = _opts; - } else { - return defaults; - } - - return { - enabled: _boolean(opts.enabled, defaults.enabled), - delay: _clampedInt(opts.delay, defaults.delay, 0, 10000), - sticky: _boolean(opts.sticky, defaults.sticky) - }; - } - - private static _sanitizeSuggestOpts(opts: IEditorOptions, defaults: InternalSuggestOptions): InternalSuggestOptions { - const suggestOpts = opts.suggest || {}; - return { - filterGraceful: _boolean(suggestOpts.filterGraceful, defaults.filterGraceful), - snippets: _stringSet<'top' | 'bottom' | 'inline' | 'none'>(opts.snippetSuggestions, defaults.snippets, ['top', 'bottom', 'inline', 'none']), - snippetsPreventQuickSuggestions: _boolean(suggestOpts.snippetsPreventQuickSuggestions, defaults.filterGraceful), - localityBonus: _boolean(suggestOpts.localityBonus, defaults.localityBonus), - shareSuggestSelections: _boolean(suggestOpts.shareSuggestSelections, defaults.shareSuggestSelections), - showIcons: _boolean(suggestOpts.showIcons, defaults.showIcons), - maxVisibleSuggestions: _clampedInt(suggestOpts.maxVisibleSuggestions, defaults.maxVisibleSuggestions, 1, 15), - filteredTypes: isObject(suggestOpts.filteredTypes) ? suggestOpts.filteredTypes : Object.create(null) - }; - } - - private static _sanitizeGotoLocationOpts(opts: IEditorOptions, defaults: InternalGoToLocationOptions): InternalGoToLocationOptions { - const gotoOpts = opts.gotoLocation || {}; - return { - multiple: _stringSet<'peek' | 'gotoAndPeek' | 'goto'>(gotoOpts.multiple, defaults.multiple, ['peek', 'gotoAndPeek', 'goto']) - }; - } - - private static _sanitizeTabCompletionOpts(opts: boolean | 'on' | 'off' | 'onlySnippets' | undefined, defaults: 'on' | 'off' | 'onlySnippets'): 'on' | 'off' | 'onlySnippets' { - if (opts === false) { - return 'off'; - } else if (opts === true) { - return 'onlySnippets'; - } else { - return _stringSet<'on' | 'off' | 'onlySnippets'>(opts, defaults, ['on', 'off', 'onlySnippets']); - } - } - - private static _sanitizeContribInfo(opts: IEditorOptions, defaults: EditorContribOptions): EditorContribOptions { - let quickSuggestions: boolean | { other: boolean, comments: boolean, strings: boolean }; - if (typeof opts.quickSuggestions === 'object') { - quickSuggestions = { other: true, ...opts.quickSuggestions }; - } else { - quickSuggestions = _boolean(opts.quickSuggestions, defaults.quickSuggestions); - } - const find = this._sanitizeFindOpts(opts.find, defaults.find); - return { - hover: this._sanitizeHoverOpts(opts.hover, defaults.hover), - quickSuggestions: quickSuggestions, - parameterHints: this._sanitizeParameterHintOpts(opts.parameterHints, defaults.parameterHints), - suggestSelection: _stringSet<'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'>(opts.suggestSelection, defaults.suggestSelection, ['first', 'recentlyUsed', 'recentlyUsedByPrefix']), - suggestFontSize: _clampedInt(opts.suggestFontSize, defaults.suggestFontSize, 0, 1000), - suggestLineHeight: _clampedInt(opts.suggestLineHeight, defaults.suggestLineHeight, 0, 1000), - tabCompletion: this._sanitizeTabCompletionOpts(opts.tabCompletion, defaults.tabCompletion), - suggest: this._sanitizeSuggestOpts(opts, defaults.suggest), - gotoLocation: this._sanitizeGotoLocationOpts(opts, defaults.gotoLocation), - foldingStrategy: _stringSet<'auto' | 'indentation'>(opts.foldingStrategy, defaults.foldingStrategy, ['auto', 'indentation']), - showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']), - find: find, - codeActionsOnSave: _booleanMap(opts.codeActionsOnSave, {}), - codeActionsOnSaveTimeout: _clampedInt(opts.codeActionsOnSaveTimeout, defaults.codeActionsOnSaveTimeout, 1, 10000) - }; - } -} - /** * @internal */ export class InternalEditorOptionsFactory { - public static createInternalEditorOptions(env: IEnvironmentalOptions, opts: IValidatedEditorOptions) { + public static createInternalEditorOptions(env: IEnvironmentalOptions) { return new InternalEditorOptions({ pixelRatio: env.pixelRatio, lineHeight: env.fontInfo.lineHeight, fontInfo: env.fontInfo, - contribInfo: opts.contribInfo, }); } } @@ -1448,55 +1136,6 @@ export const EDITOR_MODEL_DEFAULTS = { largeFileOptimizations: true }; -/** - * @internal - */ -export const EDITOR_DEFAULTS: IValidatedEditorOptions = { - contribInfo: { - hover: { - enabled: true, - delay: 300, - sticky: true - }, - quickSuggestions: { - other: true, - comments: false, - strings: false - }, - parameterHints: { - enabled: true, - cycle: false - }, - suggestSelection: 'recentlyUsed', - suggestFontSize: 0, - suggestLineHeight: 0, - tabCompletion: 'off', - suggest: { - filterGraceful: true, - snippets: 'inline', - snippetsPreventQuickSuggestions: true, - localityBonus: false, - shareSuggestSelections: false, - showIcons: true, - maxVisibleSuggestions: 12, - filteredTypes: Object.create(null) - }, - gotoLocation: { - multiple: 'peek' - }, - foldingStrategy: 'auto', - showFoldingControls: 'mouseover', - find: { - seedSearchStringFromSelection: true, - autoFindInSelection: false, - globalFindClipboard: false, - addExtraSpaceOnTop: true - }, - codeActionsOnSave: {}, - codeActionsOnSaveTimeout: 750 - }, -}; - /** * @internal */ @@ -1565,6 +1204,9 @@ export class ChangedEditorOptions { this._values[id] = value; } } + +//#region IEditorOption + /** * @internal */ @@ -1600,16 +1242,6 @@ export interface IEditorOption[] = []; - -function registerEditorOption(option: IEditorOption): IEditorOption { - editorOptionsRegistry[option.id] = option; - return option; -} - /** * @internal */ @@ -1724,6 +1356,7 @@ class EditorPassthroughOption> extends BaseEditorOption { + public validate(input: IEditorHoverOptions | undefined): InternalEditorHoverOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + delay: _clampedInt(input.delay, this.defaultValue.delay, 0, 10000), + sticky: _boolean(input.sticky, this.defaultValue.sticky) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorHoverOptions): InternalEditorHoverOptions { + return value; + } + public equals(a: InternalEditorHoverOptions, b: InternalEditorHoverOptions): boolean { + return ( + a.enabled === b.enabled + && a.delay === b.delay + && a.sticky === b.sticky + ); + } +} + +//#endregion + +//#region quickSuggestions + +export type ValidQuickSuggestionsOptions = boolean | Readonly>; + +class EditorQuickSuggestions> extends BaseEditorOption { + public readonly defaultValue: Readonly>; + constructor(id: K1, name: K2, defaultValue: Readonly>) { + super(id, name, defaultValue); + } + public validate(input: boolean | IQuickSuggestionsOptions | undefined): ValidQuickSuggestionsOptions { + if (typeof input === 'boolean') { + return input; + } + if (typeof input === 'object') { + return { + other: _boolean(input.other, this.defaultValue.other), + comments: _boolean(input.comments, this.defaultValue.comments), + strings: _boolean(input.strings, this.defaultValue.strings), + }; + } + return this.defaultValue; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: ValidQuickSuggestionsOptions): ValidQuickSuggestionsOptions { + return value; + } + public equals(a: ValidQuickSuggestionsOptions, b: ValidQuickSuggestionsOptions): boolean { + if (typeof a === 'boolean') { + if (typeof b !== 'boolean') { + return false; + } + return a === b; + } + if (typeof b === 'boolean') { + return false; + } + return ( + a.comments === b.comments + && a.other === b.other + && a.strings === b.strings + ); + } +} + +//#endregion + //#region accessibilitySupport class EditorAccessibilitySupportOption> extends BaseEditorOption { @@ -2029,6 +1740,161 @@ class EditorScrollbar>; + +export interface InternalSuggestOptions { + readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; + readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; + readonly shareSuggestSelections: boolean; + readonly showIcons: boolean; + readonly maxVisibleSuggestions: number; + readonly filteredTypes: Record; +} + +class EditorSuggest> extends BaseEditorOption { + public validate(input: ISuggestOptions | undefined): ValidSuggestOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + filterGraceful: _boolean(input.filterGraceful, this.defaultValue.filterGraceful), + snippetsPreventQuickSuggestions: _boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful), + localityBonus: _boolean(input.localityBonus, this.defaultValue.localityBonus), + shareSuggestSelections: _boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections), + showIcons: _boolean(input.showIcons, this.defaultValue.showIcons), + maxVisibleSuggestions: _clampedInt(input.maxVisibleSuggestions, this.defaultValue.maxVisibleSuggestions, 1, 15), + filteredTypes: isObject(input.filteredTypes) ? input.filteredTypes : Object.create(null) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: ValidSuggestOptions): InternalSuggestOptions { + const snippetSuggestions = options.get(EditorOption.snippetSuggestions); + return { + filterGraceful: value.filterGraceful, + snippets: snippetSuggestions, + snippetsPreventQuickSuggestions: value.snippetsPreventQuickSuggestions, + localityBonus: value.localityBonus, + shareSuggestSelections: value.shareSuggestSelections, + showIcons: value.showIcons, + maxVisibleSuggestions: value.maxVisibleSuggestions, + filteredTypes: value.filteredTypes, + }; + } + public equals(a: InternalSuggestOptions, b: InternalSuggestOptions): boolean { + return ( + a.filterGraceful === b.filterGraceful + && a.snippets === b.snippets + && a.snippetsPreventQuickSuggestions === b.snippetsPreventQuickSuggestions + && a.localityBonus === b.localityBonus + && a.shareSuggestSelections === b.shareSuggestSelections + && a.showIcons === b.showIcons + && a.maxVisibleSuggestions === b.maxVisibleSuggestions + && objects.equals(a.filteredTypes, b.filteredTypes) + ); + } +} + +//#endregion + +//#region parameterHints + +export interface InternalParameterHintOptions { + readonly enabled: boolean; + readonly cycle: boolean; +} + +class EditorParameterHints> extends BaseEditorOption { + public validate(input: IEditorParameterHintOptions | undefined): InternalParameterHintOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + cycle: _boolean(input.cycle, this.defaultValue.cycle) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalParameterHintOptions): InternalParameterHintOptions { + return value; + } + public equals(a: InternalParameterHintOptions, b: InternalParameterHintOptions): boolean { + return ( + a.enabled === b.enabled + && a.cycle === b.cycle + ); + } +} + +//#endregion + +//#region find + +export interface InternalEditorFindOptions { + readonly seedSearchStringFromSelection: boolean; + readonly autoFindInSelection: boolean; + readonly addExtraSpaceOnTop: boolean; + /** + * @internal + */ + readonly globalFindClipboard: boolean; +} + +class EditorFind> extends BaseEditorOption { + public validate(input: IEditorFindOptions | undefined): InternalEditorFindOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + seedSearchStringFromSelection: _boolean(input.seedSearchStringFromSelection, this.defaultValue.seedSearchStringFromSelection), + autoFindInSelection: _boolean(input.autoFindInSelection, this.defaultValue.autoFindInSelection), + globalFindClipboard: _boolean(input.globalFindClipboard, this.defaultValue.globalFindClipboard), + addExtraSpaceOnTop: _boolean(input.addExtraSpaceOnTop, this.defaultValue.addExtraSpaceOnTop) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorFindOptions): InternalEditorFindOptions { + return value; + } + public equals(a: InternalEditorFindOptions, b: InternalEditorFindOptions): boolean { + return ( + a.seedSearchStringFromSelection === b.seedSearchStringFromSelection + && a.autoFindInSelection === b.autoFindInSelection + && a.globalFindClipboard === b.globalFindClipboard + && a.addExtraSpaceOnTop === b.addExtraSpaceOnTop + ); + } +} + +//#endregion + +//#region gotoLocation + +export interface InternalGoToLocationOptions { + readonly multiple: 'peek' | 'gotoAndPeek' | 'goto'; +} + +class EditorGoToLocation> extends BaseEditorOption { + public validate(input: IGotoLocationOptions | undefined): InternalGoToLocationOptions { + if (typeof input !== 'object') { + return this.defaultValue; + } + return { + multiple: _stringSet<'peek' | 'gotoAndPeek' | 'goto'>(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto']) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalGoToLocationOptions): InternalGoToLocationOptions { + return value; + } + public equals(a: InternalGoToLocationOptions, b: InternalGoToLocationOptions): boolean { + return ( + a.multiple === b.multiple + ); + } +} + +//#endregion + //#region layoutInfo /** @@ -2467,6 +2333,16 @@ function _multiCursorModifierFromString(multiCursorModifier: 'ctrlCmd' | 'alt'): return 'altKey'; } +/** + * @internal + */ +export const editorOptionsRegistry: IEditorOption[] = []; + +function registerEditorOption(option: IEditorOption): IEditorOption { + editorOptionsRegistry[option.id] = option; + return option; +} + export const enum EditorOption { acceptSuggestionOnCommitCharacter, acceptSuggestionOnEnter, @@ -2491,14 +2367,18 @@ export const enum EditorOption { emptySelectionClipboard, extraEditorClassName, fastScrollSensitivity, + find, fixedOverflowWidgets, folding, + foldingStrategy, fontLigatures, formatOnPaste, formatOnType, glyphMargin, + gotoLocation, hideCursorInOverviewRuler, highlightActiveIndentGuide, + hover, inDiffEditor, lightbulb, lineDecorationsWidth, @@ -2515,6 +2395,8 @@ export const enum EditorOption { occurrencesHighlight, overviewRulerBorder, overviewRulerLanes, + parameterHints, + quickSuggestions, quickSuggestionsDelay, readOnly, renderControlCharacters, @@ -2531,12 +2413,17 @@ export const enum EditorOption { selectionClipboard, selectionHighlight, selectOnLineNumbers, + showFoldingControls, showUnused, + snippetSuggestions, smoothScrolling, stopRenderingLineAfter, + suggestFontSize, + suggestLineHeight, suggestOnTriggerCharacters, + suggestSelection, + tabCompletion, useTabStops, - wordBasedSuggestions, wordSeparators, wordWrap, wordWrapBreakAfterCharacters, @@ -2550,6 +2437,7 @@ export const enum EditorOption { disableMonospaceOptimizations, editorClassName, tabFocusMode, + suggest, layoutInfo, wrappingInfo, } @@ -2578,14 +2466,29 @@ export const EditorOptions = { emptySelectionClipboard: registerEditorOption(new EditorEmptySelectionClipboard(EditorOption.emptySelectionClipboard, 'emptySelectionClipboard', true)), extraEditorClassName: registerEditorOption(new EditorStringOption(EditorOption.extraEditorClassName, 'extraEditorClassName', '')), fastScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.fastScrollSensitivity, 'fastScrollSensitivity', 5, x => (x <= 0 ? 5 : x))), + find: registerEditorOption(new EditorFind(EditorOption.find, 'find', { + seedSearchStringFromSelection: true, + autoFindInSelection: false, + globalFindClipboard: false, + addExtraSpaceOnTop: true + })), fixedOverflowWidgets: registerEditorOption(new EditorBooleanOption(EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false)), folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), + foldingStrategy: registerEditorOption(new EditorEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto', ['auto', 'indentation'], (x: 'auto' | 'indentation') => x)), fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), formatOnPaste: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnPaste, 'formatOnPaste', false)), formatOnType: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnType, 'formatOnType', false)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), + gotoLocation: registerEditorOption(new EditorGoToLocation(EditorOption.gotoLocation, 'gotoLocation', { + multiple: 'peek' + })), hideCursorInOverviewRuler: registerEditorOption(new EditorBooleanOption(EditorOption.hideCursorInOverviewRuler, 'hideCursorInOverviewRuler', false)), highlightActiveIndentGuide: registerEditorOption(new EditorBooleanOption(EditorOption.highlightActiveIndentGuide, 'highlightActiveIndentGuide', true)), + hover: registerEditorOption(new EditorHover(EditorOption.hover, 'hover', { + enabled: true, + delay: 300, + sticky: true + })), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), lightbulb: registerEditorOption(new EditorLightbulb(EditorOption.lightbulb, 'lightbulb', { enabled: true @@ -2610,6 +2513,15 @@ export const EditorOptions = { occurrencesHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.occurrencesHighlight, 'occurrencesHighlight', true)), overviewRulerBorder: registerEditorOption(new EditorBooleanOption(EditorOption.overviewRulerBorder, 'overviewRulerBorder', true)), overviewRulerLanes: registerEditorOption(new EditorIntOption(EditorOption.overviewRulerLanes, 'overviewRulerLanes', 2, 0, 3)), + parameterHints: registerEditorOption(new EditorParameterHints(EditorOption.parameterHints, 'parameterHints', { + enabled: true, + cycle: false + })), + quickSuggestions: registerEditorOption(new EditorQuickSuggestions(EditorOption.quickSuggestions, 'quickSuggestions', { + other: true, + comments: false, + strings: false + })), quickSuggestionsDelay: registerEditorOption(new EditorIntOption(EditorOption.quickSuggestionsDelay, 'quickSuggestionsDelay', 10, 0, Constants.MAX_SAFE_SMALL_INTEGER)), readOnly: registerEditorOption(new EditorBooleanOption(EditorOption.readOnly, 'readOnly', false)), renderControlCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.renderControlCharacters, 'renderControlCharacters', false)), @@ -2638,12 +2550,17 @@ export const EditorOptions = { selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), selectionHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.selectionHighlight, 'selectionHighlight', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), + showFoldingControls: registerEditorOption(new EditorEnumOption(EditorOption.showFoldingControls, 'showFoldingControls', 'mouseover', ['always', 'mouseover'], (x: 'always' | 'mouseover') => x)), showUnused: registerEditorOption(new EditorBooleanOption(EditorOption.showUnused, 'showUnused', true)), + snippetSuggestions: registerEditorOption(new EditorEnumOption(EditorOption.snippetSuggestions, 'snippetSuggestions', 'inline', ['top', 'bottom', 'inline', 'none'], x => x)), smoothScrolling: registerEditorOption(new EditorBooleanOption(EditorOption.smoothScrolling, 'smoothScrolling', false)), stopRenderingLineAfter: registerEditorOption(new EditorIntOption(EditorOption.stopRenderingLineAfter, 'stopRenderingLineAfter', 10000, -1, Constants.MAX_SAFE_SMALL_INTEGER)), + suggestFontSize: registerEditorOption(new EditorIntOption(EditorOption.suggestFontSize, 'suggestFontSize', 0, 0, 1000)), + suggestLineHeight: registerEditorOption(new EditorIntOption(EditorOption.suggestLineHeight, 'suggestLineHeight', 0, 0, 1000)), suggestOnTriggerCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.suggestOnTriggerCharacters, 'suggestOnTriggerCharacters', true)), + suggestSelection: registerEditorOption(new EditorEnumOption(EditorOption.suggestSelection, 'suggestSelection', 'recentlyUsed', ['first', 'recentlyUsed', 'recentlyUsedByPrefix'], (x: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix') => x)), + tabCompletion: registerEditorOption(new EditorEnumOption(EditorOption.tabCompletion, 'tabCompletion', 'off', ['on', 'off', 'onlySnippets'], (x: 'on' | 'off' | 'onlySnippets') => x)), useTabStops: registerEditorOption(new EditorBooleanOption(EditorOption.useTabStops, 'useTabStops', true)), - wordBasedSuggestions: registerEditorOption(new EditorBooleanOption(EditorOption.wordBasedSuggestions, 'wordBasedSuggestions', true)), wordSeparators: registerEditorOption(new EditorStringOption(EditorOption.wordSeparators, 'wordSeparators', USUAL_WORD_SEPARATORS)), wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], (x: 'off' | 'on' | 'wordWrapColumn' | 'bounded') => x)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), @@ -2653,11 +2570,20 @@ export const EditorOptions = { wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOption.wordWrapMinified, 'wordWrapMinified', true)), wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), - // Leave these at the end! + // Leave these at the end (because they have dependencies!) ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOption.accessibilitySupport])), disableMonospaceOptimizations: registerEditorOption(new EditorDisableMonospaceOptimizations(EditorOption.disableMonospaceOptimizations, 'disableMonospaceOptimizations', false, [EditorOption.fontLigatures])), editorClassName: registerEditorOption(new EditorClassName(EditorOption.editorClassName, 'editorClassName', undefined, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])), tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), + suggest: registerEditorOption(new EditorSuggest(EditorOption.suggest, 'suggest', { + filterGraceful: true, + snippetsPreventQuickSuggestions: true, + localityBonus: false, + shareSuggestSelections: false, + showIcons: true, + maxVisibleSuggestions: 12, + filteredTypes: Object.create(null) + }, [EditorOption.snippetSuggestions])), layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers])), wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, 'wrappingInfo', undefined, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), }; diff --git a/src/vs/editor/common/services/editorWorkerServiceImpl.ts b/src/vs/editor/common/services/editorWorkerServiceImpl.ts index 34001e40608..9267a035826 100644 --- a/src/vs/editor/common/services/editorWorkerServiceImpl.ts +++ b/src/vs/editor/common/services/editorWorkerServiceImpl.ts @@ -8,7 +8,6 @@ import { Disposable, IDisposable, dispose, toDisposable, DisposableStore } from import { URI } from 'vs/base/common/uri'; import { SimpleWorkerClient, logOnceWebWorkerWarning, IWorkerClient } from 'vs/base/common/worker/simpleWorker'; import { DefaultWorkerFactory } from 'vs/base/worker/defaultWorkerFactory'; -import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange } from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -146,7 +145,7 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider { } provideCompletionItems(model: ITextModel, position: Position): Promise | undefined { - const { wordBasedSuggestions } = this._configurationService.getValue(model.uri, position, 'editor'); + const { wordBasedSuggestions } = this._configurationService.getValue<{ wordBasedSuggestions?: boolean }>(model.uri, position, 'editor'); if (!wordBasedSuggestions) { return undefined; } diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 8393a6c1ec6..6410d3b438b 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -463,66 +463,78 @@ export enum EditorOption { emptySelectionClipboard = 20, extraEditorClassName = 21, fastScrollSensitivity = 22, - fixedOverflowWidgets = 23, - folding = 24, - fontLigatures = 25, - formatOnPaste = 26, - formatOnType = 27, - glyphMargin = 28, - hideCursorInOverviewRuler = 29, - highlightActiveIndentGuide = 30, - inDiffEditor = 31, - lightbulb = 32, - lineDecorationsWidth = 33, - lineNumbers = 34, - lineNumbersMinChars = 35, - links = 36, - matchBrackets = 37, - minimap = 38, - mouseStyle = 39, - mouseWheelScrollSensitivity = 40, - mouseWheelZoom = 41, - multiCursorMergeOverlapping = 42, - multiCursorModifier = 43, - occurrencesHighlight = 44, - overviewRulerBorder = 45, - overviewRulerLanes = 46, - quickSuggestionsDelay = 47, - readOnly = 48, - renderControlCharacters = 49, - renderIndentGuides = 50, - renderFinalNewline = 51, - renderLineHighlight = 52, - renderWhitespace = 53, - revealHorizontalRightPadding = 54, - roundedSelection = 55, - rulers = 56, - scrollbar = 57, - scrollBeyondLastColumn = 58, - scrollBeyondLastLine = 59, - selectionClipboard = 60, - selectionHighlight = 61, - selectOnLineNumbers = 62, - showUnused = 63, - smoothScrolling = 64, - stopRenderingLineAfter = 65, - suggestOnTriggerCharacters = 66, - useTabStops = 67, - wordBasedSuggestions = 68, - wordSeparators = 69, - wordWrap = 70, - wordWrapBreakAfterCharacters = 71, - wordWrapBreakBeforeCharacters = 72, - wordWrapBreakObtrusiveCharacters = 73, - wordWrapColumn = 74, - wordWrapMinified = 75, - wrappingIndent = 76, - ariaLabel = 77, - disableMonospaceOptimizations = 78, - editorClassName = 79, - tabFocusMode = 80, - layoutInfo = 81, - wrappingInfo = 82 + find = 23, + fixedOverflowWidgets = 24, + folding = 25, + foldingStrategy = 26, + fontLigatures = 27, + formatOnPaste = 28, + formatOnType = 29, + glyphMargin = 30, + gotoLocation = 31, + hideCursorInOverviewRuler = 32, + highlightActiveIndentGuide = 33, + hover = 34, + inDiffEditor = 35, + lightbulb = 36, + lineDecorationsWidth = 37, + lineNumbers = 38, + lineNumbersMinChars = 39, + links = 40, + matchBrackets = 41, + minimap = 42, + mouseStyle = 43, + mouseWheelScrollSensitivity = 44, + mouseWheelZoom = 45, + multiCursorMergeOverlapping = 46, + multiCursorModifier = 47, + occurrencesHighlight = 48, + overviewRulerBorder = 49, + overviewRulerLanes = 50, + parameterHints = 51, + quickSuggestions = 52, + quickSuggestionsDelay = 53, + readOnly = 54, + renderControlCharacters = 55, + renderIndentGuides = 56, + renderFinalNewline = 57, + renderLineHighlight = 58, + renderWhitespace = 59, + revealHorizontalRightPadding = 60, + roundedSelection = 61, + rulers = 62, + scrollbar = 63, + scrollBeyondLastColumn = 64, + scrollBeyondLastLine = 65, + selectionClipboard = 66, + selectionHighlight = 67, + selectOnLineNumbers = 68, + showFoldingControls = 69, + showUnused = 70, + snippetSuggestions = 71, + smoothScrolling = 72, + stopRenderingLineAfter = 73, + suggestFontSize = 74, + suggestLineHeight = 75, + suggestOnTriggerCharacters = 76, + suggestSelection = 77, + tabCompletion = 78, + useTabStops = 79, + wordSeparators = 80, + wordWrap = 81, + wordWrapBreakAfterCharacters = 82, + wordWrapBreakBeforeCharacters = 83, + wordWrapBreakObtrusiveCharacters = 84, + wordWrapColumn = 85, + wordWrapMinified = 86, + wrappingIndent = 87, + ariaLabel = 88, + disableMonospaceOptimizations = 89, + editorClassName = 90, + tabFocusMode = 91, + suggest = 92, + layoutInfo = 93, + wrappingInfo = 94 } /** diff --git a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts index a43dabec6f0..3987b9a5eee 100644 --- a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts +++ b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts @@ -107,7 +107,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget { })); this._register(this._editor.onDidChangeConfiguration(e => { // hide when told to do so - if (e.contribInfo && !this._editor.getOption(EditorOption.lightbulb).enabled) { + if (e.hasChanged(EditorOption.lightbulb) && !this._editor.getOption(EditorOption.lightbulb).enabled) { this.hide(); } })); diff --git a/src/vs/editor/contrib/contextmenu/contextmenu.ts b/src/vs/editor/contrib/contextmenu/contextmenu.ts index 65fbdef07bb..e88f633d4ca 100644 --- a/src/vs/editor/contrib/contextmenu/contextmenu.ts +++ b/src/vs/editor/contrib/contextmenu/contextmenu.ts @@ -148,7 +148,7 @@ export class ContextMenuController implements IEditorContribution { } // Disable hover - const oldHoverSetting = this._editor.getConfiguration().contribInfo.hover; + const oldHoverSetting = this._editor.getOption(EditorOption.hover); this._editor.updateOptions({ hover: { enabled: false diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 631d9041902..f5c7305872f 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -121,7 +121,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd if (shouldRestartFind) { this._start({ forceRevealReplace: false, - seedSearchStringFromSelection: false && this._editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, + seedSearchStringFromSelection: false && this._editor.getOption(EditorOption.find).seedSearchStringFromSelection, seedSearchStringFromGlobalClipboard: false, shouldFocus: FindStartFocusAction.NoFocusChange, shouldAnimate: false, @@ -353,7 +353,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd } public getGlobalBufferTerm(): string { - if (this._editor.getConfiguration().contribInfo.find.globalFindClipboard + if (this._editor.getOption(EditorOption.find).globalFindClipboard && this._clipboardService && this._editor.hasModel() && !this._editor.getModel().isTooLargeForSyncing() @@ -364,7 +364,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd } public setGlobalBufferTerm(text: string) { - if (this._editor.getConfiguration().contribInfo.find.globalFindClipboard + if (this._editor.getOption(EditorOption.find).globalFindClipboard && this._clipboardService && this._editor.hasModel() && !this._editor.getModel().isTooLargeForSyncing() @@ -399,7 +399,7 @@ export class FindController extends CommonFindController implements IFindControl this._createFindWidget(); } - if (!this._widget!.getPosition() && this._editor.getConfiguration().contribInfo.find.autoFindInSelection) { + if (!this._widget!.getPosition() && this._editor.getOption(EditorOption.find).autoFindInSelection) { // not visible yet so we need to set search scope if `editor.find.autoFindInSelection` is `true` opts.updateSearchScope = true; } @@ -457,8 +457,8 @@ export class StartFindAction extends EditorAction { if (controller) { controller.start({ forceRevealReplace: false, - seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, - seedSearchStringFromGlobalClipboard: editor.getConfiguration().contribInfo.find.globalFindClipboard, + seedSearchStringFromSelection: editor.getOption(EditorOption.find).seedSearchStringFromSelection, + seedSearchStringFromGlobalClipboard: editor.getOption(EditorOption.find).globalFindClipboard, shouldFocus: FindStartFocusAction.FocusFindInput, shouldAnimate: true, updateSearchScope: false @@ -508,7 +508,7 @@ export abstract class MatchFindAction extends EditorAction { if (controller && !this._run(controller)) { controller.start({ forceRevealReplace: false, - seedSearchStringFromSelection: (controller.getState().searchString.length === 0) && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, + seedSearchStringFromSelection: (controller.getState().searchString.length === 0) && editor.getOption(EditorOption.find).seedSearchStringFromSelection, seedSearchStringFromGlobalClipboard: true, shouldFocus: FindStartFocusAction.NoFocusChange, shouldAnimate: true, @@ -620,7 +620,7 @@ export abstract class SelectionMatchFindAction extends EditorAction { if (!this._run(controller)) { controller.start({ forceRevealReplace: false, - seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, + seedSearchStringFromSelection: editor.getOption(EditorOption.find).seedSearchStringFromSelection, seedSearchStringFromGlobalClipboard: false, shouldFocus: FindStartFocusAction.NoFocusChange, shouldAnimate: true, @@ -709,7 +709,7 @@ export class StartFindReplaceAction extends EditorAction { // we only seed search string from selection when the current selection is single line and not empty, // + the find input is not focused let seedSearchStringFromSelection = !currentSelection.isEmpty() - && currentSelection.startLineNumber === currentSelection.endLineNumber && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection + && currentSelection.startLineNumber === currentSelection.endLineNumber && editor.getOption(EditorOption.find).seedSearchStringFromSelection && !findInputFocused; /* * if the existing search string in find widget is empty and we don't seed search string from selection, it means the Find Input is still empty, so we should focus the Find Input instead of Replace Input. @@ -726,7 +726,7 @@ export class StartFindReplaceAction extends EditorAction { controller.start({ forceRevealReplace: true, seedSearchStringFromSelection: seedSearchStringFromSelection, - seedSearchStringFromGlobalClipboard: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, + seedSearchStringFromGlobalClipboard: editor.getOption(EditorOption.find).seedSearchStringFromSelection, shouldFocus: shouldFocus, shouldAnimate: true, updateSearchScope: false diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index 4245ed4343f..9a399ea3aeb 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -192,8 +192,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this.updateAccessibilitySupport(); } - if (e.contribInfo) { - const addExtraSpaceOnTop = this._codeEditor.getConfiguration().contribInfo.find.addExtraSpaceOnTop; + if (e.hasChanged(EditorOption.find)) { + const addExtraSpaceOnTop = this._codeEditor.getOption(EditorOption.find).addExtraSpaceOnTop; if (addExtraSpaceOnTop && !this._viewZone) { this._viewZone = new FindWidgetViewZone(0); this._showViewZone(); @@ -239,7 +239,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas })); this._codeEditor.addOverlayWidget(this); - if (this._codeEditor.getConfiguration().contribInfo.find.addExtraSpaceOnTop) { + if (this._codeEditor.getOption(EditorOption.find).addExtraSpaceOnTop) { this._viewZone = new FindWidgetViewZone(0); // Put it before the first line then users can scroll beyond the first line. } @@ -467,7 +467,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas const selection = this._codeEditor.getSelection(); const isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false; - if (isSelection && this._codeEditor.getConfiguration().contribInfo.find.autoFindInSelection) { + if (isSelection && this._codeEditor.getOption(EditorOption.find).autoFindInSelection) { this._toggleSelectionFind.checked = true; } else { this._toggleSelectionFind.checked = false; @@ -488,7 +488,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._codeEditor.layoutOverlayWidget(this); let adjustEditorScrollTop = true; - if (this._codeEditor.getConfiguration().contribInfo.find.seedSearchStringFromSelection && selection) { + if (this._codeEditor.getOption(EditorOption.find).seedSearchStringFromSelection && selection) { const domNode = this._codeEditor.getDomNode(); if (domNode) { const editorCoords = dom.getDomNodePagePosition(domNode); @@ -535,7 +535,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas } private _layoutViewZone() { - const addExtraSpaceOnTop = this._codeEditor.getConfiguration().contribInfo.find.addExtraSpaceOnTop; + const addExtraSpaceOnTop = this._codeEditor.getOption(EditorOption.find).addExtraSpaceOnTop; if (!addExtraSpaceOnTop) { this._removeViewZone(); @@ -563,7 +563,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas return; } - const addExtraSpaceOnTop = this._codeEditor.getConfiguration().contribInfo.find.addExtraSpaceOnTop; + const addExtraSpaceOnTop = this._codeEditor.getOption(EditorOption.find).addExtraSpaceOnTop; if (!addExtraSpaceOnTop) { return; diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index 648461cd082..4ab5ce4decc 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -89,8 +89,8 @@ export class FoldingController extends Disposable implements IEditorContribution this.editor = editor; const options = this.editor.getOptions(); this._isEnabled = options.get(EditorOption.folding); - this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover'; - this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation'; + this._autoHideFoldingControls = options.get(EditorOption.showFoldingControls) === 'mouseover'; + this._useFoldingProviders = options.get(EditorOption.foldingStrategy) !== 'indentation'; this.foldingModel = null; this.hiddenRangeModel = null; @@ -110,7 +110,7 @@ export class FoldingController extends Disposable implements IEditorContribution this._register(this.editor.onDidChangeModel(() => this.onModelChanged())); this._register(this.editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.contribInfo || e.hasChanged(EditorOption.folding)) { + if (e.hasChanged(EditorOption.folding) || e.hasChanged(EditorOption.showFoldingControls) || e.hasChanged(EditorOption.foldingStrategy)) { let oldIsEnabled = this._isEnabled; const options = this.editor.getOptions(); this._isEnabled = options.get(EditorOption.folding); @@ -119,13 +119,13 @@ export class FoldingController extends Disposable implements IEditorContribution this.onModelChanged(); } let oldShowFoldingControls = this._autoHideFoldingControls; - this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover'; + this._autoHideFoldingControls = options.get(EditorOption.showFoldingControls) === 'mouseover'; if (oldShowFoldingControls !== this._autoHideFoldingControls) { this.foldingDecorationProvider.autoHideFoldingControls = this._autoHideFoldingControls; this.onModelContentChanged(); } let oldUseFoldingProviders = this._useFoldingProviders; - this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation'; + this._useFoldingProviders = options.get(EditorOption.foldingStrategy) !== 'indentation'; if (oldUseFoldingProviders !== this._useFoldingProviders) { this.onFoldingStrategyChanged(); } diff --git a/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts b/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts index baad3f0bb17..6e29856e81e 100644 --- a/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts +++ b/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts @@ -30,6 +30,7 @@ import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefiniti import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { EditorStateCancellationTokenSource, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState'; import { ISymbolNavigationService } from 'vs/editor/contrib/goToDefinition/goToDefinitionResultsNavigation'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class DefinitionActionConfig { @@ -137,7 +138,7 @@ export class DefinitionAction extends EditorAction { const msg = model.getAriaMessage(); alert(msg); - const { gotoLocation } = editor.getConfiguration().contribInfo; + const gotoLocation = editor.getOption(EditorOption.gotoLocation); if (this._configuration.openInPeek || (gotoLocation.multiple === 'peek' && model.references.length > 1)) { this._openInPeek(editorService, editor, model); diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index e03c5464e51..b89e96001d3 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -75,7 +75,7 @@ export class ModesHoverController implements IEditorContribution { this._hookEvents(); this._didChangeConfigurationHandler = this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.contribInfo) { + if (e.hasChanged(EditorOption.hover)) { this._hideWidgets(); this._unhookEvents(); this._hookEvents(); @@ -86,7 +86,7 @@ export class ModesHoverController implements IEditorContribution { private _hookEvents(): void { const hideWidgetsEventHandler = () => this._hideWidgets(); - const hoverOpts = this._editor.getConfiguration().contribInfo.hover; + const hoverOpts = this._editor.getOption(EditorOption.hover); this._isHoverEnabled = hoverOpts.enabled; this._isHoverSticky = hoverOpts.sticky; if (this._isHoverEnabled) { @@ -147,7 +147,6 @@ export class ModesHoverController implements IEditorContribution { } private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void { - // const this._editor.getConfiguration().contribInfo.hover.sticky; let targetType = mouseEvent.target.type; if (this._isMouseDown && this._hoverClicked && this.contentWidget.isColorPickerVisible()) { diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index d42f5153a1d..76bb60097fd 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -37,6 +37,7 @@ import { QuickFixAction, QuickFixController } from 'vs/editor/contrib/codeAction import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const $ = dom.$; @@ -222,7 +223,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { result => this._withResult(result, true), null, result => this._withResult(result, false), - this._editor.getConfiguration().contribInfo.hover.delay + this._editor.getOption(EditorOption.hover).delay ); this._register(dom.addStandardDisposableListener(this.getDomNode(), dom.EventType.FOCUS, () => { @@ -234,7 +235,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { dom.removeClass(this.getDomNode(), 'colorpicker-hover'); })); this._register(editor.onDidChangeConfiguration((e) => { - this._hoverOperation.setHoverTime(this._editor.getConfiguration().contribInfo.hover.delay); + this._hoverOperation.setHoverTime(this._editor.getOption(EditorOption.hover).delay); })); } diff --git a/src/vs/editor/contrib/parameterHints/parameterHintsModel.ts b/src/vs/editor/contrib/parameterHints/parameterHintsModel.ts index 21cf0393170..6c3c9cb9ae6 100644 --- a/src/vs/editor/contrib/parameterHints/parameterHintsModel.ts +++ b/src/vs/editor/contrib/parameterHints/parameterHintsModel.ts @@ -12,6 +12,7 @@ import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursor import { CharacterSet } from 'vs/editor/common/core/characterClassifier'; import * as modes from 'vs/editor/common/modes'; import { provideSignatureHelp } from 'vs/editor/contrib/parameterHints/provideSignatureHelp'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface TriggerContext { readonly triggerKind: modes.SignatureHelpTriggerKind; @@ -125,7 +126,7 @@ export class ParameterHintsModel extends Disposable { const length = this.state.hints.signatures.length; const activeSignature = this.state.hints.activeSignature; const last = (activeSignature % length) === (length - 1); - const cycle = this.editor.getConfiguration().contribInfo.parameterHints.cycle; + const cycle = this.editor.getOption(EditorOption.parameterHints).cycle; // If there is only one signature, or we're on last signature of list if ((length < 2 || last) && !cycle) { @@ -144,7 +145,7 @@ export class ParameterHintsModel extends Disposable { const length = this.state.hints.signatures.length; const activeSignature = this.state.hints.activeSignature; const first = activeSignature === 0; - const cycle = this.editor.getConfiguration().contribInfo.parameterHints.cycle; + const cycle = this.editor.getOption(EditorOption.parameterHints).cycle; // If there is only one signature, or we're on first signature of list if ((length < 2 || first) && !cycle) { @@ -271,7 +272,7 @@ export class ParameterHintsModel extends Disposable { } private onEditorConfigurationChange(): void { - this.triggerOnType = this.editor.getConfiguration().contribInfo.parameterHints.enabled; + this.triggerOnType = this.editor.getOption(EditorOption.parameterHints).enabled; if (!this.triggerOnType) { this.cancel(); diff --git a/src/vs/editor/contrib/suggest/completionModel.ts b/src/vs/editor/contrib/suggest/completionModel.ts index 9a806ddf3de..0796b12bb9d 100644 --- a/src/vs/editor/contrib/suggest/completionModel.ts +++ b/src/vs/editor/contrib/suggest/completionModel.ts @@ -6,7 +6,7 @@ import { fuzzyScore, fuzzyScoreGracefulAggressive, FuzzyScorer, FuzzyScore, anyScore } from 'vs/base/common/filters'; import { CompletionItemProvider, CompletionItemKind } from 'vs/editor/common/modes'; import { CompletionItem } from './suggest'; -import { InternalSuggestOptions, EDITOR_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { InternalSuggestOptions } from 'vs/editor/common/config/editorOptions'; import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance'; import { CharCode } from 'vs/base/common/charCode'; import { compareIgnoreCase } from 'vs/base/common/strings'; @@ -60,7 +60,7 @@ export class CompletionModel { column: number, lineContext: LineContext, wordDistance: WordDistance, - options: InternalSuggestOptions = EDITOR_DEFAULTS.contribInfo.suggest + options: InternalSuggestOptions ) { this._items = items; this._column = column; diff --git a/src/vs/editor/contrib/suggest/suggestModel.ts b/src/vs/editor/contrib/suggest/suggestModel.ts index 0d0bbe19f4d..bd5416bddc6 100644 --- a/src/vs/editor/contrib/suggest/suggestModel.ts +++ b/src/vs/editor/contrib/suggest/suggestModel.ts @@ -278,7 +278,7 @@ export class SuggestModel implements IDisposable { if (this._state === State.Idle) { - if (this._editor.getConfiguration().contribInfo.quickSuggestions === false) { + if (this._editor.getOption(EditorOption.quickSuggestions) === false) { // not enabled return; } @@ -288,7 +288,7 @@ export class SuggestModel implements IDisposable { return; } - if (this._editor.getConfiguration().contribInfo.suggest.snippetsPreventQuickSuggestions && SnippetController2.get(this._editor).isInSnippet()) { + if (this._editor.getOption(EditorOption.suggest).snippetsPreventQuickSuggestions && SnippetController2.get(this._editor).isInSnippet()) { // no quick suggestion when in snippet mode return; } @@ -308,7 +308,7 @@ export class SuggestModel implements IDisposable { const model = this._editor.getModel(); const pos = this._editor.getPosition(); // validate enabled now - const { quickSuggestions } = this._editor.getConfiguration().contribInfo; + const quickSuggestions = this._editor.getOption(EditorOption.quickSuggestions); if (quickSuggestions === false) { return; } else if (quickSuggestions === true) { @@ -388,10 +388,10 @@ export class SuggestModel implements IDisposable { this._requestToken = new CancellationTokenSource(); // kind filter and snippet sort rules - const { contribInfo } = this._editor.getConfiguration(); + const suggestOptions = this._editor.getOption(EditorOption.suggest); let itemKindFilter = new Set(); let snippetSortOrder = SnippetSortOrder.Inline; - switch (contribInfo.suggest.snippets) { + switch (suggestOptions.snippets) { case 'top': snippetSortOrder = SnippetSortOrder.Top; break; @@ -408,9 +408,9 @@ export class SuggestModel implements IDisposable { } // kind filter - for (const key in contribInfo.suggest.filteredTypes) { + for (const key in suggestOptions.filteredTypes) { const kind = completionKindFromString(key, true); - if (typeof kind !== 'undefined' && contribInfo.suggest.filteredTypes[key] === false) { + if (typeof kind !== 'undefined' && suggestOptions.filteredTypes[key] === false) { itemKindFilter.add(kind); } } @@ -450,7 +450,7 @@ export class SuggestModel implements IDisposable { characterCountDelta: ctx.column - this._context!.column }, wordDistance, - this._editor.getConfiguration().contribInfo.suggest + this._editor.getOption(EditorOption.suggest) ); // store containers so that they can be disposed later diff --git a/src/vs/editor/contrib/suggest/suggestWidget.ts b/src/vs/editor/contrib/suggest/suggestWidget.ts index 4bb095d5d41..3a9a8eec06f 100644 --- a/src/vs/editor/contrib/suggest/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/suggestWidget.ts @@ -16,7 +16,7 @@ import { List } from 'vs/base/browser/ui/list/listWidget'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { Context as SuggestContext, CompletionItem } from './suggest'; import { CompletionModel } from './completionModel'; @@ -125,9 +125,10 @@ class Renderer implements IListRenderer const configureFont = () => { const configuration = this.editor.getConfiguration(); + const options = this.editor.getOptions(); const fontFamily = configuration.fontInfo.fontFamily; - const fontSize = configuration.contribInfo.suggestFontSize || configuration.fontInfo.fontSize; - const lineHeight = configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight; + const fontSize = options.get(EditorOption.suggestFontSize) || configuration.fontInfo.fontSize; + const lineHeight = options.get(EditorOption.suggestLineHeight) || configuration.fontInfo.lineHeight; const fontWeight = configuration.fontInfo.fontWeight; const fontSizePx = `${fontSize}px`; const lineHeightPx = `${lineHeight}px`; @@ -145,7 +146,7 @@ class Renderer implements IListRenderer configureFont(); data.disposables.add(Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) - .filter(e => e.fontInfo || e.contribInfo) + .filter(e => e.fontInfo || e.hasChanged(EditorOption.suggestFontSize) || e.hasChanged(EditorOption.suggestLineHeight)) .on(configureFont, null)); return data; @@ -390,9 +391,10 @@ class SuggestionDetails { private configureFont() { const configuration = this.editor.getConfiguration(); + const options = this.editor.getOptions(); const fontFamily = configuration.fontInfo.fontFamily; - const fontSize = configuration.contribInfo.suggestFontSize || configuration.fontInfo.fontSize; - const lineHeight = configuration.contribInfo.suggestLineHeight || configuration.fontInfo.lineHeight; + const fontSize = options.get(EditorOption.suggestFontSize) || configuration.fontInfo.fontSize; + const lineHeight = options.get(EditorOption.suggestLineHeight) || configuration.fontInfo.lineHeight; const fontWeight = configuration.fontInfo.fontWeight; const fontSizePx = `${fontSize}px`; const lineHeightPx = `${lineHeight}px`; @@ -500,7 +502,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate toggleClass(this.element, 'no-icons', !this.editor.getConfiguration().contribInfo.suggest.showIcons); + const applyIconStyle = () => toggleClass(this.element, 'no-icons', !this.editor.getOption(EditorOption.suggest).showIcons); applyIconStyle(); let renderer = instantiationService.createInstance(Renderer, this, this.editor, triggerKeybindingLabel); @@ -521,7 +523,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate this.onListSelection(e))); this.toDispose.add(this.list.onFocusChange(e => this.onListFocus(e))); this.toDispose.add(this.editor.onDidChangeCursorSelection(() => this.onCursorSelectionChanged())); - this.toDispose.add(this.editor.onDidChangeConfiguration(e => e.contribInfo && applyIconStyle())); + this.toDispose.add(this.editor.onDidChangeConfiguration(e => e.hasChanged(EditorOption.suggest) && applyIconStyle())); this.suggestWidgetVisible = SuggestContext.Visible.bindTo(contextKeyService); @@ -1051,7 +1053,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate e.contribInfo && this._update())); + this._register(this._editor.onDidChangeConfiguration(e => e.hasChanged(EditorOption.tabCompletion) && this._update())); this._update(); } @@ -34,7 +35,7 @@ export class WordContextKey extends Disposable { private _update(): void { // only update this when tab completions are enabled - const enabled = this._editor.getConfiguration().contribInfo.tabCompletion === 'on'; + const enabled = this._editor.getOption(EditorOption.tabCompletion) === 'on'; if (this._enabled === enabled) { return; } diff --git a/src/vs/editor/contrib/suggest/wordDistance.ts b/src/vs/editor/contrib/suggest/wordDistance.ts index c076d21a0b3..5b7ea2cb945 100644 --- a/src/vs/editor/contrib/suggest/wordDistance.ts +++ b/src/vs/editor/contrib/suggest/wordDistance.ts @@ -10,6 +10,7 @@ import { IPosition } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import { CompletionItem, CompletionItemKind } from 'vs/editor/common/modes'; import { BracketSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/bracketSelections'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export abstract class WordDistance { @@ -19,7 +20,7 @@ export abstract class WordDistance { static create(service: IEditorWorkerService, editor: ICodeEditor): Promise { - if (!editor.getConfiguration().contribInfo.suggest.localityBonus) { + if (!editor.getOption(EditorOption.suggest).localityBonus) { return Promise.resolve(WordDistance.None); } diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index a105d7b2c29..fe76a97d60e 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -186,8 +186,8 @@ suite('Common Editor Config', () => { }); let config = new TestConfiguration({ hover: hoverOptions }); - assert.equal(config.editor.contribInfo.hover.enabled, true); + assert.equal(config.options.get(EditorOption.hover).enabled, true); config.updateOptions({ hover: { enabled: false } }); - assert.equal(config.editor.contribInfo.hover.enabled, false); + assert.equal(config.options.get(EditorOption.hover).enabled, false); }); }); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 8c02338f8da..ee94ff2b4bc 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2611,7 +2611,7 @@ declare namespace monaco.editor { /** * Max suggestions to show in suggestions. Defaults to 12. */ - maxVisibleSuggestions?: boolean; + maxVisibleSuggestions?: number; /** * Names of suggestion types to filter. */ @@ -2625,11 +2625,10 @@ declare namespace monaco.editor { multiple?: 'peek' | 'gotoAndPeek' | 'goto'; } - /** - * Configuration map for codeActionsOnSave - */ - export interface ICodeActionsOnSaveOptions { - [kind: string]: boolean; + export interface IQuickSuggestionsOptions { + other: boolean; + comments: boolean; + strings: boolean; } /** @@ -2921,11 +2920,7 @@ declare namespace monaco.editor { * Enable quick suggestions (shadow suggestions) * Defaults to true. */ - quickSuggestions?: boolean | { - other: boolean; - comments: boolean; - strings: boolean; - }; + quickSuggestions?: boolean | IQuickSuggestionsOptions; /** * Quick suggestions show delay (in ms) * Defaults to 10 (ms) @@ -3001,10 +2996,6 @@ declare namespace monaco.editor { * Syntax highlighting is copied. */ copyWithSyntaxHighlighting?: boolean; - /** - * Enable word based suggestions. Defaults to 'true' - */ - wordBasedSuggestions?: boolean; /** * The history mode for suggestions. */ @@ -3022,7 +3013,7 @@ declare namespace monaco.editor { /** * Enable tab completion. */ - tabCompletion?: boolean | 'on' | 'off' | 'onlySnippets'; + tabCompletion?: 'on' | 'off' | 'onlySnippets'; /** * Enable selection highlight. * Defaults to true. @@ -3042,10 +3033,6 @@ declare namespace monaco.editor { * Control the behavior and rendering of the code action lightbulb. */ lightbulb?: IEditorLightbulbOptions; - /** - * Code action kinds to be run on save. - */ - codeActionsOnSave?: ICodeActionsOnSaveOptions; /** * Timeout for running code actions on save. */ @@ -3262,59 +3249,6 @@ declare namespace monaco.editor { UnderlineThin = 6 } - export interface InternalEditorFindOptions { - readonly seedSearchStringFromSelection: boolean; - readonly autoFindInSelection: boolean; - readonly addExtraSpaceOnTop: boolean; - } - - export interface InternalEditorHoverOptions { - readonly enabled: boolean; - readonly delay: number; - readonly sticky: boolean; - } - - export interface InternalGoToLocationOptions { - readonly multiple: 'peek' | 'gotoAndPeek' | 'goto'; - } - - export interface InternalSuggestOptions { - readonly filterGraceful: boolean; - readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; - readonly snippetsPreventQuickSuggestions: boolean; - readonly localityBonus: boolean; - readonly shareSuggestSelections: boolean; - readonly showIcons: boolean; - readonly maxVisibleSuggestions: number; - readonly filteredTypes: Record; - } - - export interface InternalParameterHintOptions { - readonly enabled: boolean; - readonly cycle: boolean; - } - - export interface EditorContribOptions { - readonly hover: InternalEditorHoverOptions; - readonly quickSuggestions: boolean | { - other: boolean; - comments: boolean; - strings: boolean; - }; - readonly parameterHints: InternalParameterHintOptions; - readonly suggestSelection: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; - readonly suggestFontSize: number; - readonly suggestLineHeight: number; - readonly tabCompletion: 'on' | 'off' | 'onlySnippets'; - readonly suggest: InternalSuggestOptions; - readonly gotoLocation: InternalGoToLocationOptions; - readonly foldingStrategy: 'auto' | 'indentation'; - readonly showFoldingControls: 'always' | 'mouseover'; - readonly find: InternalEditorFindOptions; - readonly codeActionsOnSave: ICodeActionsOnSaveOptions; - readonly codeActionsOnSaveTimeout: number; - } - /** * Internal configuration options (transformed or computed) for the editor. */ @@ -3323,7 +3257,6 @@ declare namespace monaco.editor { readonly pixelRatio: number; readonly lineHeight: number; readonly fontInfo: FontInfo; - readonly contribInfo: EditorContribOptions; } /** @@ -3334,7 +3267,6 @@ declare namespace monaco.editor { readonly pixelRatio: boolean; readonly lineHeight: boolean; readonly fontInfo: boolean; - readonly contribInfo: boolean; } export interface IEnvironmentalOptions { @@ -3383,6 +3315,14 @@ declare namespace monaco.editor { readonly maxColumn: number; } + export interface InternalEditorHoverOptions { + readonly enabled: boolean; + readonly delay: number; + readonly sticky: boolean; + } + + export type ValidQuickSuggestionsOptions = boolean | Readonly>; + export type ValidEditorLightbulbOptions = Required; export interface InternalEditorScrollbarOptions { @@ -3399,6 +3339,34 @@ declare namespace monaco.editor { readonly verticalSliderSize: number; } + export type ValidSuggestOptions = Readonly>; + + export interface InternalSuggestOptions { + readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; + readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; + readonly shareSuggestSelections: boolean; + readonly showIcons: boolean; + readonly maxVisibleSuggestions: number; + readonly filteredTypes: Record; + } + + export interface InternalParameterHintOptions { + readonly enabled: boolean; + readonly cycle: boolean; + } + + export interface InternalEditorFindOptions { + readonly seedSearchStringFromSelection: boolean; + readonly autoFindInSelection: boolean; + readonly addExtraSpaceOnTop: boolean; + } + + export interface InternalGoToLocationOptions { + readonly multiple: 'peek' | 'gotoAndPeek' | 'goto'; + } + /** * A description for the overview ruler position. */ @@ -3542,66 +3510,78 @@ declare namespace monaco.editor { emptySelectionClipboard = 20, extraEditorClassName = 21, fastScrollSensitivity = 22, - fixedOverflowWidgets = 23, - folding = 24, - fontLigatures = 25, - formatOnPaste = 26, - formatOnType = 27, - glyphMargin = 28, - hideCursorInOverviewRuler = 29, - highlightActiveIndentGuide = 30, - inDiffEditor = 31, - lightbulb = 32, - lineDecorationsWidth = 33, - lineNumbers = 34, - lineNumbersMinChars = 35, - links = 36, - matchBrackets = 37, - minimap = 38, - mouseStyle = 39, - mouseWheelScrollSensitivity = 40, - mouseWheelZoom = 41, - multiCursorMergeOverlapping = 42, - multiCursorModifier = 43, - occurrencesHighlight = 44, - overviewRulerBorder = 45, - overviewRulerLanes = 46, - quickSuggestionsDelay = 47, - readOnly = 48, - renderControlCharacters = 49, - renderIndentGuides = 50, - renderFinalNewline = 51, - renderLineHighlight = 52, - renderWhitespace = 53, - revealHorizontalRightPadding = 54, - roundedSelection = 55, - rulers = 56, - scrollbar = 57, - scrollBeyondLastColumn = 58, - scrollBeyondLastLine = 59, - selectionClipboard = 60, - selectionHighlight = 61, - selectOnLineNumbers = 62, - showUnused = 63, - smoothScrolling = 64, - stopRenderingLineAfter = 65, - suggestOnTriggerCharacters = 66, - useTabStops = 67, - wordBasedSuggestions = 68, - wordSeparators = 69, - wordWrap = 70, - wordWrapBreakAfterCharacters = 71, - wordWrapBreakBeforeCharacters = 72, - wordWrapBreakObtrusiveCharacters = 73, - wordWrapColumn = 74, - wordWrapMinified = 75, - wrappingIndent = 76, - ariaLabel = 77, - disableMonospaceOptimizations = 78, - editorClassName = 79, - tabFocusMode = 80, - layoutInfo = 81, - wrappingInfo = 82 + find = 23, + fixedOverflowWidgets = 24, + folding = 25, + foldingStrategy = 26, + fontLigatures = 27, + formatOnPaste = 28, + formatOnType = 29, + glyphMargin = 30, + gotoLocation = 31, + hideCursorInOverviewRuler = 32, + highlightActiveIndentGuide = 33, + hover = 34, + inDiffEditor = 35, + lightbulb = 36, + lineDecorationsWidth = 37, + lineNumbers = 38, + lineNumbersMinChars = 39, + links = 40, + matchBrackets = 41, + minimap = 42, + mouseStyle = 43, + mouseWheelScrollSensitivity = 44, + mouseWheelZoom = 45, + multiCursorMergeOverlapping = 46, + multiCursorModifier = 47, + occurrencesHighlight = 48, + overviewRulerBorder = 49, + overviewRulerLanes = 50, + parameterHints = 51, + quickSuggestions = 52, + quickSuggestionsDelay = 53, + readOnly = 54, + renderControlCharacters = 55, + renderIndentGuides = 56, + renderFinalNewline = 57, + renderLineHighlight = 58, + renderWhitespace = 59, + revealHorizontalRightPadding = 60, + roundedSelection = 61, + rulers = 62, + scrollbar = 63, + scrollBeyondLastColumn = 64, + scrollBeyondLastLine = 65, + selectionClipboard = 66, + selectionHighlight = 67, + selectOnLineNumbers = 68, + showFoldingControls = 69, + showUnused = 70, + snippetSuggestions = 71, + smoothScrolling = 72, + stopRenderingLineAfter = 73, + suggestFontSize = 74, + suggestLineHeight = 75, + suggestOnTriggerCharacters = 76, + suggestSelection = 77, + tabCompletion = 78, + useTabStops = 79, + wordSeparators = 80, + wordWrap = 81, + wordWrapBreakAfterCharacters = 82, + wordWrapBreakBeforeCharacters = 83, + wordWrapBreakObtrusiveCharacters = 84, + wordWrapColumn = 85, + wordWrapMinified = 86, + wrappingIndent = 87, + ariaLabel = 88, + disableMonospaceOptimizations = 89, + editorClassName = 90, + tabFocusMode = 91, + suggest = 92, + layoutInfo = 93, + wrappingInfo = 94 } export const EditorOptions: { @@ -3628,14 +3608,18 @@ declare namespace monaco.editor { emptySelectionClipboard: IEditorOption; extraEditorClassName: IEditorOption; fastScrollSensitivity: IEditorOption; + find: IEditorOption; fixedOverflowWidgets: IEditorOption; folding: IEditorOption; + foldingStrategy: IEditorOption; fontLigatures: IEditorOption; formatOnPaste: IEditorOption; formatOnType: IEditorOption; glyphMargin: IEditorOption; + gotoLocation: IEditorOption; hideCursorInOverviewRuler: IEditorOption; highlightActiveIndentGuide: IEditorOption; + hover: IEditorOption; inDiffEditor: IEditorOption; lightbulb: IEditorOption; lineDecorationsWidth: IEditorOption; @@ -3652,6 +3636,8 @@ declare namespace monaco.editor { occurrencesHighlight: IEditorOption; overviewRulerBorder: IEditorOption; overviewRulerLanes: IEditorOption; + parameterHints: IEditorOption; + quickSuggestions: IEditorOption; quickSuggestionsDelay: IEditorOption; readOnly: IEditorOption; renderControlCharacters: IEditorOption; @@ -3668,12 +3654,17 @@ declare namespace monaco.editor { selectionClipboard: IEditorOption; selectionHighlight: IEditorOption; selectOnLineNumbers: IEditorOption; + showFoldingControls: IEditorOption; showUnused: IEditorOption; + snippetSuggestions: IEditorOption; smoothScrolling: IEditorOption; stopRenderingLineAfter: IEditorOption; + suggestFontSize: IEditorOption; + suggestLineHeight: IEditorOption; suggestOnTriggerCharacters: IEditorOption; + suggestSelection: IEditorOption; + tabCompletion: IEditorOption; useTabStops: IEditorOption; - wordBasedSuggestions: IEditorOption; wordSeparators: IEditorOption; wordWrap: IEditorOption; wordWrapBreakAfterCharacters: IEditorOption; @@ -3686,6 +3677,7 @@ declare namespace monaco.editor { disableMonospaceOptimizations: IEditorOption; editorClassName: IEditorOption; tabFocusMode: IEditorOption; + suggest: IEditorOption; layoutInfo: IEditorOption; wrappingInfo: IEditorOption; }; diff --git a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts index 1bd75108c5a..8827222e22c 100644 --- a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts @@ -10,7 +10,6 @@ import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser'; import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { trimTrailingWhitespace } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand'; -import { ICodeActionsOnSaveOptions } from 'vs/editor/common/config/editorOptions'; import { EditOperation } from 'vs/editor/common/core/editOperation'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -34,6 +33,10 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF import { ISaveParticipant, SaveReason, IResolvedTextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles'; import { ExtHostContext, ExtHostDocumentSaveParticipantShape, IExtHostContext } from '../common/extHost.protocol'; +export interface ICodeActionsOnSaveOptions { + [kind: string]: boolean; +} + export interface ISaveParticipantParticipant extends ISaveParticipant { // progressMessage: string; } diff --git a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts index 569598138e8..20f06e31a9e 100644 --- a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts +++ b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts @@ -19,6 +19,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { Snippet } from './snippetsFile'; import { SnippetCompletion } from './snippetCompletionProvider'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class TabCompletionController implements editorCommon.IEditorContribution { @@ -42,7 +43,7 @@ export class TabCompletionController implements editorCommon.IEditorContribution ) { this._hasSnippets = TabCompletionController.ContextKey.bindTo(contextKeyService); this._configListener = this._editor.onDidChangeConfiguration(e => { - if (e.contribInfo) { + if (e.hasChanged(EditorOption.tabCompletion)) { this._update(); } }); @@ -59,7 +60,7 @@ export class TabCompletionController implements editorCommon.IEditorContribution } private _update(): void { - const enabled = this._editor.getConfiguration().contribInfo.tabCompletion === 'onlySnippets'; + const enabled = this._editor.getOption(EditorOption.tabCompletion) === 'onlySnippets'; if (this._enabled !== enabled) { this._enabled = enabled; if (!this._enabled) { From 9e3942707e2743f313119122ec2fe71c8e6aa430 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 11:24:36 +0200 Subject: [PATCH 012/109] Add test for eventing --- .../test/common/config/commonEditorConfig.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index fe76a97d60e..f2ab0bbbd41 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorHoverOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOption, IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; @@ -190,4 +190,15 @@ suite('Common Editor Config', () => { config.updateOptions({ hover: { enabled: false } }); assert.equal(config.options.get(EditorOption.hover).enabled, false); }); + + test('does not emit event when nothing changes', () => { + const config = new TestConfiguration({ glyphMargin: true, roundedSelection: false }); + let event: IConfigurationChangedEvent | null = null; + config.onDidChange(e => event = e); + assert.equal(config.options.get(EditorOption.glyphMargin), true); + + config.updateOptions({ glyphMargin: true }); + config.updateOptions({ roundedSelection: false }); + assert.equal(event, null); + }); }); From dd0fe9e08a1fba0936ac824496e4ea84d6870d51 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 12:17:55 +0200 Subject: [PATCH 013/109] Migrate computed editor options --- .../editor/browser/controller/mouseTarget.ts | 2 +- .../browser/controller/textAreaHandler.ts | 4 +- src/vs/editor/browser/view/viewOverlays.ts | 6 +- .../contentWidgets/contentWidgets.ts | 8 +- .../currentLineHighlight.ts | 4 +- .../currentLineMarginHighlight.ts | 4 +- .../viewParts/decorations/decorations.ts | 9 +- .../viewParts/glyphMargin/glyphMargin.ts | 4 +- .../viewParts/indentGuides/indentGuides.ts | 4 +- .../viewParts/lineNumbers/lineNumbers.ts | 3 +- .../browser/viewParts/lines/viewLine.ts | 2 +- .../browser/viewParts/lines/viewLines.ts | 4 +- .../browser/viewParts/minimap/minimap.ts | 4 +- .../overviewRuler/decorationsOverviewRuler.ts | 4 +- .../viewParts/overviewRuler/overviewRuler.ts | 17 ++- .../viewParts/selections/selections.ts | 4 +- .../viewParts/viewCursors/viewCursor.ts | 4 +- .../browser/viewParts/viewZones/viewZones.ts | 6 +- .../editor/browser/widget/codeEditorWidget.ts | 2 +- .../editor/browser/widget/diffEditorWidget.ts | 4 +- .../editor/browser/widget/inlineDiffMargin.ts | 2 +- src/vs/editor/common/config/editorOptions.ts | 93 ++++++------ .../editor/common/controller/cursorCommon.ts | 7 +- .../common/standalone/standaloneEnums.ts | 116 +++++++-------- src/vs/editor/common/view/viewEvents.ts | 4 - src/vs/editor/common/viewLayout/viewLayout.ts | 13 +- .../contrib/codeAction/lightBulbWidget.ts | 2 +- .../editor/contrib/codelens/codelensWidget.ts | 5 +- .../contrib/gotoError/gotoErrorWidget.ts | 3 +- src/vs/editor/contrib/hover/hoverWidgets.ts | 26 ++-- .../editor/contrib/hover/modesContentHover.ts | 2 +- .../contrib/referenceSearch/peekViewWidget.ts | 3 +- .../editor/contrib/rename/renameInputField.ts | 3 +- .../editor/contrib/zoneWidget/zoneWidget.ts | 8 +- src/vs/monaco.d.ts | 133 +++++++++--------- .../comments/browser/commentThreadWidget.ts | 7 +- .../contrib/debug/browser/exceptionWidget.ts | 3 +- .../preferences/browser/preferencesWidgets.ts | 5 +- .../contrib/scm/browser/dirtydiffDecorator.ts | 4 +- .../walkThrough/browser/walkThroughPart.ts | 6 +- 40 files changed, 285 insertions(+), 259 deletions(-) diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index 1db7f2849a4..4ec958948b2 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -242,7 +242,7 @@ export class HitTestContext { const options = context.configuration.options; this.layoutInfo = options.get(EditorOption.layoutInfo); this.viewDomNode = viewHelper.viewDomNode; - this.lineHeight = context.configuration.editor.lineHeight; + this.lineHeight = options.get(EditorOption.lineHeight); this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this.lastViewCursorsRenderData = lastViewCursorsRenderData; this._context = context; diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index 2cde2415361..18902d71eb9 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -130,7 +130,7 @@ export class TextAreaHandler extends ViewPart { this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; this._fontInfo = conf.fontInfo; - this._lineHeight = conf.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); @@ -383,7 +383,7 @@ export class TextAreaHandler extends ViewPart { this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; this._fontInfo = conf.fontInfo; - this._lineHeight = conf.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); this.textArea.setAttribute('aria-label', options.get(EditorOption.ariaLabel)); diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index 1145334be17..43a6a96f830 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -149,7 +149,7 @@ export class ViewOverlayLine implements IVisibleLine { constructor(configuration: IConfiguration, dynamicOverlays: DynamicViewOverlay[]) { this._configuration = configuration; - this._lineHeight = this._configuration.editor.lineHeight; + this._lineHeight = this._configuration.options.get(EditorOption.lineHeight); this._dynamicOverlays = dynamicOverlays; this._domNode = null; @@ -173,9 +173,7 @@ export class ViewOverlayLine implements IVisibleLine { // Nothing } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): void { - if (e.lineHeight) { - this._lineHeight = this._configuration.editor.lineHeight; - } + this._lineHeight = this._configuration.options.get(EditorOption.lineHeight); } public renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: IStringBuilder): boolean { diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index 721a7ff2acb..3a962f22ea2 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -215,7 +215,7 @@ class Widget { this._fixedOverflowWidgets = options.get(EditorOption.fixedOverflowWidgets); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._position = null; this._range = null; @@ -235,11 +235,9 @@ class Widget { } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): void { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } + const options = this._context.configuration.options; + this._lineHeight = options.get(EditorOption.lineHeight); if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; diff --git a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts index 448aff03d52..820b7c30e29 100644 --- a/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineHighlight/currentLineHighlight.ts @@ -29,7 +29,7 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); this._contentWidth = layoutInfo.contentWidth; @@ -52,7 +52,7 @@ export class CurrentLineHighlightOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); this._contentWidth = layoutInfo.contentWidth; return true; diff --git a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts index 17a473d86b4..f07b024aca1 100644 --- a/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts +++ b/src/vs/editor/browser/viewParts/currentLineMarginHighlight/currentLineMarginHighlight.ts @@ -28,7 +28,7 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); this._contentLeft = layoutInfo.contentLeft; @@ -49,7 +49,7 @@ export class CurrentLineMarginHighlightOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._renderLineHighlight = options.get(EditorOption.renderLineHighlight); this._contentLeft = layoutInfo.contentLeft; return true; diff --git a/src/vs/editor/browser/viewParts/decorations/decorations.ts b/src/vs/editor/browser/viewParts/decorations/decorations.ts index 0716cc3b4e1..2e0627b2b94 100644 --- a/src/vs/editor/browser/viewParts/decorations/decorations.ts +++ b/src/vs/editor/browser/viewParts/decorations/decorations.ts @@ -10,6 +10,7 @@ import { HorizontalRange, RenderingContext } from 'vs/editor/common/view/renderi import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; import { ViewModelDecoration } from 'vs/editor/common/viewModel/viewModel'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export class DecorationsOverlay extends DynamicViewOverlay { @@ -21,7 +22,8 @@ export class DecorationsOverlay extends DynamicViewOverlay { constructor(context: ViewContext) { super(); this._context = context; - this._lineHeight = this._context.configuration.editor.lineHeight; + const options = this._context.configuration.options; + this._lineHeight = options.get(EditorOption.lineHeight); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this._renderResult = null; @@ -37,9 +39,8 @@ export class DecorationsOverlay extends DynamicViewOverlay { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._lineHeight = this._context.configuration.editor.lineHeight; - } + const options = this._context.configuration.options; + this._lineHeight = options.get(EditorOption.lineHeight); if (e.fontInfo) { this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; } diff --git a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts index 7bc4e31bd2e..494b7d7ca23 100644 --- a/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts +++ b/src/vs/editor/browser/viewParts/glyphMargin/glyphMargin.ts @@ -90,7 +90,7 @@ export class GlyphMarginOverlay extends DedupOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._glyphMargin = options.get(EditorOption.glyphMargin); this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; @@ -110,7 +110,7 @@ export class GlyphMarginOverlay extends DedupOverlay { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._glyphMargin = options.get(EditorOption.glyphMargin); this._glyphMarginLeft = layoutInfo.glyphMarginLeft; this._glyphMarginWidth = layoutInfo.glyphMarginWidth; diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index 705700fc6d6..762c8dff713 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -33,7 +33,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; this._enabled = options.get(EditorOption.renderIndentGuides); this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); @@ -56,7 +56,7 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; this._enabled = options.get(EditorOption.renderIndentGuides); this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); diff --git a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts index 1d5e6508062..ccf43d5b694 100644 --- a/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts +++ b/src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts @@ -42,8 +42,7 @@ export class LineNumbersOverlay extends DynamicViewOverlay { private _readConfig(): void { const options = this._context.configuration.options; - const config = this._context.configuration.editor; - this._lineHeight = config.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); const lineNumbers = options.get(EditorOption.lineNumbers); this._renderLineNumbers = lineNumbers.renderType; this._renderCustomLineNumbers = lineNumbers.renderFn; diff --git a/src/vs/editor/browser/viewParts/lines/viewLine.ts b/src/vs/editor/browser/viewParts/lines/viewLine.ts index 25e861bf9c6..f337db9c1f8 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLine.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLine.ts @@ -90,7 +90,7 @@ export class ViewLineOptions { && !options.get(EditorOption.disableMonospaceOptimizations) ); this.canUseHalfwidthRightwardsArrow = config.editor.fontInfo.canUseHalfwidthRightwardsArrow; - this.lineHeight = config.editor.lineHeight; + this.lineHeight = options.get(EditorOption.lineHeight); this.stopRenderingLineAfter = options.get(EditorOption.stopRenderingLineAfter); this.fontLigatures = options.get(EditorOption.fontLigatures); } diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index f8d9fb45839..092cb3c9a70 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -96,7 +96,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); - this._lineHeight = conf.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; this._isViewportWrapping = wrappingInfo.isViewportWrapping; this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); @@ -149,7 +149,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); - this._lineHeight = conf.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; this._isViewportWrapping = wrappingInfo.isViewportWrapping; this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index 27312e54b80..2550266af76 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -108,7 +108,7 @@ class MinimapOptions { constructor(configuration: IConfiguration) { const options = configuration.options; - const pixelRatio = configuration.editor.pixelRatio; + const pixelRatio = options.get(EditorOption.pixelRatio); const layoutInfo = options.get(EditorOption.layoutInfo); const fontInfo = configuration.editor.fontInfo; @@ -118,7 +118,7 @@ class MinimapOptions { this.showSlider = minimapOpts.showSlider; this.pixelRatio = pixelRatio; this.typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; - this.lineHeight = configuration.editor.lineHeight; + this.lineHeight = options.get(EditorOption.lineHeight); this.minimapLeft = layoutInfo.minimapLeft; this.minimapWidth = layoutInfo.minimapWidth; this.minimapHeight = layoutInfo.height; diff --git a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts index 7658dfbf33c..a4e988745cb 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/decorationsOverviewRuler.ts @@ -44,8 +44,8 @@ class Settings { constructor(config: IConfiguration, theme: ITheme) { const options = config.options; - this.lineHeight = config.editor.lineHeight; - this.pixelRatio = config.editor.pixelRatio; + this.lineHeight = options.get(EditorOption.lineHeight); + this.pixelRatio = options.get(EditorOption.pixelRatio); this.overviewRulerLanes = options.get(EditorOption.overviewRulerLanes); this.renderBorder = options.get(EditorOption.overviewRulerBorder); diff --git a/src/vs/editor/browser/viewParts/overviewRuler/overviewRuler.ts b/src/vs/editor/browser/viewParts/overviewRuler/overviewRuler.ts index 4b164f01c6b..7b9ef090d2a 100644 --- a/src/vs/editor/browser/viewParts/overviewRuler/overviewRuler.ts +++ b/src/vs/editor/browser/viewParts/overviewRuler/overviewRuler.ts @@ -5,7 +5,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode'; import { IOverviewRuler } from 'vs/editor/browser/editorBrowser'; -import { OverviewRulerPosition } from 'vs/editor/common/config/editorOptions'; +import { OverviewRulerPosition, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ColorZone, OverviewRulerZone, OverviewZoneManager } from 'vs/editor/common/view/overviewZoneManager'; import { ViewContext } from 'vs/editor/common/view/viewContext'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; @@ -20,6 +20,7 @@ export class OverviewRuler extends ViewEventHandler implements IOverviewRuler { constructor(context: ViewContext, cssClassName: string) { super(); this._context = context; + const options = this._context.configuration.options; this._domNode = createFastDomNode(document.createElement('canvas')); this._domNode.setClassName(cssClassName); @@ -30,9 +31,9 @@ export class OverviewRuler extends ViewEventHandler implements IOverviewRuler { this._zoneManager.setDOMWidth(0); this._zoneManager.setDOMHeight(0); this._zoneManager.setOuterHeight(this._context.viewLayout.getScrollHeight()); - this._zoneManager.setLineHeight(this._context.configuration.editor.lineHeight); + this._zoneManager.setLineHeight(options.get(EditorOption.lineHeight)); - this._zoneManager.setPixelRatio(this._context.configuration.editor.pixelRatio); + this._zoneManager.setPixelRatio(options.get(EditorOption.pixelRatio)); this._context.addEventHandler(this); } @@ -45,13 +46,15 @@ export class OverviewRuler extends ViewEventHandler implements IOverviewRuler { // ---- begin view event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - if (e.lineHeight) { - this._zoneManager.setLineHeight(this._context.configuration.editor.lineHeight); + const options = this._context.configuration.options; + + if (e.hasChanged(EditorOption.lineHeight)) { + this._zoneManager.setLineHeight(options.get(EditorOption.lineHeight)); this._render(); } - if (e.pixelRatio) { - this._zoneManager.setPixelRatio(this._context.configuration.editor.pixelRatio); + if (e.hasChanged(EditorOption.pixelRatio)) { + this._zoneManager.setPixelRatio(options.get(EditorOption.pixelRatio)); this._domNode.setWidth(this._zoneManager.getDOMWidth()); this._domNode.setHeight(this._zoneManager.getDOMHeight()); this._domNode.domNode.width = this._zoneManager.getCanvasWidth(); diff --git a/src/vs/editor/browser/viewParts/selections/selections.ts b/src/vs/editor/browser/viewParts/selections/selections.ts index 1c1cd7fdd48..b960faf5751 100644 --- a/src/vs/editor/browser/viewParts/selections/selections.ts +++ b/src/vs/editor/browser/viewParts/selections/selections.ts @@ -85,7 +85,7 @@ export class SelectionsOverlay extends DynamicViewOverlay { super(); this._context = context; const options = this._context.configuration.options; - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._roundedSelection = options.get(EditorOption.roundedSelection); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this._selections = []; @@ -103,7 +103,7 @@ export class SelectionsOverlay extends DynamicViewOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._roundedSelection = options.get(EditorOption.roundedSelection); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; return true; diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts index 491943b8fb6..be49b426a8d 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts @@ -54,7 +54,7 @@ export class ViewCursor { const options = this._context.configuration.options; this._cursorStyle = options.get(EditorOption.cursorStyle); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); @@ -101,7 +101,7 @@ export class ViewCursor { const options = this._context.configuration.options; this._cursorStyle = options.get(EditorOption.cursorStyle); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); Configuration.applyFontInfo(this._domNode, this._context.configuration.editor.fontInfo); diff --git a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts index 8bac486f4bc..6d7e1473089 100644 --- a/src/vs/editor/browser/viewParts/viewZones/viewZones.ts +++ b/src/vs/editor/browser/viewParts/viewZones/viewZones.ts @@ -45,7 +45,7 @@ export class ViewZones extends ViewPart { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; @@ -92,11 +92,11 @@ export class ViewZones extends ViewPart { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._lineHeight = this._context.configuration.editor.lineHeight; + this._lineHeight = options.get(EditorOption.lineHeight); this._contentWidth = layoutInfo.contentWidth; this._contentLeft = layoutInfo.contentLeft; - if (e.lineHeight) { + if (e.hasChanged(EditorOption.lineHeight)) { this._recomputeWhitespacesProps(); } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index bd776263369..730a5c027f8 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1289,7 +1289,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE return { top: top, left: left, - height: this._configuration.editor.lineHeight + height: options.get(EditorOption.lineHeight) }; } diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index fd704dbd5d2..93f4e544425 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -1998,7 +1998,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { const layoutInfo = this.modifiedEditorOptions.get(EditorOption.layoutInfo); const lineDecorationsWidth = layoutInfo.decorationsWidth; - let lineHeight = this.modifiedEditorConfiguration.lineHeight; + let lineHeight = this.modifiedEditorOptions.get(EditorOption.lineHeight); const typicalHalfwidthCharacterWidth = this.modifiedEditorConfiguration.fontInfo.typicalHalfwidthCharacterWidth; let maxCharsPerLine = 0; const originalContent: string[] = []; @@ -2054,7 +2054,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { sb.appendASCIIString(' char-delete'); } sb.appendASCIIString('" style="top:'); - sb.appendASCIIString(String(count * config.lineHeight)); + sb.appendASCIIString(String(count * options.get(EditorOption.lineHeight))); sb.appendASCIIString('px;width:1000000px;">'); const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, originalModel.mightContainNonBasicASCII()); diff --git a/src/vs/editor/browser/widget/inlineDiffMargin.ts b/src/vs/editor/browser/widget/inlineDiffMargin.ts index cec830e304c..90bb8d9165a 100644 --- a/src/vs/editor/browser/widget/inlineDiffMargin.ts +++ b/src/vs/editor/browser/widget/inlineDiffMargin.ts @@ -59,7 +59,7 @@ export class InlineDiffMargin extends Disposable { this._diffActions = document.createElement('div'); this._diffActions.className = 'lightbulb-glyph'; this._diffActions.style.position = 'absolute'; - const lineHeight = editor.getConfiguration().lineHeight; + const lineHeight = editor.getOption(EditorOption.lineHeight); const lineFeed = editor.getModel()!.getEOL(); this._diffActions.style.right = '0px'; this._diffActions.style.visibility = 'hidden'; diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 873bb5575e7..c88fa2db71c 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -717,11 +717,17 @@ export interface IEditorOptions { * Controls fading out of unused variables. */ showUnused?: boolean; +} +export type IExtendedEditorOptions = IEditorOptions & { /** * Do not use, this is a computed option. */ editorClassName?: undefined; + /** + * Do not use, this is a computed option. + */ + pixelRatio?: undefined; /** * Do not use, this is a computed option. */ @@ -734,7 +740,7 @@ export interface IEditorOptions { * Do not use, this is a computed option. */ wrappingInfo?: undefined; -} +}; /** * Configuration options for the diff editor. @@ -900,9 +906,6 @@ function _cursorStyleFromString(cursorStyle: 'line' | 'block' | 'underline' | 'l export class InternalEditorOptions { readonly _internalEditorOptionsBrand: void; - readonly pixelRatio: number; - readonly lineHeight: number; - // ---- grouped options readonly fontInfo: FontInfo; @@ -910,12 +913,8 @@ export class InternalEditorOptions { * @internal */ constructor(source: { - pixelRatio: number; - lineHeight: number; fontInfo: FontInfo; }) { - this.pixelRatio = source.pixelRatio; - this.lineHeight = source.lineHeight | 0; this.fontInfo = source.fontInfo; } @@ -924,9 +923,7 @@ export class InternalEditorOptions { */ public equals(other: InternalEditorOptions): boolean { return ( - this.pixelRatio === other.pixelRatio - && this.lineHeight === other.lineHeight - && this.fontInfo.equals(other.fontInfo) + this.fontInfo.equals(other.fontInfo) ); } @@ -941,8 +938,6 @@ export class InternalEditorOptions { } return changeEvent.get(id); }, - pixelRatio: (this.pixelRatio !== newOpts.pixelRatio), - lineHeight: (this.lineHeight !== newOpts.lineHeight), fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)), }; } @@ -953,8 +948,6 @@ export class InternalEditorOptions { */ export interface IConfigurationChangedEvent { hasChanged(id: EditorOption): boolean; - readonly pixelRatio: boolean; - readonly lineHeight: boolean; readonly fontInfo: boolean; } @@ -1067,8 +1060,6 @@ export class InternalEditorOptionsFactory { public static createInternalEditorOptions(env: IEnvironmentalOptions) { return new InternalEditorOptions({ - pixelRatio: env.pixelRatio, - lineHeight: env.fontInfo.lineHeight, fontInfo: env.fontInfo, }); } @@ -1139,7 +1130,7 @@ export const EDITOR_MODEL_DEFAULTS = { /** * @internal */ -export interface IRawEditorOptionsBag extends IEditorOptions { +export interface IRawEditorOptionsBag extends IExtendedEditorOptions { [key: string]: any; } @@ -1210,28 +1201,28 @@ export class ChangedEditorOptions { /** * @internal */ -type PossibleKeyName0 = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; +type PossibleKeyName0 = { [K in keyof IExtendedEditorOptions]: IExtendedEditorOptions[K] extends V | undefined ? K : never }[keyof IExtendedEditorOptions]; /** * @internal */ type PossibleKeyName = NonNullable>; -export interface IEditorOption, T3 = T2> { +export interface IEditorOption, T3 = T2> { readonly id: K1; readonly name: K2; readonly defaultValue: T2; /** * @internal */ - read(options: IRawEditorOptionsBag): IEditorOptions[K2] | undefined; + read(options: IRawEditorOptionsBag): IExtendedEditorOptions[K2] | undefined; /** * @internal */ - mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined; + mix(a: IExtendedEditorOptions[K2] | undefined, b: IExtendedEditorOptions[K2] | undefined): IExtendedEditorOptions[K2] | undefined; /** * @internal */ - validate(input: IEditorOptions[K2] | undefined): T2; + validate(input: IExtendedEditorOptions[K2] | undefined): T2; /** * @internal */ @@ -1245,7 +1236,7 @@ export interface IEditorOption implements IEditorOption { +abstract class BaseEditorOption implements IEditorOption { public readonly id: K1; public readonly name: K2; @@ -1259,10 +1250,10 @@ abstract class BaseEditorOptionthis.name]; } - public mix(a: IEditorOptions[K2] | undefined, b: IEditorOptions[K2] | undefined): IEditorOptions[K2] | undefined { + public mix(a: IExtendedEditorOptions[K2] | undefined, b: IExtendedEditorOptions[K2] | undefined): IExtendedEditorOptions[K2] | undefined { switch (typeof b) { case 'bigint': return b; case 'boolean': return b; @@ -1274,7 +1265,7 @@ abstract class BaseEditorOption, this.allowedValues = allowedValues; this.convert = convert; } - public validate(input: IEditorOptions[K2] | undefined): T1 { + public validate(input: IExtendedEditorOptions[K2] | undefined): T1 { return _stringSet(input, this.defaultValue, this.allowedValues); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T1): T2 { @@ -1345,14 +1336,14 @@ class EditorEnumOption, } } -class EditorPassthroughOption extends BaseEditorOption { - public validate(input: IEditorOptions[K2] | undefined): IEditorOptions[K2] { +class EditorPassthroughOption extends BaseEditorOption { + public validate(input: IExtendedEditorOptions[K2] | undefined): IExtendedEditorOptions[K2] { if (typeof input === 'undefined') { return this.defaultValue; } return input; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: IEditorOptions[K2]): IEditorOptions[K2] { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: IExtendedEditorOptions[K2]): IExtendedEditorOptions[K2] { return value; } } @@ -1646,6 +1637,32 @@ class EditorTabFocusMode> extends BaseEditorOption { + public validate(input: undefined): undefined { + return undefined; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): number { + return env.pixelRatio; + } +} + +//#endregion + +//#region lineHeight + +class EditorLineHeight> extends BaseEditorOption { + public validate(input: number | undefined): number { + return this.defaultValue; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + return env.fontInfo.lineHeight; + } +} + +//#endregion + //#region emptySelectionClipboard class EditorEmptySelectionClipboard> extends EditorBooleanOption { @@ -2338,7 +2355,7 @@ function _multiCursorModifierFromString(multiCursorModifier: 'ctrlCmd' | 'alt'): */ export const editorOptionsRegistry: IEditorOption[] = []; -function registerEditorOption(option: IEditorOption): IEditorOption { +function registerEditorOption(option: IEditorOption): IEditorOption { editorOptionsRegistry[option.id] = option; return option; } @@ -2382,6 +2399,7 @@ export const enum EditorOption { inDiffEditor, lightbulb, lineDecorationsWidth, + lineHeight, lineNumbers, lineNumbersMinChars, links, @@ -2436,6 +2454,7 @@ export const enum EditorOption { ariaLabel, disableMonospaceOptimizations, editorClassName, + pixelRatio, tabFocusMode, suggest, layoutInfo, @@ -2494,6 +2513,7 @@ export const EditorOptions = { enabled: true })), lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineHeight: registerEditorOption(new EditorLineHeight(EditorOption.lineHeight, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight)), lineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), links: registerEditorOption(new EditorBooleanOption(EditorOption.links, 'links', true)), @@ -2574,6 +2594,7 @@ export const EditorOptions = { ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOption.accessibilitySupport])), disableMonospaceOptimizations: registerEditorOption(new EditorDisableMonospaceOptimizations(EditorOption.disableMonospaceOptimizations, 'disableMonospaceOptimizations', false, [EditorOption.fontLigatures])), editorClassName: registerEditorOption(new EditorClassName(EditorOption.editorClassName, 'editorClassName', undefined, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])), + pixelRatio: registerEditorOption(new EditorPixelRatio(EditorOption.pixelRatio, 'pixelRatio', undefined)), tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), suggest: registerEditorOption(new EditorSuggest(EditorOption.suggest, 'suggest', { filterGraceful: true, @@ -2588,14 +2609,6 @@ export const EditorOptions = { wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, 'wrappingInfo', undefined, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), }; -// const tmp: { [key: string]: IEditorOption; } = EditorOptions; -// for (const key of Object.keys(tmp)) { -// const option = tmp[key]; -// if (key !== option.name) { -// throw new Error(`mismatch - ${key} - ${option.name}`); -// } -// } - export type EditorOptionsType = typeof EditorOptions; export type FindEditorOptionsKeyById = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType]; export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index 3016ee9e803..dd85df4cc43 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -121,7 +121,7 @@ export class CursorConfiguration { || e.hasChanged(EditorOption.autoClosingOvertype) || e.hasChanged(EditorOption.autoSurround) || e.hasChanged(EditorOption.useTabStops) - || e.lineHeight + || e.hasChanged(EditorOption.lineHeight) || e.hasChanged(EditorOption.readOnly) ); } @@ -133,7 +133,6 @@ export class CursorConfiguration { ) { this._languageIdentifier = languageIdentifier; - const c = configuration.editor; const options = configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); @@ -141,8 +140,8 @@ export class CursorConfiguration { this.tabSize = modelOptions.tabSize; this.indentSize = modelOptions.indentSize; this.insertSpaces = modelOptions.insertSpaces; - this.pageSize = Math.max(1, Math.floor(layoutInfo.height / c.fontInfo.lineHeight) - 2); - this.lineHeight = c.lineHeight; + this.lineHeight = options.get(EditorOption.lineHeight); + this.pageSize = Math.max(1, Math.floor(layoutInfo.height / this.lineHeight) - 2); this.useTabStops = options.get(EditorOption.useTabStops); this.wordSeparators = options.get(EditorOption.wordSeparators); this.emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 6410d3b438b..268d0bfada7 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -478,63 +478,65 @@ export enum EditorOption { inDiffEditor = 35, lightbulb = 36, lineDecorationsWidth = 37, - lineNumbers = 38, - lineNumbersMinChars = 39, - links = 40, - matchBrackets = 41, - minimap = 42, - mouseStyle = 43, - mouseWheelScrollSensitivity = 44, - mouseWheelZoom = 45, - multiCursorMergeOverlapping = 46, - multiCursorModifier = 47, - occurrencesHighlight = 48, - overviewRulerBorder = 49, - overviewRulerLanes = 50, - parameterHints = 51, - quickSuggestions = 52, - quickSuggestionsDelay = 53, - readOnly = 54, - renderControlCharacters = 55, - renderIndentGuides = 56, - renderFinalNewline = 57, - renderLineHighlight = 58, - renderWhitespace = 59, - revealHorizontalRightPadding = 60, - roundedSelection = 61, - rulers = 62, - scrollbar = 63, - scrollBeyondLastColumn = 64, - scrollBeyondLastLine = 65, - selectionClipboard = 66, - selectionHighlight = 67, - selectOnLineNumbers = 68, - showFoldingControls = 69, - showUnused = 70, - snippetSuggestions = 71, - smoothScrolling = 72, - stopRenderingLineAfter = 73, - suggestFontSize = 74, - suggestLineHeight = 75, - suggestOnTriggerCharacters = 76, - suggestSelection = 77, - tabCompletion = 78, - useTabStops = 79, - wordSeparators = 80, - wordWrap = 81, - wordWrapBreakAfterCharacters = 82, - wordWrapBreakBeforeCharacters = 83, - wordWrapBreakObtrusiveCharacters = 84, - wordWrapColumn = 85, - wordWrapMinified = 86, - wrappingIndent = 87, - ariaLabel = 88, - disableMonospaceOptimizations = 89, - editorClassName = 90, - tabFocusMode = 91, - suggest = 92, - layoutInfo = 93, - wrappingInfo = 94 + lineHeight = 38, + lineNumbers = 39, + lineNumbersMinChars = 40, + links = 41, + matchBrackets = 42, + minimap = 43, + mouseStyle = 44, + mouseWheelScrollSensitivity = 45, + mouseWheelZoom = 46, + multiCursorMergeOverlapping = 47, + multiCursorModifier = 48, + occurrencesHighlight = 49, + overviewRulerBorder = 50, + overviewRulerLanes = 51, + parameterHints = 52, + quickSuggestions = 53, + quickSuggestionsDelay = 54, + readOnly = 55, + renderControlCharacters = 56, + renderIndentGuides = 57, + renderFinalNewline = 58, + renderLineHighlight = 59, + renderWhitespace = 60, + revealHorizontalRightPadding = 61, + roundedSelection = 62, + rulers = 63, + scrollbar = 64, + scrollBeyondLastColumn = 65, + scrollBeyondLastLine = 66, + selectionClipboard = 67, + selectionHighlight = 68, + selectOnLineNumbers = 69, + showFoldingControls = 70, + showUnused = 71, + snippetSuggestions = 72, + smoothScrolling = 73, + stopRenderingLineAfter = 74, + suggestFontSize = 75, + suggestLineHeight = 76, + suggestOnTriggerCharacters = 77, + suggestSelection = 78, + tabCompletion = 79, + useTabStops = 80, + wordSeparators = 81, + wordWrap = 82, + wordWrapBreakAfterCharacters = 83, + wordWrapBreakBeforeCharacters = 84, + wordWrapBreakObtrusiveCharacters = 85, + wordWrapColumn = 86, + wordWrapMinified = 87, + wrappingIndent = 88, + ariaLabel = 89, + disableMonospaceOptimizations = 90, + editorClassName = 91, + pixelRatio = 92, + tabFocusMode = 93, + suggest = 94, + layoutInfo = 95, + wrappingInfo = 96 } /** diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index e113f65c072..05d9e6b0db8 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -35,14 +35,10 @@ export class ViewConfigurationChangedEvent { public readonly type = ViewEventType.ViewConfigurationChanged; public readonly _source: IConfigurationChangedEvent; - public readonly pixelRatio: boolean; - public readonly lineHeight: boolean; public readonly fontInfo: boolean; constructor(source: IConfigurationChangedEvent) { this._source = source; - this.pixelRatio = source.pixelRatio; - this.lineHeight = source.lineHeight; this.fontInfo = source.fontInfo; } diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 952406baa27..2a4f9355ac8 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -30,7 +30,7 @@ export class ViewLayout extends Disposable implements IViewLayout { const options = this._configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); - this._linesLayout = new LinesLayout(lineCount, this._configuration.editor.lineHeight); + this._linesLayout = new LinesLayout(lineCount, options.get(EditorOption.lineHeight)); this.scrollable = this._register(new Scrollable(0, scheduleAtNextAnimationFrame)); this._configureSmoothScrollDuration(); @@ -59,11 +59,11 @@ export class ViewLayout extends Disposable implements IViewLayout { // ---- begin view event handlers public onConfigurationChanged(e: IConfigurationChangedEvent): void { - if (e.lineHeight) { - this._linesLayout.setLineHeight(this._configuration.editor.lineHeight); + const options = this._configuration.options; + if (e.hasChanged(EditorOption.lineHeight)) { + this._linesLayout.setLineHeight(options.get(EditorOption.lineHeight)); } if (e.hasChanged(EditorOption.layoutInfo)) { - const options = this._configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); this.scrollable.setScrollDimensions({ width: layoutInfo.contentWidth, @@ -102,11 +102,12 @@ export class ViewLayout extends Disposable implements IViewLayout { } private _getTotalHeight(): number { + const options = this._configuration.options; const scrollDimensions = this.scrollable.getScrollDimensions(); let result = this._linesLayout.getLinesTotalHeight(); - if (this._configuration.options.get(EditorOption.scrollBeyondLastLine)) { - result += scrollDimensions.height - this._configuration.editor.lineHeight; + if (options.get(EditorOption.scrollBeyondLastLine)) { + result += scrollDimensions.height - options.get(EditorOption.lineHeight); } else { result += this._getHorizontalScrollbarHeight(scrollDimensions); } diff --git a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts index 3987b9a5eee..f4a3bbf228a 100644 --- a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts +++ b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts @@ -79,7 +79,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget { // a bit of extra work to make sure the menu // doesn't cover the line-text const { top, height } = dom.getDomNodePagePosition(this._domNode); - const { lineHeight } = this._editor.getConfiguration(); + const lineHeight = this._editor.getOption(EditorOption.lineHeight); let pad = Math.floor(lineHeight / 3); if (this._state.widgetPosition.position !== null && this._state.widgetPosition.position.lineNumber < this._state.editorPosition.lineNumber) { diff --git a/src/vs/editor/contrib/codelens/codelensWidget.ts b/src/vs/editor/contrib/codelens/codelensWidget.ts index 5ae20b27edb..516f971af2b 100644 --- a/src/vs/editor/contrib/codelens/codelensWidget.ts +++ b/src/vs/editor/contrib/codelens/codelensWidget.ts @@ -16,6 +16,7 @@ import { editorCodeLensForeground } from 'vs/editor/common/view/editorColorRegis import { CodeLensItem } from 'vs/editor/contrib/codelens/codelens'; import { editorActiveLinkForeground } from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class CodeLensViewZone implements editorBrowser.IViewZone { @@ -80,7 +81,9 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget { } updateHeight(): void { - const { fontInfo, lineHeight } = this._editor.getConfiguration(); + const options = this._editor.getOptions(); + const { fontInfo } = this._editor.getConfiguration(); + const lineHeight = options.get(EditorOption.lineHeight); this._domNode.style.height = `${Math.round(lineHeight * 1.1)}px`; this._domNode.style.lineHeight = `${lineHeight}px`; this._domNode.style.fontSize = `${Math.round(fontInfo.fontSize * 0.9)}px`; diff --git a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts index 9da6b13042f..dd7414923a7 100644 --- a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts +++ b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts @@ -26,6 +26,7 @@ import { IAction } from 'vs/base/common/actions'; import { IActionBarOptions, ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar'; import { peekViewTitleForeground, peekViewTitleInfoForeground } from 'vs/editor/contrib/referenceSearch/referencesWidget'; import { SeverityIcon } from 'vs/platform/severityIcon/common/severityIcon'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; class MessageWidget { @@ -122,7 +123,7 @@ class MessageWidget { this._editor.applyFontInfo(this._relatedBlock); if (isNonEmptyArray(relatedInformation)) { const relatedInformationNode = this._relatedBlock.appendChild(document.createElement('div')); - relatedInformationNode.style.paddingTop = `${Math.floor(this._editor.getConfiguration().lineHeight * 0.66)}px`; + relatedInformationNode.style.paddingTop = `${Math.floor(this._editor.getOption(EditorOption.lineHeight) * 0.66)}px`; this._lines += 1; for (const related of relatedInformation) { diff --git a/src/vs/editor/contrib/hover/hoverWidgets.ts b/src/vs/editor/contrib/hover/hoverWidgets.ts index 13dff650038..96d28a55099 100644 --- a/src/vs/editor/contrib/hover/hoverWidgets.ts +++ b/src/vs/editor/contrib/hover/hoverWidgets.ts @@ -8,15 +8,15 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { Widget } from 'vs/base/browser/ui/widget'; import { KeyCode } from 'vs/base/common/keyCodes'; -import * as editorBrowser from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IContentWidget, ICodeEditor, IContentWidgetPosition, ContentWidgetPositionPreference, IOverlayWidget, IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser'; +import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; -export class ContentHoverWidget extends Widget implements editorBrowser.IContentWidget { +export class ContentHoverWidget extends Widget implements IContentWidget { private readonly _id: string; - protected _editor: editorBrowser.ICodeEditor; + protected _editor: ICodeEditor; private _isVisible: boolean; private readonly _containerDomNode: HTMLElement; private readonly _domNode: HTMLElement; @@ -37,7 +37,7 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent toggleClass(this._containerDomNode, 'hidden', !this._isVisible); } - constructor(id: string, editor: editorBrowser.ICodeEditor) { + constructor(id: string, editor: ICodeEditor) { super(); this._id = id; this._editor = editor; @@ -113,14 +113,14 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent } } - public getPosition(): editorBrowser.IContentWidgetPosition | null { + public getPosition(): IContentWidgetPosition | null { if (this.isVisible) { return { position: this._showAtPosition, range: this._showAtRange, preference: [ - editorBrowser.ContentWidgetPositionPreference.ABOVE, - editorBrowser.ContentWidgetPositionPreference.BELOW + ContentWidgetPositionPreference.ABOVE, + ContentWidgetPositionPreference.BELOW ] }; } @@ -161,15 +161,15 @@ export class ContentHoverWidget extends Widget implements editorBrowser.IContent } } -export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWidget { +export class GlyphHoverWidget extends Widget implements IOverlayWidget { private readonly _id: string; - protected _editor: editorBrowser.ICodeEditor; + protected _editor: ICodeEditor; private _isVisible: boolean; private readonly _domNode: HTMLElement; protected _showAtLineNumber: number; - constructor(id: string, editor: editorBrowser.ICodeEditor) { + constructor(id: string, editor: ICodeEditor) { super(); this._id = id; this._editor = editor; @@ -218,7 +218,7 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi const editorLayout = this._editor.getLayoutInfo(); const topForLineNumber = this._editor.getTopForLineNumber(this._showAtLineNumber); const editorScrollTop = this._editor.getScrollTop(); - const lineHeight = this._editor.getConfiguration().lineHeight; + const lineHeight = this._editor.getOption(EditorOption.lineHeight); const nodeHeight = this._domNode.clientHeight; const top = topForLineNumber - editorScrollTop - ((nodeHeight - lineHeight) / 2); @@ -233,7 +233,7 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi this.isVisible = false; } - public getPosition(): editorBrowser.IOverlayWidgetPosition | null { + public getPosition(): IOverlayWidgetPosition | null { return null; } diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index 76bb60097fd..06877b671d5 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -366,7 +366,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { // create blank olor picker model and widget first to ensure it's positioned correctly. const model = new ColorPickerModel(color, [], 0); - const widget = new ColorPickerWidget(fragment, model, this._editor.getConfiguration().pixelRatio, this._themeService); + const widget = new ColorPickerWidget(fragment, model, this._editor.getOption(EditorOption.pixelRatio), this._themeService); getColorPresentations(editorModel, colorInfo, msg.provider, CancellationToken.None).then(colorPresentations => { model.colorPresentations = colorPresentations || []; diff --git a/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts b/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts index 0ef1a5253c6..16d358dd7a4 100644 --- a/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/peekViewWidget.ts @@ -21,6 +21,7 @@ import { ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/con import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IDisposable } from 'vs/base/common/lifecycle'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const IPeekViewService = createDecorator('IPeekViewService'); @@ -216,7 +217,7 @@ export abstract class PeekViewWidget extends ZoneWidget { return; } - const headHeight = Math.ceil(this.editor.getConfiguration().lineHeight * 1.2); + const headHeight = Math.ceil(this.editor.getOption(EditorOption.lineHeight) * 1.2); const bodyHeight = heightInPixel - (headHeight + 2 /* the border-top/bottom width*/); this._doLayoutHead(headHeight, widthInPixel); diff --git a/src/vs/editor/contrib/rename/renameInputField.ts b/src/vs/editor/contrib/rename/renameInputField.ts index c285d9707cd..b3c9bea2be8 100644 --- a/src/vs/editor/contrib/rename/renameInputField.ts +++ b/src/vs/editor/contrib/rename/renameInputField.ts @@ -13,6 +13,7 @@ import { localize } from 'vs/nls'; import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { inputBackground, inputBorder, inputForeground, widgetShadow } from 'vs/platform/theme/common/colorRegistry'; import { ITheme, IThemeService } from 'vs/platform/theme/common/themeService'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const CONTEXT_RENAME_INPUT_VISIBLE = new RawContextKey('renameInputVisible', false); @@ -68,7 +69,7 @@ export class RenameInputField implements IContentWidget, IDisposable { this._inputField.type = 'text'; this._inputField.setAttribute('aria-label', localize('renameAriaLabel', "Rename input. Type new name and press Enter to commit.")); this._domNode = document.createElement('div'); - this._domNode.style.height = `${this._editor.getConfiguration().lineHeight}px`; + this._domNode.style.height = `${this._editor.getOption(EditorOption.lineHeight)}px`; this._domNode.className = 'monaco-editor rename-box'; this._domNode.appendChild(this._inputField); diff --git a/src/vs/editor/contrib/zoneWidget/zoneWidget.ts b/src/vs/editor/contrib/zoneWidget/zoneWidget.ts index 703706bf238..f464b2b14f3 100644 --- a/src/vs/editor/contrib/zoneWidget/zoneWidget.ts +++ b/src/vs/editor/contrib/zoneWidget/zoneWidget.ts @@ -11,7 +11,7 @@ import { IdGenerator } from 'vs/base/common/idGenerator'; import { DisposableStore } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, IViewZoneChangeAccessor } from 'vs/editor/browser/editorBrowser'; -import { EditorLayoutInfo } from 'vs/editor/common/config/editorOptions'; +import { EditorLayoutInfo, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ScrollType } from 'vs/editor/common/editorCommon'; @@ -334,7 +334,7 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { } private _decoratingElementsHeight(): number { - let lineHeight = this.editor.getConfiguration().lineHeight; + let lineHeight = this.editor.getOption(EditorOption.lineHeight); let result = 0; if (this.options.showArrow) { @@ -364,7 +364,7 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { // Render the widget as zone (rendering) and widget (lifecycle) const viewZoneDomNode = document.createElement('div'); viewZoneDomNode.style.overflow = 'hidden'; - const lineHeight = this.editor.getConfiguration().lineHeight; + const lineHeight = this.editor.getOption(EditorOption.lineHeight); // adjust heightInLines to viewport const maxHeightInLines = (this.editor.getLayoutInfo().height / lineHeight) * 0.8; @@ -505,7 +505,7 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { this._disposables.add(this._resizeSash.onDidChange((evt: ISashEvent) => { if (data) { - let lineDelta = (evt.currentY - data.startY) / this.editor.getConfiguration().lineHeight; + let lineDelta = (evt.currentY - data.startY) / this.editor.getOption(EditorOption.lineHeight); let roundedLineDelta = lineDelta < 0 ? Math.ceil(lineDelta) : Math.floor(lineDelta); let newHeightInLines = data.heightInLines + roundedLineDelta; diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index ee94ff2b4bc..59b8f512f19 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3110,10 +3110,17 @@ declare namespace monaco.editor { * Controls fading out of unused variables. */ showUnused?: boolean; + } + + export type IExtendedEditorOptions = IEditorOptions & { /** * Do not use, this is a computed option. */ editorClassName?: undefined; + /** + * Do not use, this is a computed option. + */ + pixelRatio?: undefined; /** * Do not use, this is a computed option. */ @@ -3126,7 +3133,7 @@ declare namespace monaco.editor { * Do not use, this is a computed option. */ wrappingInfo?: undefined; - } + }; /** * Configuration options for the diff editor. @@ -3254,8 +3261,6 @@ declare namespace monaco.editor { */ export class InternalEditorOptions { readonly _internalEditorOptionsBrand: void; - readonly pixelRatio: number; - readonly lineHeight: number; readonly fontInfo: FontInfo; } @@ -3264,8 +3269,6 @@ declare namespace monaco.editor { */ export interface IConfigurationChangedEvent { hasChanged(id: EditorOption): boolean; - readonly pixelRatio: boolean; - readonly lineHeight: boolean; readonly fontInfo: boolean; } @@ -3286,7 +3289,7 @@ declare namespace monaco.editor { get(id: T): FindComputedEditorOptionValueById; } - export interface IEditorOption, T3 = T2> { + export interface IEditorOption, T3 = T2> { readonly id: K1; readonly name: K2; readonly defaultValue: T2; @@ -3525,63 +3528,65 @@ declare namespace monaco.editor { inDiffEditor = 35, lightbulb = 36, lineDecorationsWidth = 37, - lineNumbers = 38, - lineNumbersMinChars = 39, - links = 40, - matchBrackets = 41, - minimap = 42, - mouseStyle = 43, - mouseWheelScrollSensitivity = 44, - mouseWheelZoom = 45, - multiCursorMergeOverlapping = 46, - multiCursorModifier = 47, - occurrencesHighlight = 48, - overviewRulerBorder = 49, - overviewRulerLanes = 50, - parameterHints = 51, - quickSuggestions = 52, - quickSuggestionsDelay = 53, - readOnly = 54, - renderControlCharacters = 55, - renderIndentGuides = 56, - renderFinalNewline = 57, - renderLineHighlight = 58, - renderWhitespace = 59, - revealHorizontalRightPadding = 60, - roundedSelection = 61, - rulers = 62, - scrollbar = 63, - scrollBeyondLastColumn = 64, - scrollBeyondLastLine = 65, - selectionClipboard = 66, - selectionHighlight = 67, - selectOnLineNumbers = 68, - showFoldingControls = 69, - showUnused = 70, - snippetSuggestions = 71, - smoothScrolling = 72, - stopRenderingLineAfter = 73, - suggestFontSize = 74, - suggestLineHeight = 75, - suggestOnTriggerCharacters = 76, - suggestSelection = 77, - tabCompletion = 78, - useTabStops = 79, - wordSeparators = 80, - wordWrap = 81, - wordWrapBreakAfterCharacters = 82, - wordWrapBreakBeforeCharacters = 83, - wordWrapBreakObtrusiveCharacters = 84, - wordWrapColumn = 85, - wordWrapMinified = 86, - wrappingIndent = 87, - ariaLabel = 88, - disableMonospaceOptimizations = 89, - editorClassName = 90, - tabFocusMode = 91, - suggest = 92, - layoutInfo = 93, - wrappingInfo = 94 + lineHeight = 38, + lineNumbers = 39, + lineNumbersMinChars = 40, + links = 41, + matchBrackets = 42, + minimap = 43, + mouseStyle = 44, + mouseWheelScrollSensitivity = 45, + mouseWheelZoom = 46, + multiCursorMergeOverlapping = 47, + multiCursorModifier = 48, + occurrencesHighlight = 49, + overviewRulerBorder = 50, + overviewRulerLanes = 51, + parameterHints = 52, + quickSuggestions = 53, + quickSuggestionsDelay = 54, + readOnly = 55, + renderControlCharacters = 56, + renderIndentGuides = 57, + renderFinalNewline = 58, + renderLineHighlight = 59, + renderWhitespace = 60, + revealHorizontalRightPadding = 61, + roundedSelection = 62, + rulers = 63, + scrollbar = 64, + scrollBeyondLastColumn = 65, + scrollBeyondLastLine = 66, + selectionClipboard = 67, + selectionHighlight = 68, + selectOnLineNumbers = 69, + showFoldingControls = 70, + showUnused = 71, + snippetSuggestions = 72, + smoothScrolling = 73, + stopRenderingLineAfter = 74, + suggestFontSize = 75, + suggestLineHeight = 76, + suggestOnTriggerCharacters = 77, + suggestSelection = 78, + tabCompletion = 79, + useTabStops = 80, + wordSeparators = 81, + wordWrap = 82, + wordWrapBreakAfterCharacters = 83, + wordWrapBreakBeforeCharacters = 84, + wordWrapBreakObtrusiveCharacters = 85, + wordWrapColumn = 86, + wordWrapMinified = 87, + wrappingIndent = 88, + ariaLabel = 89, + disableMonospaceOptimizations = 90, + editorClassName = 91, + pixelRatio = 92, + tabFocusMode = 93, + suggest = 94, + layoutInfo = 95, + wrappingInfo = 96 } export const EditorOptions: { @@ -3623,6 +3628,7 @@ declare namespace monaco.editor { inDiffEditor: IEditorOption; lightbulb: IEditorOption; lineDecorationsWidth: IEditorOption; + lineHeight: IEditorOption; lineNumbers: IEditorOption; lineNumbersMinChars: IEditorOption; links: IEditorOption; @@ -3676,6 +3682,7 @@ declare namespace monaco.editor { ariaLabel: IEditorOption; disableMonospaceOptimizations: IEditorOption; editorClassName: IEditorOption; + pixelRatio: IEditorOption; tabFocusMode: IEditorOption; suggest: IEditorOption; layoutInfo: IEditorOption; diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 0bd28e5fe58..42d3d7a8a14 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -44,6 +44,7 @@ import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentSe import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; import { SimpleCommentEditor } from './simpleCommentEditor'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration'; const COLLAPSE_ACTION_CLASS = 'expand-review-action'; @@ -386,7 +387,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget this._disposables.add(this.editor.onMouseDown(e => this.onEditorMouseDown(e))); this._disposables.add(this.editor.onMouseUp(e => this.onEditorMouseUp(e))); - let headHeight = Math.ceil(this.editor.getConfiguration().lineHeight * 1.2); + let headHeight = Math.ceil(this.editor.getOption(EditorOption.lineHeight) * 1.2); this._headElement.style.height = `${headHeight}px`; this._headElement.style.lineHeight = this._headElement.style.height; @@ -692,8 +693,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget _refresh() { if (this._isExpanded && this._bodyElement) { let dimensions = dom.getClientArea(this._bodyElement); - const headHeight = Math.ceil(this.editor.getConfiguration().lineHeight * 1.2); - const lineHeight = this.editor.getConfiguration().lineHeight; + const headHeight = Math.ceil(this.editor.getOption(EditorOption.lineHeight) * 1.2); + const lineHeight = this.editor.getOption(EditorOption.lineHeight); const arrowHeight = Math.round(lineHeight / 3); const frameThickness = Math.round(lineHeight / 9) * 2; diff --git a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts index 0d038ec13c9..9191e39728b 100644 --- a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts +++ b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts @@ -15,6 +15,7 @@ import { Color } from 'vs/base/common/color'; import { registerColor } from 'vs/platform/theme/common/colorRegistry'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { LinkDetector } from 'vs/workbench/contrib/debug/browser/linkDetector'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; const $ = dom.$; // theming @@ -89,7 +90,7 @@ export class ExceptionWidget extends ZoneWidget { // Reload the height with respect to the exception text content and relayout it to match the line count. this.container!.style.height = 'initial'; - const lineHeight = this.editor.getConfiguration().lineHeight; + const lineHeight = this.editor.getOption(EditorOption.lineHeight); const arrowHeight = Math.round(lineHeight / 3); const computedLinesNumber = Math.ceil((this.container!.offsetHeight + arrowHeight) / lineHeight); diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts index 7f66cba3d62..2697f1a9e02 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts @@ -202,10 +202,11 @@ export class SettingsGroupTitleWidget extends Widget implements IViewZone { private layout(): void { const configuration = this.editor.getConfiguration(); + const options = this.editor.getOptions(); const layoutInfo = this.editor.getLayoutInfo(); this._domNode.style.width = layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth + 'px'; - this.titleContainer.style.lineHeight = configuration.lineHeight + 3 + 'px'; - this.titleContainer.style.height = configuration.lineHeight + 3 + 'px'; + this.titleContainer.style.lineHeight = options.get(EditorOption.lineHeight) + 3 + 'px'; + this.titleContainer.style.height = options.get(EditorOption.lineHeight) + 3 + 'px'; this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; this.icon.style.minWidth = `${this.getIconSize(16)}px`; } diff --git a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts index 955579069d7..ec16eec903b 100644 --- a/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts +++ b/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts @@ -33,7 +33,7 @@ import { rot } from 'vs/base/common/numbers'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { peekViewBorder, peekViewTitleBackground, peekViewTitleForeground, peekViewTitleInfoForeground } from 'vs/editor/contrib/referenceSearch/referencesWidget'; import { EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; -import { IDiffEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IDiffEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Action, IAction, ActionRunner } from 'vs/base/common/actions'; import { IActionBarOptions, ActionsOrientation, IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; @@ -223,7 +223,7 @@ class DirtyDiffWidget extends PeekViewWidget { const position = new Position(getModifiedEndLineNumber(change), 1); - const lineHeight = this.editor.getConfiguration().lineHeight; + const lineHeight = this.editor.getOption(EditorOption.lineHeight); const editorHeight = this.editor.getLayoutInfo().height; const editorHeightInLines = Math.floor(editorHeight / lineHeight); const height = Math.min(getChangeHeight(change) + /* padding */ 8, Math.floor(editorHeightInLines / 3)); diff --git a/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts b/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts index 9a0ed0de114..089c2bb1a46 100644 --- a/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts +++ b/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts @@ -26,7 +26,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { Event } from 'vs/base/common/event'; import { isObject } from 'vs/base/common/types'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; -import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { registerColor, focusBorder, textLinkForeground, textLinkActiveForeground, textPreformatForeground, contrastBorder, textBlockQuoteBackground, textBlockQuoteBorder } from 'vs/platform/theme/common/colorRegistry'; import { getExtraColor } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughUtils'; @@ -312,7 +312,7 @@ export class WalkThroughPart extends BaseEditor { this.contentDisposables.push(editor); const updateHeight = (initial: boolean) => { - const lineHeight = editor.getConfiguration().lineHeight; + const lineHeight = editor.getOption(EditorOption.lineHeight); const height = `${Math.max(model.getLineCount() + 1, 4) * lineHeight}px`; if (div.style.height !== height) { div.style.height = height; @@ -329,7 +329,7 @@ export class WalkThroughPart extends BaseEditor { if (innerContent) { const targetTop = div.getBoundingClientRect().top; const containerTop = innerContent.getBoundingClientRect().top; - const lineHeight = editor.getConfiguration().lineHeight; + const lineHeight = editor.getOption(EditorOption.lineHeight); const lineTop = (targetTop + (e.position.lineNumber - 1) * lineHeight) - containerTop; const lineBottom = lineTop + lineHeight; const scrollDimensions = this.scrollbar.getScrollDimensions(); From 27adb78b9d91a8f697a8cb2901610e897b34cf73 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 15:18:07 +0200 Subject: [PATCH 014/109] Migrate fontInfo to the new editor option format --- .../editor/browser/controller/mouseTarget.ts | 4 +- .../browser/controller/textAreaHandler.ts | 6 +- src/vs/editor/browser/editorBrowser.ts | 6 +- src/vs/editor/browser/view/viewOverlays.ts | 4 +- .../viewParts/decorations/decorations.ts | 6 +- .../viewParts/indentGuides/indentGuides.ts | 10 +- .../browser/viewParts/lines/viewLine.ts | 7 +- .../browser/viewParts/lines/viewLines.ts | 11 +- .../browser/viewParts/minimap/minimap.ts | 2 +- .../editor/browser/viewParts/rulers/rulers.ts | 4 +- .../viewParts/selections/selections.ts | 4 +- .../viewParts/viewCursors/viewCursor.ts | 10 +- .../editor/browser/widget/codeEditorWidget.ts | 12 +- .../editor/browser/widget/diffEditorWidget.ts | 24 +- src/vs/editor/browser/widget/diffReview.ts | 25 +- .../widget/embeddedCodeEditorWidget.ts | 8 +- .../common/config/commonEditorConfig.ts | 78 +++--- src/vs/editor/common/config/editorOptions.ts | 242 ++++++------------ src/vs/editor/common/config/fontInfo.ts | 93 ++----- .../editor/common/controller/cursorCommon.ts | 4 +- src/vs/editor/common/editorCommon.ts | 13 +- .../common/standalone/standaloneEnums.ts | 145 ++++++----- src/vs/editor/common/view/viewEvents.ts | 8 +- src/vs/editor/common/viewLayout/viewLayout.ts | 6 +- .../editor/common/viewModel/viewModelImpl.ts | 14 +- .../contrib/codeAction/lightBulbWidget.ts | 6 +- .../contrib/codelens/codelensController.ts | 2 +- .../editor/contrib/codelens/codelensWidget.ts | 2 +- src/vs/editor/contrib/find/findWidget.ts | 4 +- src/vs/editor/contrib/folding/folding.ts | 4 +- .../contrib/gotoError/gotoErrorWidget.ts | 2 +- src/vs/editor/contrib/hover/hover.ts | 6 +- src/vs/editor/contrib/hover/hoverWidgets.ts | 12 +- .../contrib/markdown/markdownRenderer.ts | 3 +- .../parameterHints/parameterHintsWidget.ts | 10 +- .../editor/contrib/rename/renameInputField.ts | 4 +- .../editor/contrib/suggest/suggestWidget.ts | 35 ++- .../standalone/browser/standaloneEditor.ts | 6 +- .../common/config/commonEditorConfig.test.ts | 4 +- .../viewModel/splitLinesCollection.test.ts | 6 +- src/vs/monaco.d.ts | 171 +++++++------ .../browser/parts/editor/editorStatus.ts | 4 +- .../codeEditor/browser/selectionClipboard.ts | 4 +- .../comments/browser/commentThreadWidget.ts | 4 +- .../contrib/debug/browser/debugHover.ts | 6 +- .../contrib/debug/browser/exceptionWidget.ts | 2 +- .../preferences/browser/preferencesWidgets.ts | 10 +- 47 files changed, 478 insertions(+), 575 deletions(-) diff --git a/src/vs/editor/browser/controller/mouseTarget.ts b/src/vs/editor/browser/controller/mouseTarget.ts index 4ec958948b2..c025c958a0f 100644 --- a/src/vs/editor/browser/controller/mouseTarget.ts +++ b/src/vs/editor/browser/controller/mouseTarget.ts @@ -243,7 +243,7 @@ export class HitTestContext { this.layoutInfo = options.get(EditorOption.layoutInfo); this.viewDomNode = viewHelper.viewDomNode; this.lineHeight = options.get(EditorOption.lineHeight); - this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this.typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; this.lastViewCursorsRenderData = lastViewCursorsRenderData; this._context = context; this._viewHelper = viewHelper; @@ -717,7 +717,7 @@ export class MouseTargetFactory { const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + pos.x - editorPos.x - layoutInfo.contentLeft; - return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); + return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth); } public static _getMouseColumn(mouseContentHorizontalOffset: number, typicalHalfwidthCharacterWidth: number): number { diff --git a/src/vs/editor/browser/controller/textAreaHandler.ts b/src/vs/editor/browser/controller/textAreaHandler.ts index 18902d71eb9..c65043b9515 100644 --- a/src/vs/editor/browser/controller/textAreaHandler.ts +++ b/src/vs/editor/browser/controller/textAreaHandler.ts @@ -121,7 +121,6 @@ export class TextAreaHandler extends ViewPart { this._scrollLeft = 0; this._scrollTop = 0; - const conf = this._context.configuration.editor; const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); @@ -129,7 +128,7 @@ export class TextAreaHandler extends ViewPart { this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; - this._fontInfo = conf.fontInfo; + this._fontInfo = options.get(EditorOption.fontInfo); this._lineHeight = options.get(EditorOption.lineHeight); this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); @@ -374,7 +373,6 @@ export class TextAreaHandler extends ViewPart { // --- begin event handlers public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - const conf = this._context.configuration.editor; const options = this._context.configuration.options; const layoutInfo = options.get(EditorOption.layoutInfo); @@ -382,7 +380,7 @@ export class TextAreaHandler extends ViewPart { this._contentLeft = layoutInfo.contentLeft; this._contentWidth = layoutInfo.contentWidth; this._contentHeight = layoutInfo.contentHeight; - this._fontInfo = conf.fontInfo; + this._fontInfo = options.get(EditorOption.fontInfo); this._lineHeight = options.get(EditorOption.lineHeight); this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard); this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting); diff --git a/src/vs/editor/browser/editorBrowser.ts b/src/vs/editor/browser/editorBrowser.ts index c8f7a8ee5ca..0fa2f337921 100644 --- a/src/vs/editor/browser/editorBrowser.ts +++ b/src/vs/editor/browser/editorBrowser.ts @@ -6,7 +6,7 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IMouseEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { OverviewRulerPosition, IConfigurationChangedEvent, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { OverviewRulerPosition, ConfigurationChangedEvent, EditorLayoutInfo, IComputedEditorOptions, EditorOption, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { IPosition, Position } from 'vs/editor/common/core/position'; @@ -351,7 +351,7 @@ export interface ICodeEditor extends editorCommon.IEditor { * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) * @event */ - onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; + onDidChangeConfiguration(listener: (e: ConfigurationChangedEvent) => void): IDisposable; /** * An event emitted when the cursor position has changed. * @event @@ -534,8 +534,6 @@ export interface ICodeEditor extends editorCommon.IEditor { /** * Returns the current editor's configuration */ - getConfiguration(): InternalEditorOptions; - getOptions(): IComputedEditorOptions; getOption(id: T): FindComputedEditorOptionValueById; diff --git a/src/vs/editor/browser/view/viewOverlays.ts b/src/vs/editor/browser/view/viewOverlays.ts index 43a6a96f830..130f1f09fae 100644 --- a/src/vs/editor/browser/view/viewOverlays.ts +++ b/src/vs/editor/browser/view/viewOverlays.ts @@ -257,12 +257,12 @@ export class MarginViewOverlays extends ViewOverlays { this.domNode.setClassName('margin-view-overlays'); this.domNode.setWidth(1); - Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); + Configuration.applyFontInfo(this.domNode, options.get(EditorOption.fontInfo)); } public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { - Configuration.applyFontInfo(this.domNode, this._context.configuration.editor.fontInfo); const options = this._context.configuration.options; + Configuration.applyFontInfo(this.domNode, options.get(EditorOption.fontInfo)); const layoutInfo = options.get(EditorOption.layoutInfo); this._contentLeft = layoutInfo.contentLeft; return super.onConfigurationChanged(e) || true; diff --git a/src/vs/editor/browser/viewParts/decorations/decorations.ts b/src/vs/editor/browser/viewParts/decorations/decorations.ts index 2e0627b2b94..7ba28975519 100644 --- a/src/vs/editor/browser/viewParts/decorations/decorations.ts +++ b/src/vs/editor/browser/viewParts/decorations/decorations.ts @@ -24,7 +24,7 @@ export class DecorationsOverlay extends DynamicViewOverlay { this._context = context; const options = this._context.configuration.options; this._lineHeight = options.get(EditorOption.lineHeight); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; this._renderResult = null; this._context.addEventHandler(this); @@ -41,9 +41,7 @@ export class DecorationsOverlay extends DynamicViewOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; this._lineHeight = options.get(EditorOption.lineHeight); - if (e.fontInfo) { - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; - } + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; return true; } public onDecorationsChanged(e: viewEvents.ViewDecorationsChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts index 762c8dff713..6af61888a62 100644 --- a/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts +++ b/src/vs/editor/browser/viewParts/indentGuides/indentGuides.ts @@ -32,12 +32,13 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); + const fontInfo = options.get(EditorOption.fontInfo); this._lineHeight = options.get(EditorOption.lineHeight); - this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; + this._spaceWidth = fontInfo.spaceWidth; this._enabled = options.get(EditorOption.renderIndentGuides); this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); - this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); + this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * fontInfo.typicalHalfwidthCharacterWidth); this._renderResult = null; @@ -55,12 +56,13 @@ export class IndentGuidesOverlay extends DynamicViewOverlay { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); + const fontInfo = options.get(EditorOption.fontInfo); this._lineHeight = options.get(EditorOption.lineHeight); - this._spaceWidth = this._context.configuration.editor.fontInfo.spaceWidth; + this._spaceWidth = fontInfo.spaceWidth; this._enabled = options.get(EditorOption.renderIndentGuides); this._activeIndentEnabled = options.get(EditorOption.highlightActiveIndentGuide); - this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth); + this._maxIndentLeft = wrappingInfo.wrappingColumn === -1 ? -1 : (wrappingInfo.wrappingColumn * fontInfo.typicalHalfwidthCharacterWidth); return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/lines/viewLine.ts b/src/vs/editor/browser/viewParts/lines/viewLine.ts index f337db9c1f8..79b99d939a4 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLine.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLine.ts @@ -82,14 +82,15 @@ export class ViewLineOptions { constructor(config: IConfiguration, themeType: ThemeType) { this.themeType = themeType; const options = config.options; + const fontInfo = options.get(EditorOption.fontInfo); this.renderWhitespace = options.get(EditorOption.renderWhitespace); this.renderControlCharacters = options.get(EditorOption.renderControlCharacters); - this.spaceWidth = config.editor.fontInfo.spaceWidth; + this.spaceWidth = fontInfo.spaceWidth; this.useMonospaceOptimizations = ( - config.editor.fontInfo.isMonospace + fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations) ); - this.canUseHalfwidthRightwardsArrow = config.editor.fontInfo.canUseHalfwidthRightwardsArrow; + this.canUseHalfwidthRightwardsArrow = fontInfo.canUseHalfwidthRightwardsArrow; this.lineHeight = options.get(EditorOption.lineHeight); this.stopRenderingLineAfter = options.get(EditorOption.stopRenderingLineAfter); this.fontLigatures = options.get(EditorOption.fontLigatures); diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 092cb3c9a70..eb524a41b69 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -94,10 +94,11 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, const conf = this._context.configuration; const options = this._context.configuration.options; + const fontInfo = options.get(EditorOption.fontInfo); const wrappingInfo = options.get(EditorOption.wrappingInfo); this._lineHeight = options.get(EditorOption.lineHeight); - this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; this._isViewportWrapping = wrappingInfo.isViewportWrapping; this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); this._cursorSurroundingLines = options.get(EditorOption.cursorSurroundingLines); @@ -107,7 +108,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, PartFingerprints.write(this.domNode, PartFingerprint.ViewLines); this.domNode.setClassName('view-lines'); - Configuration.applyFontInfo(this.domNode, conf.editor.fontInfo); + Configuration.applyFontInfo(this.domNode, fontInfo); // --- width & height this._maxLineWidth = 0; @@ -145,17 +146,17 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost, this._maxLineWidth = 0; } - const conf = this._context.configuration; const options = this._context.configuration.options; + const fontInfo = options.get(EditorOption.fontInfo); const wrappingInfo = options.get(EditorOption.wrappingInfo); this._lineHeight = options.get(EditorOption.lineHeight); - this._typicalHalfwidthCharacterWidth = conf.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; this._isViewportWrapping = wrappingInfo.isViewportWrapping; this._revealHorizontalRightPadding = options.get(EditorOption.revealHorizontalRightPadding); this._cursorSurroundingLines = options.get(EditorOption.cursorSurroundingLines); this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting); - Configuration.applyFontInfo(this.domNode, conf.editor.fontInfo); + Configuration.applyFontInfo(this.domNode, fontInfo); this._onOptionsMaybeChanged(); diff --git a/src/vs/editor/browser/viewParts/minimap/minimap.ts b/src/vs/editor/browser/viewParts/minimap/minimap.ts index 2550266af76..d7fb6e54408 100644 --- a/src/vs/editor/browser/viewParts/minimap/minimap.ts +++ b/src/vs/editor/browser/viewParts/minimap/minimap.ts @@ -110,7 +110,7 @@ class MinimapOptions { const options = configuration.options; const pixelRatio = options.get(EditorOption.pixelRatio); const layoutInfo = options.get(EditorOption.layoutInfo); - const fontInfo = configuration.editor.fontInfo; + const fontInfo = options.get(EditorOption.fontInfo); this.renderMinimap = layoutInfo.renderMinimap | 0; this.scrollBeyondLastLine = options.get(EditorOption.scrollBeyondLastLine); diff --git a/src/vs/editor/browser/viewParts/rulers/rulers.ts b/src/vs/editor/browser/viewParts/rulers/rulers.ts index 3c9f9cf6bb5..0f22de06a73 100644 --- a/src/vs/editor/browser/viewParts/rulers/rulers.ts +++ b/src/vs/editor/browser/viewParts/rulers/rulers.ts @@ -29,7 +29,7 @@ export class Rulers extends ViewPart { this._renderedRulers = []; const options = this._context.configuration.options; this._rulers = options.get(EditorOption.rulers); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; } public dispose(): void { @@ -41,7 +41,7 @@ export class Rulers extends ViewPart { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; this._rulers = options.get(EditorOption.rulers); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; return true; } public onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/selections/selections.ts b/src/vs/editor/browser/viewParts/selections/selections.ts index b960faf5751..f059e95dbb1 100644 --- a/src/vs/editor/browser/viewParts/selections/selections.ts +++ b/src/vs/editor/browser/viewParts/selections/selections.ts @@ -87,7 +87,7 @@ export class SelectionsOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; this._lineHeight = options.get(EditorOption.lineHeight); this._roundedSelection = options.get(EditorOption.roundedSelection); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; this._selections = []; this._renderResult = null; this._context.addEventHandler(this); @@ -105,7 +105,7 @@ export class SelectionsOverlay extends DynamicViewOverlay { const options = this._context.configuration.options; this._lineHeight = options.get(EditorOption.lineHeight); this._roundedSelection = options.get(EditorOption.roundedSelection); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; return true; } public onCursorStateChanged(e: viewEvents.ViewCursorStateChangedEvent): boolean { diff --git a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts index be49b426a8d..09648af24a8 100644 --- a/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts +++ b/src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts @@ -52,10 +52,11 @@ export class ViewCursor { constructor(context: ViewContext) { this._context = context; const options = this._context.configuration.options; + const fontInfo = options.get(EditorOption.fontInfo); this._cursorStyle = options.get(EditorOption.cursorStyle); this._lineHeight = options.get(EditorOption.lineHeight); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); this._isVisible = true; @@ -66,7 +67,7 @@ export class ViewCursor { this._domNode.setHeight(this._lineHeight); this._domNode.setTop(0); this._domNode.setLeft(0); - Configuration.applyFontInfo(this._domNode, this._context.configuration.editor.fontInfo); + Configuration.applyFontInfo(this._domNode, fontInfo); this._domNode.setDisplay('none'); this._position = new Position(1, 1); @@ -99,12 +100,13 @@ export class ViewCursor { public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean { const options = this._context.configuration.options; + const fontInfo = options.get(EditorOption.fontInfo); this._cursorStyle = options.get(EditorOption.cursorStyle); this._lineHeight = options.get(EditorOption.lineHeight); - this._typicalHalfwidthCharacterWidth = this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth); - Configuration.applyFontInfo(this._domNode, this._context.configuration.editor.fontInfo); + Configuration.applyFontInfo(this._domNode, fontInfo); return true; } diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 730a5c027f8..3170cdb2b66 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -23,7 +23,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService import { ICommandDelegate } from 'vs/editor/browser/view/viewController'; import { IContentWidgetData, IOverlayWidgetData, View } from 'vs/editor/browser/view/viewImpl'; import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents'; -import { IConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, InternalEditorOptions, IComputedEditorOptions, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorLayoutInfo, IEditorOptions, EditorOption, IComputedEditorOptions, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; import { Cursor, CursorStateChangedEvent } from 'vs/editor/common/controller/cursor'; import { CursorColumns, ICursors } from 'vs/editor/common/controller/cursorCommon'; import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; @@ -125,8 +125,8 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE private readonly _onDidChangeModelDecorations: Emitter = this._register(new Emitter()); public readonly onDidChangeModelDecorations: Event = this._onDidChangeModelDecorations.event; - private readonly _onDidChangeConfiguration: Emitter = this._register(new Emitter()); - public readonly onDidChangeConfiguration: Event = this._onDidChangeConfiguration.event; + private readonly _onDidChangeConfiguration: Emitter = this._register(new Emitter()); + public readonly onDidChangeConfiguration: Event = this._onDidChangeConfiguration.event; protected readonly _onDidChangeModel: Emitter = this._register(new Emitter()); public readonly onDidChangeModel: Event = this._onDidChangeModel.event; @@ -368,10 +368,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE this._configuration.updateOptions(newOptions); } - public getConfiguration(): InternalEditorOptions { - return this._configuration.editor; - } - public getOptions(): IComputedEditorOptions { return this._configuration.options; } @@ -1308,7 +1304,7 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE } public applyFontInfo(target: HTMLElement): void { - Configuration.applyFontInfoSlow(target, this._configuration.editor.fontInfo); + Configuration.applyFontInfoSlow(target, this._configuration.options.get(EditorOption.fontInfo)); } protected _attachModel(model: ITextModel | null): void { diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index 93f4e544425..3e6e67a65a0 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -20,7 +20,7 @@ import * as editorBrowser from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffReview } from 'vs/editor/browser/widget/diffReview'; -import { IDiffEditorOptions, IEditorOptions, EditorLayoutInfo, InternalEditorOptions, IComputedEditorOptions, EditorOption, EditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IDiffEditorOptions, IEditorOptions, EditorLayoutInfo, IComputedEditorOptions, EditorOption, EditorOptions } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -480,7 +480,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE })); this._register(editor.onDidChangeConfiguration((e) => { - if (e.fontInfo && editor.getModel()) { + if (e.hasChanged(EditorOption.fontInfo) && editor.getModel()) { this._onViewZonesChanged(); } })); @@ -1946,7 +1946,6 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito class InlineViewZonesComputer extends ViewZonesComputer { private readonly originalModel: ITextModel; - private readonly modifiedEditorConfiguration: InternalEditorOptions; private readonly modifiedEditorOptions: IComputedEditorOptions; private readonly modifiedEditorTabSize: number; private readonly renderIndicators: boolean; @@ -1954,7 +1953,6 @@ class InlineViewZonesComputer extends ViewZonesComputer { constructor(lineChanges: editorCommon.ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, renderIndicators: boolean) { super(lineChanges, originalForeignVZ, modifiedForeignVZ); this.originalModel = originalEditor.getModel()!; - this.modifiedEditorConfiguration = modifiedEditor.getConfiguration(); this.modifiedEditorOptions = modifiedEditor.getOptions(); this.modifiedEditorTabSize = modifiedEditor.getModel()!.getOptions().tabSize; this.renderIndicators = renderIndicators; @@ -1996,14 +1994,15 @@ class InlineViewZonesComputer extends ViewZonesComputer { let sb = createStringBuilder(10000); let marginHTML: string[] = []; const layoutInfo = this.modifiedEditorOptions.get(EditorOption.layoutInfo); + const fontInfo = this.modifiedEditorOptions.get(EditorOption.fontInfo); const lineDecorationsWidth = layoutInfo.decorationsWidth; let lineHeight = this.modifiedEditorOptions.get(EditorOption.lineHeight); - const typicalHalfwidthCharacterWidth = this.modifiedEditorConfiguration.fontInfo.typicalHalfwidthCharacterWidth; + const typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth; let maxCharsPerLine = 0; const originalContent: string[] = []; for (let lineNumber = lineChange.originalStartLineNumber; lineNumber <= lineChange.originalEndLineNumber; lineNumber++) { - maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorConfiguration, this.modifiedEditorOptions, this.modifiedEditorTabSize, lineNumber, decorations, sb)); + maxCharsPerLine = Math.max(maxCharsPerLine, this._renderOriginalLine(lineNumber - lineChange.originalStartLineNumber, this.originalModel, this.modifiedEditorOptions, this.modifiedEditorTabSize, lineNumber, decorations, sb)); originalContent.push(this.originalModel.getLineContent(lineNumber)); if (this.renderIndicators) { @@ -2018,12 +2017,12 @@ class InlineViewZonesComputer extends ViewZonesComputer { let domNode = document.createElement('div'); domNode.className = 'view-lines line-delete'; domNode.innerHTML = sb.build(); - Configuration.applyFontInfoSlow(domNode, this.modifiedEditorConfiguration.fontInfo); + Configuration.applyFontInfoSlow(domNode, fontInfo); let marginDomNode = document.createElement('div'); marginDomNode.className = 'inline-deleted-margin-view-zone'; marginDomNode.innerHTML = marginHTML.join(''); - Configuration.applyFontInfoSlow(marginDomNode, this.modifiedEditorConfiguration.fontInfo); + Configuration.applyFontInfoSlow(marginDomNode, fontInfo); return { shouldNotShrink: true, @@ -2042,9 +2041,10 @@ class InlineViewZonesComputer extends ViewZonesComputer { }; } - private _renderOriginalLine(count: number, originalModel: ITextModel, config: InternalEditorOptions, options: IComputedEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { + private _renderOriginalLine(count: number, originalModel: ITextModel, options: IComputedEditorOptions, tabSize: number, lineNumber: number, decorations: InlineDecoration[], sb: IStringBuilder): number { const lineTokens = originalModel.getLineTokens(lineNumber); const lineContent = lineTokens.getLineContent(); + const fontInfo = options.get(EditorOption.fontInfo); const actualDecorations = LineDecoration.filter(decorations, lineNumber, 1, lineContent.length + 1); @@ -2060,8 +2060,8 @@ class InlineViewZonesComputer extends ViewZonesComputer { const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, originalModel.mightContainNonBasicASCII()); const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, originalModel.mightContainRTL()); const output = renderViewLine(new RenderLineInput( - (config.fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), - config.fontInfo.canUseHalfwidthRightwardsArrow, + (fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), + fontInfo.canUseHalfwidthRightwardsArrow, lineContent, false, isBasicASCII, @@ -2070,7 +2070,7 @@ class InlineViewZonesComputer extends ViewZonesComputer { lineTokens, actualDecorations, tabSize, - config.fontInfo.spaceWidth, + fontInfo.spaceWidth, options.get(EditorOption.stopRenderingLineAfter), options.get(EditorOption.renderWhitespace), options.get(EditorOption.renderControlCharacters), diff --git a/src/vs/editor/browser/widget/diffReview.ts b/src/vs/editor/browser/widget/diffReview.ts index c2b32e4c5ae..81e1de6d6a6 100644 --- a/src/vs/editor/browser/widget/diffReview.ts +++ b/src/vs/editor/browser/widget/diffReview.ts @@ -17,7 +17,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; -import { InternalEditorOptions, IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { IComputedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { LineTokens } from 'vs/editor/common/core/lineTokens'; import { Position } from 'vs/editor/common/core/position'; import { ILineChange, ScrollType } from 'vs/editor/common/editorCommon'; @@ -524,9 +524,7 @@ export class DiffReview extends Disposable { private _render(): void { - const originalOpts = this._diffEditor.getOriginalEditor().getConfiguration(); const originalOptions = this._diffEditor.getOriginalEditor().getOptions(); - const modifiedOpts = this._diffEditor.getModifiedEditor().getConfiguration(); const modifiedOptions = this._diffEditor.getModifiedEditor().getOptions(); const originalModel = this._diffEditor.getOriginalEditor().getModel(); @@ -553,7 +551,7 @@ export class DiffReview extends Disposable { let container = document.createElement('div'); container.className = 'diff-review-table'; container.setAttribute('role', 'list'); - Configuration.applyFontInfoSlow(container, modifiedOpts.fontInfo); + Configuration.applyFontInfoSlow(container, modifiedOptions.get(EditorOption.fontInfo)); let minOriginalLine = 0; let maxOriginalLine = 0; @@ -622,7 +620,7 @@ export class DiffReview extends Disposable { let modLine = minModifiedLine; for (let i = 0, len = diffs.length; i < len; i++) { const diffEntry = diffs[i]; - DiffReview._renderSection(container, diffEntry, modLine, this._width, originalOpts, originalOptions, originalModel, originalModelOpts, modifiedOpts, modifiedOptions, modifiedModel, modifiedModelOpts); + DiffReview._renderSection(container, diffEntry, modLine, this._width, originalOptions, originalModel, originalModelOpts, modifiedOptions, modifiedModel, modifiedModelOpts); if (diffEntry.modifiedLineStart !== 0) { modLine = diffEntry.modifiedLineEnd; } @@ -635,8 +633,8 @@ export class DiffReview extends Disposable { private static _renderSection( dest: HTMLElement, diffEntry: DiffEntry, modLine: number, width: number, - originalOpts: InternalEditorOptions, originalOptions: IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, - modifiedOpts: InternalEditorOptions, modifiedOptions: IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions + originalOptions: IComputedEditorOptions, originalModel: ITextModel, originalModelOpts: TextModelResolvedOptions, + modifiedOptions: IComputedEditorOptions, modifiedModel: ITextModel, modifiedModelOpts: TextModelResolvedOptions ): void { const type = diffEntry.getType(); @@ -721,12 +719,12 @@ export class DiffReview extends Disposable { let lineContent: string; if (modifiedLine !== 0) { cell.insertAdjacentHTML('beforeend', - this._renderLine(modifiedModel, modifiedOpts, modifiedOptions, modifiedModelOpts.tabSize, modifiedLine) + this._renderLine(modifiedModel, modifiedOptions, modifiedModelOpts.tabSize, modifiedLine) ); lineContent = modifiedModel.getLineContent(modifiedLine); } else { cell.insertAdjacentHTML('beforeend', - this._renderLine(originalModel, originalOpts, originalOptions, originalModelOpts.tabSize, originalLine) + this._renderLine(originalModel, originalOptions, originalModelOpts.tabSize, originalLine) ); lineContent = originalModel.getLineContent(originalLine); } @@ -753,8 +751,9 @@ export class DiffReview extends Disposable { } } - private static _renderLine(model: ITextModel, config: InternalEditorOptions, options: IComputedEditorOptions, tabSize: number, lineNumber: number): string { + private static _renderLine(model: ITextModel, options: IComputedEditorOptions, tabSize: number, lineNumber: number): string { const lineContent = model.getLineContent(lineNumber); + const fontInfo = options.get(EditorOption.fontInfo); const defaultMetadata = ( (FontStyle.None << MetadataConsts.FONT_STYLE_OFFSET) @@ -771,8 +770,8 @@ export class DiffReview extends Disposable { const isBasicASCII = ViewLineRenderingData.isBasicASCII(lineContent, model.mightContainNonBasicASCII()); const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, model.mightContainRTL()); const r = renderViewLine(new RenderLineInput( - (config.fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), - config.fontInfo.canUseHalfwidthRightwardsArrow, + (fontInfo.isMonospace && !options.get(EditorOption.disableMonospaceOptimizations)), + fontInfo.canUseHalfwidthRightwardsArrow, lineContent, false, isBasicASCII, @@ -781,7 +780,7 @@ export class DiffReview extends Disposable { lineTokens, [], tabSize, - config.fontInfo.spaceWidth, + fontInfo.spaceWidth, options.get(EditorOption.stopRenderingLineAfter), options.get(EditorOption.renderWhitespace), options.get(EditorOption.renderControlCharacters), diff --git a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts index 2f36d8e9765..5e63eaa0669 100644 --- a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts +++ b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts @@ -8,7 +8,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; -import { IConfigurationChangedEvent, IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; @@ -44,14 +44,14 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget { // Overwrite parent's options super.updateOptions(this._overwriteOptions); - this._register(parentEditor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => this._onParentConfigurationChanged(e))); + this._register(parentEditor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => this._onParentConfigurationChanged(e))); } getParentEditor(): ICodeEditor { return this._parentEditor; } - private _onParentConfigurationChanged(e: IConfigurationChangedEvent): void { + private _onParentConfigurationChanged(e: ConfigurationChangedEvent): void { super.updateOptions(this._parentEditor.getRawConfiguration()); super.updateOptions(this._overwriteOptions); } @@ -95,7 +95,7 @@ export class EmbeddedDiffEditorWidget extends DiffEditorWidget { return this._parentEditor; } - private _onParentConfigurationChanged(e: IConfigurationChangedEvent): void { + private _onParentConfigurationChanged(e: ConfigurationChangedEvent): void { super.updateOptions(this._parentEditor.getRawConfiguration()); super.updateOptions(this._overwriteOptions); } diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 686808bbd1c..f751b1bcbcf 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -8,7 +8,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; -import { IEditorOptions, RawEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ChangedEditorOptions, InternalEditorOptions, IConfigurationChangedEvent, InternalEditorOptionsFactory, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -60,21 +60,46 @@ export interface IEnvConfiguration { const hasOwnProperty = Object.hasOwnProperty; -export class EditorConfiguration2 { - public static readOptions(options: IEditorOptions): RawEditorOptions { - // console.log(`parseOptions`, options); +class RawEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOption): T | undefined { + return this._values[id]; + } + public _write(id: EditorOption, value: T | undefined): void { + this._values[id] = value; + } +} + +class EditorConfiguration2 { + public static readOptions(_options: IEditorOptions): RawEditorOptions { + const options: { [key: string]: any; } = _options; const result = new RawEditorOptions(); for (const editorOption of editorOptionsRegistry) { - result._write(editorOption.id, editorOption.read(options)); + const value = options[editorOption.name]; + result._write(editorOption.id, value); } return result; } - public static mixOptions(a: RawEditorOptions, b: IEditorOptions): RawEditorOptions { - // console.log(`mixOptions`, a, b); + private static _mix(a: any, b: any): any { + switch (typeof b) { + case 'bigint': return b; + case 'boolean': return b; + case 'function': return b; + case 'number': return b; + case 'object': return (Array.isArray(b) || typeof a !== 'object' ? b : objects.mixin(objects.mixin({}, a), b)); + case 'string': return b; + default: + return a; + } + } + + public static mixOptions(a: RawEditorOptions, _b: IEditorOptions): RawEditorOptions { + const b: { [key: string]: any; } = _b; const result = new RawEditorOptions(); for (const editorOption of editorOptionsRegistry) { - result._write(editorOption.id, editorOption.mix(a._read(editorOption.id), editorOption.read(b))); + const bValue = b[editorOption.name]; + result._write(editorOption.id, EditorConfiguration2._mix(a._read(editorOption.id), bValue)); } return result; } @@ -97,18 +122,18 @@ export class EditorConfiguration2 { return result; } - public static checkEquals(a: ComputedEditorOptions, b: ComputedEditorOptions): ChangedEditorOptions | null { + public static checkEquals(a: ComputedEditorOptions, b: ComputedEditorOptions): ConfigurationChangedEvent | null { // console.log(`equals`, a, b); - const result = new ChangedEditorOptions(); + const result: boolean[] = []; let somethingChanged = false; for (const editorOption of editorOptionsRegistry) { const changed = !editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); - result._write(editorOption.id, changed); + result[editorOption.id] = changed; if (changed) { somethingChanged = true; } } - return (somethingChanged ? result : null); + return (somethingChanged ? new ConfigurationChangedEvent(result) : null); } } @@ -186,12 +211,11 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed public readonly isSimpleWidget: boolean; protected _rawOptions: IEditorOptions; - public editor!: InternalEditorOptions; private _isDominatedByLongLines: boolean; private _lineNumbersDigitCount: number; - private _onDidChange = this._register(new Emitter()); - public readonly onDidChange: Event = this._onDidChange.event; + private _onDidChange = this._register(new Emitter()); + public readonly onDidChange: Event = this._onDidChange.event; private _rawOptions2: RawEditorOptions; protected _validatedOptions2: ValidatedEditorOptions; @@ -229,21 +253,19 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed } protected _recomputeOptions(): void { - const oldOptions = this.editor; - const oldOptions2 = this.options; - const [newOptions, newOptions2] = this._computeInternalOptions(); + const oldOptions = this.options; + const newOptions = this._computeInternalOptions(); - const changeEvent = (oldOptions2 ? EditorConfiguration2.checkEquals(oldOptions2, newOptions2) : null); + const changeEvent = (oldOptions ? EditorConfiguration2.checkEquals(oldOptions, newOptions) : null); - if (oldOptions && oldOptions.equals(newOptions) && oldOptions2 && changeEvent === null) { + if (oldOptions && changeEvent === null) { return; } - this.editor = newOptions; - this.options = newOptions2; + this.options = newOptions; - if (oldOptions) { - this._onDidChange.fire(oldOptions.createChangeEvent(newOptions, changeEvent)); + if (changeEvent) { + this._onDidChange.fire(changeEvent); } } @@ -251,9 +273,9 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return this._rawOptions; } - private _computeInternalOptions(): [InternalEditorOptions, ComputedEditorOptions] { + private _computeInternalOptions(): ComputedEditorOptions { const partialEnv = this._getEnvConfiguration(); - const bareFontInfo = BareFontInfo.createFromRawSettings(this._rawOptions, partialEnv.zoomLevel, this.isSimpleWidget); + const bareFontInfo = BareFontInfo.createFromValidatedSettings(this._validatedOptions2, partialEnv.zoomLevel, this.isSimpleWidget); const env: IEnvironmentalOptions = { outerWidth: partialEnv.outerWidth, outerHeight: partialEnv.outerHeight, @@ -266,9 +288,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; - const r = InternalEditorOptionsFactory.createInternalEditorOptions(env); - const r2 = EditorConfiguration2.computeOptions(this._validatedOptions2, env); - return [r, r2]; + return EditorConfiguration2.computeOptions(this._validatedOptions2, env); } private static _primitiveArrayEquals(a: any[], b: any[]): boolean { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index c88fa2db71c..a5ff1b80768 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -700,7 +700,7 @@ export interface IEditorOptions { /** * The font weight */ - fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | 'initial' | 'inherit' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'; + fontWeight?: string; /** * The font size */ @@ -728,6 +728,10 @@ export type IExtendedEditorOptions = IEditorOptions & { * Do not use, this is a computed option. */ pixelRatio?: undefined; + /** + * Do not use, this is a computed option. + */ + fontInfo?: undefined; /** * Do not use, this is a computed option. */ @@ -868,87 +872,41 @@ export enum TextEditorCursorStyle { */ 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'; + 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; - } -} - -/** - * Internal configuration options (transformed or computed) for the editor. - */ -export class InternalEditorOptions { - readonly _internalEditorOptionsBrand: void; - - // ---- grouped options - readonly fontInfo: FontInfo; - - /** - * @internal - */ - constructor(source: { - fontInfo: FontInfo; - }) { - this.fontInfo = source.fontInfo; - } - - /** - * @internal - */ - public equals(other: InternalEditorOptions): boolean { - return ( - this.fontInfo.equals(other.fontInfo) - ); - } - - /** - * @internal - */ - public createChangeEvent(newOpts: InternalEditorOptions, changeEvent: ChangedEditorOptions | null): IConfigurationChangedEvent { - return { - hasChanged: (id: EditorOption) => { - if (!changeEvent) { - return false; - } - return changeEvent.get(id); - }, - fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)), - }; + 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; } } /** * An event describing that the configuration of the editor has changed. */ -export interface IConfigurationChangedEvent { - hasChanged(id: EditorOption): boolean; - readonly fontInfo: boolean; +export class ConfigurationChangedEvent { + private readonly _values: boolean[]; + /** + * @internal + */ + constructor(values: boolean[]) { + this._values = values; + } + + public hasChanged(id: EditorOption): boolean { + return this._values[id]; + } } export interface IEnvironmentalOptions { @@ -992,6 +950,16 @@ function _stringSet(value: T | undefined, defaultValue: T, allowedValues: T[] return value; } +function _clamp(n: number, min: number, max: number): number { + if (n < min) { + return min; + } + if (n > max) { + return max; + } + return n; +} + function _clampedInt(value: any, defaultValue: number, minimum: number, maximum: number): number { let r: number; if (typeof value === 'undefined') { @@ -1008,11 +976,14 @@ function _clampedInt(value: any, defaultValue: number, minimum: number, maximum: } function _float(value: any, defaultValue: number): number { - let r = parseFloat(value); - if (isNaN(r)) { - r = defaultValue; + if (typeof value === 'number') { + return value; } - return r; + if (typeof value === 'undefined') { + return defaultValue; + } + const r = parseFloat(value); + return (isNaN(r) ? defaultValue : r); } function _wrappingIndentFromString(wrappingIndent: 'none' | 'same' | 'indent' | 'deepIndent'): WrappingIndent { @@ -1026,16 +997,11 @@ function _wrappingIndentFromString(wrappingIndent: 'none' | 'same' | 'indent' | 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; + 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; } } @@ -1044,24 +1010,9 @@ function _scrollbarVisibilityFromString(visibility: string | undefined, defaultV return defaultValue; } switch (visibility) { - case 'hidden': - return ScrollbarVisibility.Hidden; - case 'visible': - return ScrollbarVisibility.Visible; - default: - return ScrollbarVisibility.Auto; - } -} - -/** - * @internal - */ -export class InternalEditorOptionsFactory { - - public static createInternalEditorOptions(env: IEnvironmentalOptions) { - return new InternalEditorOptions({ - fontInfo: env.fontInfo, - }); + case 'hidden': return ScrollbarVisibility.Hidden; + case 'visible': return ScrollbarVisibility.Visible; + default: return ScrollbarVisibility.Auto; } } @@ -1134,19 +1085,6 @@ export interface IRawEditorOptionsBag extends IExtendedEditorOptions { [key: string]: any; } -/** - * @internal - */ -export class RawEditorOptions { - private readonly _values: any[] = []; - public _read(id: EditorOption): T | undefined { - return this._values[id]; - } - public _write(id: EditorOption, value: T | undefined): void { - this._values[id] = value; - } -} - /** * @internal */ @@ -1183,19 +1121,6 @@ export class ComputedEditorOptions implements IComputedEditorOptions { } } -/** - * @internal - */ -export class ChangedEditorOptions { - private readonly _values: boolean[] = []; - public get(id: EditorOption): boolean { - return this._values[id]; - } - public _write(id: EditorOption, value: boolean): void { - this._values[id] = value; - } -} - //#region IEditorOption /** @@ -1211,14 +1136,6 @@ export interface IEditorOptionthis.name]; - } - public mix(a: IExtendedEditorOptions[K2] | undefined, b: IExtendedEditorOptions[K2] | undefined): IExtendedEditorOptions[K2] | undefined { - switch (typeof b) { - case 'bigint': return b; - case 'boolean': return b; - case 'function': return b; - case 'number': return b; - case 'object': return (Array.isArray(b) || typeof a !== 'object' ? b : objects.mixin(objects.mixin({}, a), b)); - case 'string': return b; - default: - return a; - } - } public abstract validate(input: IExtendedEditorOptions[K2] | undefined): T2; public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; public equals(a: T3, b: T3): boolean { @@ -1652,10 +1554,7 @@ class EditorPixelRatio> extends BaseEditorOption { - public validate(input: number | undefined): number { - return this.defaultValue; - } +class EditorLineHeight> extends EditorIntOption { public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { return env.fontInfo.lineHeight; } @@ -1663,6 +1562,22 @@ class EditorLineHeight> extends BaseEditorOption { + public validate(input: number | undefined): undefined { + return undefined; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): FontInfo { + return env.fontInfo; + } + public equals(a: FontInfo, b: FontInfo): boolean { + return a.equals(b); + } +} + +//#endregion + //#region emptySelectionClipboard class EditorEmptySelectionClipboard> extends EditorBooleanOption { @@ -2265,9 +2180,6 @@ export interface EditorWrappingInfo { } class EditorWrappingInfoComputer> extends BaseEditorOption { - public mix(a: undefined, b: undefined): undefined { - return undefined; - } public validate(input: undefined): undefined { return undefined; } @@ -2388,7 +2300,11 @@ export const enum EditorOption { fixedOverflowWidgets, folding, foldingStrategy, + fontFamily, + fontInfo, fontLigatures, + fontSize, + fontWeight, formatOnPaste, formatOnType, glyphMargin, @@ -2397,6 +2313,7 @@ export const enum EditorOption { highlightActiveIndentGuide, hover, inDiffEditor, + letterSpacing, lightbulb, lineDecorationsWidth, lineHeight, @@ -2494,7 +2411,11 @@ export const EditorOptions = { fixedOverflowWidgets: registerEditorOption(new EditorBooleanOption(EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false)), folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), foldingStrategy: registerEditorOption(new EditorEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto', ['auto', 'indentation'], (x: 'auto' | 'indentation') => x)), + fontFamily: registerEditorOption(new EditorStringOption(EditorOption.fontFamily, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily)), + fontInfo: registerEditorOption(new EditorFontInfo(EditorOption.fontInfo, 'fontInfo', undefined)), fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), + fontSize: registerEditorOption(new EditorFloatOption(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize, x => _clamp(x, 0, 100))), + fontWeight: registerEditorOption(new EditorStringOption(EditorOption.fontWeight, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight)), formatOnPaste: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnPaste, 'formatOnPaste', false)), formatOnType: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnType, 'formatOnType', false)), glyphMargin: registerEditorOption(new EditorBooleanOption(EditorOption.glyphMargin, 'glyphMargin', true)), @@ -2509,11 +2430,12 @@ export const EditorOptions = { sticky: true })), inDiffEditor: registerEditorOption(new EditorBooleanOption(EditorOption.inDiffEditor, 'inDiffEditor', false)), + letterSpacing: registerEditorOption(new EditorFloatOption(EditorOption.letterSpacing, 'letterSpacing', EDITOR_FONT_DEFAULTS.letterSpacing, x => _clamp(x, -5, 20))), lightbulb: registerEditorOption(new EditorLightbulb(EditorOption.lightbulb, 'lightbulb', { enabled: true })), lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), - lineHeight: registerEditorOption(new EditorLineHeight(EditorOption.lineHeight, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight)), + lineHeight: registerEditorOption(new EditorLineHeight(EditorOption.lineHeight, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight, 0, 150)), lineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), links: registerEditorOption(new EditorBooleanOption(EditorOption.links, 'links', true)), diff --git a/src/vs/editor/common/config/fontInfo.ts b/src/vs/editor/common/config/fontInfo.ts index c69ea3f3320..b23edab7d90 100644 --- a/src/vs/editor/common/config/fontInfo.ts +++ b/src/vs/editor/common/config/fontInfo.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as platform from 'vs/base/common/platform'; -import { EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions'; +import { EDITOR_FONT_DEFAULTS, EditorOptions, ValidatedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; /** @@ -17,56 +17,7 @@ const GOLDEN_LINE_HEIGHT_RATIO = platform.isMacintosh ? 1.5 : 1.35; * Font settings maximum and minimum limits */ const MINIMUM_FONT_SIZE = 8; -const MAXIMUM_FONT_SIZE = 100; const MINIMUM_LINE_HEIGHT = 8; -const MAXIMUM_LINE_HEIGHT = 150; -const MINIMUM_LETTER_SPACING = -5; -const MAXIMUM_LETTER_SPACING = 20; - -function safeParseFloat(n: number | string | undefined, defaultValue: number): number { - if (typeof n === 'number') { - return n; - } - if (typeof n === 'undefined') { - return defaultValue; - } - let r = parseFloat(n); - if (isNaN(r)) { - return defaultValue; - } - return r; -} - -function safeParseInt(n: number | string | undefined, defaultValue: number): number { - if (typeof n === 'number') { - return Math.round(n); - } - if (typeof n === 'undefined') { - return defaultValue; - } - let r = parseInt(n); - if (isNaN(r)) { - return defaultValue; - } - return r; -} - -function clamp(n: number, min: number, max: number): number { - if (n < min) { - return min; - } - if (n > max) { - return max; - } - return n; -} - -function _string(value: any, defaultValue: string): string { - if (typeof value !== 'string') { - return defaultValue; - } - return value; -} export class BareFontInfo { readonly _bareFontInfoBrand: void; @@ -74,38 +25,44 @@ export class BareFontInfo { /** * @internal */ - public static createFromRawSettings(opts: { - fontFamily?: string; - fontWeight?: string; - fontSize?: number | string; - lineHeight?: number | string; - letterSpacing?: number | string; - }, zoomLevel: number, ignoreEditorZoom: boolean = false): BareFontInfo { + public static createFromValidatedSettings(options: ValidatedEditorOptions, zoomLevel: number, ignoreEditorZoom: boolean): BareFontInfo { + const fontFamily = options.get(EditorOption.fontFamily); + const fontWeight = options.get(EditorOption.fontWeight); + const fontSize = options.get(EditorOption.fontSize); + const lineHeight = options.get(EditorOption.lineHeight); + const letterSpacing = options.get(EditorOption.letterSpacing); + return BareFontInfo._create(fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, zoomLevel, ignoreEditorZoom); + } - let fontFamily = _string(opts.fontFamily, EDITOR_FONT_DEFAULTS.fontFamily); - let fontWeight = _string(opts.fontWeight, EDITOR_FONT_DEFAULTS.fontWeight); + /** + * @internal + */ + public static createFromRawSettings(opts: { fontFamily?: string; fontWeight?: string; fontSize?: number; lineHeight?: number; letterSpacing?: number; }, zoomLevel: number, ignoreEditorZoom: boolean = false): BareFontInfo { + const fontFamily = EditorOptions.fontFamily.validate(opts.fontFamily); + const fontWeight = EditorOptions.fontWeight.validate(opts.fontWeight); + const fontSize = EditorOptions.fontSize.validate(opts.fontSize); + const lineHeight = EditorOptions.lineHeight.validate(opts.lineHeight); + const letterSpacing = EditorOptions.letterSpacing.validate(opts.letterSpacing); + return BareFontInfo._create(fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, zoomLevel, ignoreEditorZoom); + } - - let fontSize = safeParseFloat(opts.fontSize, EDITOR_FONT_DEFAULTS.fontSize); - fontSize = clamp(fontSize, 0, MAXIMUM_FONT_SIZE); + /** + * @internal + */ + private static _create(fontFamily: string, fontWeight: string, fontSize: number, lineHeight: number, letterSpacing: number, zoomLevel: number, ignoreEditorZoom: boolean): BareFontInfo { if (fontSize === 0) { fontSize = EDITOR_FONT_DEFAULTS.fontSize; } else if (fontSize < MINIMUM_FONT_SIZE) { fontSize = MINIMUM_FONT_SIZE; } - let lineHeight = safeParseInt(opts.lineHeight, 0); - lineHeight = clamp(lineHeight, 0, MAXIMUM_LINE_HEIGHT); if (lineHeight === 0) { lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize); } else if (lineHeight < MINIMUM_LINE_HEIGHT) { lineHeight = MINIMUM_LINE_HEIGHT; } - let letterSpacing = safeParseFloat(opts.letterSpacing, 0); - letterSpacing = clamp(letterSpacing, MINIMUM_LETTER_SPACING, MAXIMUM_LETTER_SPACING); - - let editorZoomLevelMultiplier = 1 + (ignoreEditorZoom ? 0 : EditorZoom.getZoomLevel() * 0.1); + const editorZoomLevelMultiplier = 1 + (ignoreEditorZoom ? 0 : EditorZoom.getZoomLevel() * 0.1); fontSize *= editorZoomLevelMultiplier; lineHeight *= editorZoomLevelMultiplier; diff --git a/src/vs/editor/common/controller/cursorCommon.ts b/src/vs/editor/common/controller/cursorCommon.ts index dd85df4cc43..168234965e9 100644 --- a/src/vs/editor/common/controller/cursorCommon.ts +++ b/src/vs/editor/common/controller/cursorCommon.ts @@ -6,7 +6,7 @@ import { CharCode } from 'vs/base/common/charCode'; import { onUnexpectedError } from 'vs/base/common/errors'; import * as strings from 'vs/base/common/strings'; -import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, IConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, ConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption } from 'vs/editor/common/config/editorOptions'; import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -110,7 +110,7 @@ export class CursorConfiguration { private readonly _languageIdentifier: LanguageIdentifier; private _electricChars: { [key: string]: boolean; } | null; - public static shouldRecreate(e: IConfigurationChangedEvent): boolean { + public static shouldRecreate(e: ConfigurationChangedEvent): boolean { return ( e.hasChanged(EditorOption.layoutInfo) || e.hasChanged(EditorOption.wordSeparators) diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 6c954159234..e11482fa25b 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -6,7 +6,7 @@ import { IMarkdownString } from 'vs/base/common/htmlContent'; import { IDisposable } from 'vs/base/common/lifecycle'; import { URI, UriComponents } from 'vs/base/common/uri'; -import * as editorOptions from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, IComputedEditorOptions, IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ISelection, Selection } from 'vs/editor/common/core/selection'; @@ -149,14 +149,13 @@ export interface ILineChange extends IChange { * @internal */ export interface IConfiguration extends IDisposable { - onDidChange(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable; + onDidChange(listener: (e: ConfigurationChangedEvent) => void): IDisposable; - readonly editor: editorOptions.InternalEditorOptions; - readonly options: editorOptions.IComputedEditorOptions; + readonly options: IComputedEditorOptions; setMaxLineNumber(maxLineNumber: number): void; - updateOptions(newOptions: editorOptions.IEditorOptions): void; - getRawOptions(): editorOptions.IEditorOptions; + updateOptions(newOptions: IEditorOptions): void; + getRawOptions(): IEditorOptions; observeReferenceElement(dimension?: IDimension): void; setIsDominatedByLongLines(isDominatedByLongLines: boolean): void; } @@ -264,7 +263,7 @@ export interface IEditor { /** * Update the editor's options after the editor has been created. */ - updateOptions(newOptions: editorOptions.IEditorOptions): void; + updateOptions(newOptions: IEditorOptions): void; /** * Indicates that the editor becomes visible. diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 268d0bfada7..9a5f179dfab 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -467,76 +467,81 @@ export enum EditorOption { fixedOverflowWidgets = 24, folding = 25, foldingStrategy = 26, - fontLigatures = 27, - formatOnPaste = 28, - formatOnType = 29, - glyphMargin = 30, - gotoLocation = 31, - hideCursorInOverviewRuler = 32, - highlightActiveIndentGuide = 33, - hover = 34, - inDiffEditor = 35, - lightbulb = 36, - lineDecorationsWidth = 37, - lineHeight = 38, - lineNumbers = 39, - lineNumbersMinChars = 40, - links = 41, - matchBrackets = 42, - minimap = 43, - mouseStyle = 44, - mouseWheelScrollSensitivity = 45, - mouseWheelZoom = 46, - multiCursorMergeOverlapping = 47, - multiCursorModifier = 48, - occurrencesHighlight = 49, - overviewRulerBorder = 50, - overviewRulerLanes = 51, - parameterHints = 52, - quickSuggestions = 53, - quickSuggestionsDelay = 54, - readOnly = 55, - renderControlCharacters = 56, - renderIndentGuides = 57, - renderFinalNewline = 58, - renderLineHighlight = 59, - renderWhitespace = 60, - revealHorizontalRightPadding = 61, - roundedSelection = 62, - rulers = 63, - scrollbar = 64, - scrollBeyondLastColumn = 65, - scrollBeyondLastLine = 66, - selectionClipboard = 67, - selectionHighlight = 68, - selectOnLineNumbers = 69, - showFoldingControls = 70, - showUnused = 71, - snippetSuggestions = 72, - smoothScrolling = 73, - stopRenderingLineAfter = 74, - suggestFontSize = 75, - suggestLineHeight = 76, - suggestOnTriggerCharacters = 77, - suggestSelection = 78, - tabCompletion = 79, - useTabStops = 80, - wordSeparators = 81, - wordWrap = 82, - wordWrapBreakAfterCharacters = 83, - wordWrapBreakBeforeCharacters = 84, - wordWrapBreakObtrusiveCharacters = 85, - wordWrapColumn = 86, - wordWrapMinified = 87, - wrappingIndent = 88, - ariaLabel = 89, - disableMonospaceOptimizations = 90, - editorClassName = 91, - pixelRatio = 92, - tabFocusMode = 93, - suggest = 94, - layoutInfo = 95, - wrappingInfo = 96 + fontFamily = 27, + fontInfo = 28, + fontLigatures = 29, + fontSize = 30, + fontWeight = 31, + formatOnPaste = 32, + formatOnType = 33, + glyphMargin = 34, + gotoLocation = 35, + hideCursorInOverviewRuler = 36, + highlightActiveIndentGuide = 37, + hover = 38, + inDiffEditor = 39, + letterSpacing = 40, + lightbulb = 41, + lineDecorationsWidth = 42, + lineHeight = 43, + lineNumbers = 44, + lineNumbersMinChars = 45, + links = 46, + matchBrackets = 47, + minimap = 48, + mouseStyle = 49, + mouseWheelScrollSensitivity = 50, + mouseWheelZoom = 51, + multiCursorMergeOverlapping = 52, + multiCursorModifier = 53, + occurrencesHighlight = 54, + overviewRulerBorder = 55, + overviewRulerLanes = 56, + parameterHints = 57, + quickSuggestions = 58, + quickSuggestionsDelay = 59, + readOnly = 60, + renderControlCharacters = 61, + renderIndentGuides = 62, + renderFinalNewline = 63, + renderLineHighlight = 64, + renderWhitespace = 65, + revealHorizontalRightPadding = 66, + roundedSelection = 67, + rulers = 68, + scrollbar = 69, + scrollBeyondLastColumn = 70, + scrollBeyondLastLine = 71, + selectionClipboard = 72, + selectionHighlight = 73, + selectOnLineNumbers = 74, + showFoldingControls = 75, + showUnused = 76, + snippetSuggestions = 77, + smoothScrolling = 78, + stopRenderingLineAfter = 79, + suggestFontSize = 80, + suggestLineHeight = 81, + suggestOnTriggerCharacters = 82, + suggestSelection = 83, + tabCompletion = 84, + useTabStops = 85, + wordSeparators = 86, + wordWrap = 87, + wordWrapBreakAfterCharacters = 88, + wordWrapBreakBeforeCharacters = 89, + wordWrapBreakObtrusiveCharacters = 90, + wordWrapColumn = 91, + wordWrapMinified = 92, + wrappingIndent = 93, + ariaLabel = 94, + disableMonospaceOptimizations = 95, + editorClassName = 96, + pixelRatio = 97, + tabFocusMode = 98, + suggest = 99, + layoutInfo = 100, + wrappingInfo = 101 } /** diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index 05d9e6b0db8..55c455808ad 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -6,7 +6,7 @@ import * as errors from 'vs/base/common/errors'; import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { ScrollEvent } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { ScrollType } from 'vs/editor/common/editorCommon'; @@ -34,12 +34,10 @@ export class ViewConfigurationChangedEvent { public readonly type = ViewEventType.ViewConfigurationChanged; - public readonly _source: IConfigurationChangedEvent; - public readonly fontInfo: boolean; + public readonly _source: ConfigurationChangedEvent; - constructor(source: IConfigurationChangedEvent) { + constructor(source: ConfigurationChangedEvent) { this._source = source; - this.fontInfo = source.fontInfo; } public hasChanged(id: EditorOption): boolean { diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 2a4f9355ac8..c06d7220a42 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -6,7 +6,7 @@ import { Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { IScrollDimensions, IScrollPosition, ScrollEvent, Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { LinesLayout } from 'vs/editor/common/viewLayout/linesLayout'; import { IPartialViewLinesViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'; @@ -58,7 +58,7 @@ export class ViewLayout extends Disposable implements IViewLayout { // ---- begin view event handlers - public onConfigurationChanged(e: IConfigurationChangedEvent): void { + public onConfigurationChanged(e: ConfigurationChangedEvent): void { const options = this._configuration.options; if (e.hasChanged(EditorOption.lineHeight)) { this._linesLayout.setLineHeight(options.get(EditorOption.lineHeight)); @@ -150,7 +150,7 @@ export class ViewLayout extends Disposable implements IViewLayout { const wrappingInfo = options.get(EditorOption.wrappingInfo); let isViewportWrapping = wrappingInfo.isViewportWrapping; if (!isViewportWrapping) { - const extraHorizontalSpace = options.get(EditorOption.scrollBeyondLastColumn) * this._configuration.editor.fontInfo.typicalHalfwidthCharacterWidth; + const extraHorizontalSpace = options.get(EditorOption.scrollBeyondLastColumn) * options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth; const whitespaceMinWidth = this._linesLayout.getWhitespaceMinWidth(); return Math.max(maxLineWidth + extraHorizontalSpace, viewportWidth, whitespaceMinWidth); } diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 055cf6ae0d1..01e9f36723c 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import * as strings from 'vs/base/common/strings'; -import { IConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IPosition, Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -59,9 +59,9 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel this.lines = new IdentityLinesCollection(this.model); } else { - const conf = this.configuration.editor; const options = this.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); + const fontInfo = options.get(EditorOption.fontInfo); const wordWrapBreakAfterCharacters = options.get(EditorOption.wordWrapBreakAfterCharacters); const wordWrapBreakBeforeCharacters = options.get(EditorOption.wordWrapBreakBeforeCharacters); const wordWrapBreakObtrusiveCharacters = options.get(EditorOption.wordWrapBreakObtrusiveCharacters); @@ -78,7 +78,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel hardWrappingLineMapperFactory, this.model.getOptions().tabSize, wrappingInfo.wrappingColumn, - conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth, + fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent ); } @@ -142,7 +142,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel this.hasFocus = hasFocus; } - private _onConfigurationChanged(eventsCollector: viewEvents.ViewEventsCollector, e: IConfigurationChangedEvent): void { + private _onConfigurationChanged(eventsCollector: viewEvents.ViewEventsCollector, e: ConfigurationChangedEvent): void { // We might need to restore the current centered view range, so save it (if available) let previousViewportStartModelPosition: Position | null = null; @@ -152,12 +152,12 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel } let restorePreviousViewportStart = false; - const conf = this.configuration.editor; const options = this.configuration.options; const wrappingInfo = options.get(EditorOption.wrappingInfo); + const fontInfo = options.get(EditorOption.fontInfo); const wrappingIndent = options.get(EditorOption.wrappingIndent); - if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, conf.fontInfo.typicalFullwidthCharacterWidth / conf.fontInfo.typicalHalfwidthCharacterWidth)) { + if (this.lines.setWrappingSettings(wrappingIndent, wrappingInfo.wrappingColumn, fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth)) { eventsCollector.emit(new viewEvents.ViewFlushedEvent()); eventsCollector.emit(new viewEvents.ViewLineMappingChangedEvent()); eventsCollector.emit(new viewEvents.ViewDecorationsChangedEvent()); @@ -675,7 +675,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel range = new Range(lineNumber, this.model.getLineMinColumn(lineNumber), lineNumber, this.model.getLineMaxColumn(lineNumber)); } - const fontInfo = this.configuration.editor.fontInfo; + const fontInfo = this.configuration.options.get(EditorOption.fontInfo); const colorMap = this._getColorMap(); const fontFamily = fontInfo.fontFamily === EDITOR_FONT_DEFAULTS.fontFamily ? fontInfo.fontFamily : `'${fontInfo.fontFamily}', ${EDITOR_FONT_DEFAULTS.fontFamily}`; diff --git a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts index f4a3bbf228a..d5d8dac4981 100644 --- a/src/vs/editor/contrib/codeAction/lightBulbWidget.ts +++ b/src/vs/editor/contrib/codeAction/lightBulbWidget.ts @@ -138,7 +138,6 @@ export class LightBulbWidget extends Disposable implements IContentWidget { return this.hide(); } - const config = this._editor.getConfiguration(); const options = this._editor.getOptions(); if (!options.get(EditorOption.lightbulb).enabled) { return this.hide(); @@ -151,9 +150,10 @@ export class LightBulbWidget extends Disposable implements IContentWidget { } const tabSize = model.getOptions().tabSize; + const fontInfo = options.get(EditorOption.fontInfo); const lineContent = model.getLineContent(lineNumber); const indent = TextModel.computeIndentLevel(lineContent, tabSize); - const lineHasSpace = config.fontInfo.spaceWidth * indent > 22; + const lineHasSpace = fontInfo.spaceWidth * indent > 22; const isFolded = (lineNumber: number) => { return lineNumber > 2 && this._editor.getTopForLineNumber(lineNumber) === this._editor.getTopForLineNumber(lineNumber - 1); }; @@ -164,7 +164,7 @@ export class LightBulbWidget extends Disposable implements IContentWidget { effectiveLineNumber -= 1; } else if (!isFolded(lineNumber + 1)) { effectiveLineNumber += 1; - } else if (column * config.fontInfo.spaceWidth < 22) { + } else if (column * fontInfo.spaceWidth < 22) { // cannot show lightbulb above/below and showing // it inline would overlay the cursor... return this.hide(); diff --git a/src/vs/editor/contrib/codelens/codelensController.ts b/src/vs/editor/contrib/codelens/codelensController.ts index 72e341842a8..6e89d47039c 100644 --- a/src/vs/editor/contrib/codelens/codelensController.ts +++ b/src/vs/editor/contrib/codelens/codelensController.ts @@ -205,7 +205,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { } })); this._localToDispose.add(this._editor.onDidChangeConfiguration(e => { - if (e.fontInfo) { + if (e.hasChanged(EditorOption.fontInfo)) { for (const lens of this._lenses) { lens.updateHeight(); } diff --git a/src/vs/editor/contrib/codelens/codelensWidget.ts b/src/vs/editor/contrib/codelens/codelensWidget.ts index 516f971af2b..42cf0deb06e 100644 --- a/src/vs/editor/contrib/codelens/codelensWidget.ts +++ b/src/vs/editor/contrib/codelens/codelensWidget.ts @@ -82,7 +82,7 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget { updateHeight(): void { const options = this._editor.getOptions(); - const { fontInfo } = this._editor.getConfiguration(); + const fontInfo = options.get(EditorOption.fontInfo); const lineHeight = options.get(EditorOption.lineHeight); this._domNode.style.height = `${Math.round(lineHeight * 1.1)}px`; this._domNode.style.lineHeight = `${lineHeight}px`; diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index 9a399ea3aeb..a05f0191e31 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -23,7 +23,7 @@ import { toDisposable } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import * as strings from 'vs/base/common/strings'; import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_REPLACE_INPUT_FOCUSED, FIND_IDS, MATCHES_LIMIT } from 'vs/editor/contrib/find/findModel'; import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/findState'; @@ -176,7 +176,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas this._tryUpdateWidgetWidth(); this._findInput.inputBox.layout(); - this._register(this._codeEditor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { + this._register(this._codeEditor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { if (e.hasChanged(EditorOption.readOnly)) { if (this._codeEditor.getOption(EditorOption.readOnly)) { // Hide replace part if editor becomes read only diff --git a/src/vs/editor/contrib/folding/folding.ts b/src/vs/editor/contrib/folding/folding.ts index 4ab5ce4decc..f0ae51e1955 100644 --- a/src/vs/editor/contrib/folding/folding.ts +++ b/src/vs/editor/contrib/folding/folding.ts @@ -18,7 +18,7 @@ import { FoldingModel, setCollapseStateAtLevel, CollapseMemento, setCollapseStat import { FoldingDecorationProvider } from './foldingDecorations'; import { FoldingRegions, FoldingRegion } from './foldingRanges'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { IMarginData, IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { HiddenRangeModel } from 'vs/editor/contrib/folding/hiddenRangeModel'; import { IRange } from 'vs/editor/common/core/range'; @@ -109,7 +109,7 @@ export class FoldingController extends Disposable implements IEditorContribution this._register(this.editor.onDidChangeModel(() => this.onModelChanged())); - this._register(this.editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { + this._register(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { if (e.hasChanged(EditorOption.folding) || e.hasChanged(EditorOption.showFoldingControls) || e.hasChanged(EditorOption.foldingStrategy)) { let oldIsEnabled = this._isEnabled; const options = this.editor.getOptions(); diff --git a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts index dd7414923a7..39fe2e80364 100644 --- a/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts +++ b/src/vs/editor/contrib/gotoError/gotoErrorWidget.ts @@ -147,7 +147,7 @@ class MessageWidget { } } - const fontInfo = this._editor.getConfiguration().fontInfo; + const fontInfo = this._editor.getOption(EditorOption.fontInfo); const scrollWidth = Math.ceil(fontInfo.typicalFullwidthCharacterWidth * this._longestLineLength * 0.75); const scrollHeight = fontInfo.lineHeight * this._lines; this._scrollable.setScrollDimensions({ scrollWidth, scrollHeight }); diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index b89e96001d3..215ddd5844c 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -11,7 +11,7 @@ import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution, IScrollEvent } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -74,7 +74,7 @@ export class ModesHoverController implements IEditorContribution { this._hookEvents(); - this._didChangeConfigurationHandler = this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { + this._didChangeConfigurationHandler = this._editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { if (e.hasChanged(EditorOption.hover)) { this._hideWidgets(); this._unhookEvents(); @@ -164,7 +164,7 @@ export class ModesHoverController implements IEditorContribution { } if (targetType === MouseTargetType.CONTENT_EMPTY) { - const epsilon = this._editor.getConfiguration().fontInfo.typicalHalfwidthCharacterWidth / 2; + const epsilon = this._editor.getOption(EditorOption.fontInfo).typicalHalfwidthCharacterWidth / 2; const data = mouseEvent.target.detail; if (data && !data.isAfterLines && typeof data.horizontalDistanceToText === 'number' && data.horizontalDistanceToText < epsilon) { // Let hover kick in even when the mouse is technically in the empty area after a line, given the distance is small enough diff --git a/src/vs/editor/contrib/hover/hoverWidgets.ts b/src/vs/editor/contrib/hover/hoverWidgets.ts index 96d28a55099..9077e4a9eb0 100644 --- a/src/vs/editor/contrib/hover/hoverWidgets.ts +++ b/src/vs/editor/contrib/hover/hoverWidgets.ts @@ -9,7 +9,7 @@ import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableEle import { Widget } from 'vs/base/browser/ui/widget'; import { KeyCode } from 'vs/base/common/keyCodes'; import { IContentWidget, ICodeEditor, IContentWidgetPosition, ContentWidgetPositionPreference, IOverlayWidget, IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; @@ -61,8 +61,8 @@ export class ContentHoverWidget extends Widget implements IContentWidget { } }); - this._register(this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.fontInfo) { + this._register(this._editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { + if (e.hasChanged(EditorOption.fontInfo)) { this.updateFont(); } })); @@ -152,7 +152,7 @@ export class ContentHoverWidget extends Widget implements IContentWidget { private layout(): void { const height = Math.max(this._editor.getLayoutInfo().height / 4, 250); - const { fontSize, lineHeight } = this._editor.getConfiguration().fontInfo; + const { fontSize, lineHeight } = this._editor.getOption(EditorOption.fontInfo); this._domNode.style.fontSize = `${fontSize}px`; this._domNode.style.lineHeight = `${lineHeight}px`; @@ -182,8 +182,8 @@ export class GlyphHoverWidget extends Widget implements IOverlayWidget { this._showAtLineNumber = -1; - this._register(this._editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.fontInfo) { + this._register(this._editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { + if (e.hasChanged(EditorOption.fontInfo)) { this.updateFont(); } })); diff --git a/src/vs/editor/contrib/markdown/markdownRenderer.ts b/src/vs/editor/contrib/markdown/markdownRenderer.ts index 81f0b2ccc87..e8165ed3e7a 100644 --- a/src/vs/editor/contrib/markdown/markdownRenderer.ts +++ b/src/vs/editor/contrib/markdown/markdownRenderer.ts @@ -15,6 +15,7 @@ import { optional } from 'vs/platform/instantiation/common/instantiation'; import { Event, Emitter } from 'vs/base/common/event'; import { IDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle'; import { TokenizationRegistry } from 'vs/editor/common/modes'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; export interface IMarkdownRenderResult extends IDisposable { element: HTMLElement; @@ -57,7 +58,7 @@ export class MarkdownRenderer extends Disposable { } return tokenizeToString(value, undefined); }).then(code => { - return `${code}`; + return `${code}`; }); }, codeBlockRenderCallback: () => this._onDidRenderCodeBlock.fire(), diff --git a/src/vs/editor/contrib/parameterHints/parameterHintsWidget.ts b/src/vs/editor/contrib/parameterHints/parameterHintsWidget.ts index 0efd0207cb6..696ff9f693a 100644 --- a/src/vs/editor/contrib/parameterHints/parameterHintsWidget.ts +++ b/src/vs/editor/contrib/parameterHints/parameterHintsWidget.ts @@ -11,7 +11,7 @@ import { Event } from 'vs/base/common/event'; import { IDisposable, Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle'; import 'vs/css!./parameterHints'; import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import * as modes from 'vs/editor/common/modes'; import { IModeService } from 'vs/editor/common/services/modeService'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; @@ -105,14 +105,14 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget, })); const updateFont = () => { - const fontInfo = this.editor.getConfiguration().fontInfo; + const fontInfo = this.editor.getOption(EditorOption.fontInfo); this.element.style.fontSize = `${fontInfo.fontSize}px`; }; updateFont(); - this._register(Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) - .filter(e => e.fontInfo) + this._register(Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) + .filter(e => e.hasChanged(EditorOption.fontInfo)) .on(updateFont, null)); this._register(this.editor.onDidLayoutChange(e => this.updateMaxHeight())); @@ -177,7 +177,7 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget, const code = dom.append(this.signature, $('.code')); const hasParameters = signature.parameters.length > 0; - const fontInfo = this.editor.getConfiguration().fontInfo; + const fontInfo = this.editor.getOption(EditorOption.fontInfo); code.style.fontSize = `${fontInfo.fontSize}px`; code.style.fontFamily = fontInfo.fontFamily; diff --git a/src/vs/editor/contrib/rename/renameInputField.ts b/src/vs/editor/contrib/rename/renameInputField.ts index b3c9bea2be8..1113144c6c4 100644 --- a/src/vs/editor/contrib/rename/renameInputField.ts +++ b/src/vs/editor/contrib/rename/renameInputField.ts @@ -41,7 +41,7 @@ export class RenameInputField implements IContentWidget, IDisposable { this._editor.addContentWidget(this); this._disposables.add(editor.onDidChangeConfiguration(e => { - if (e.fontInfo) { + if (e.hasChanged(EditorOption.fontInfo)) { this.updateFont(); } })); @@ -104,7 +104,7 @@ export class RenameInputField implements IContentWidget, IDisposable { return; } - const fontInfo = this._editor.getConfiguration().fontInfo; + const fontInfo = this._editor.getOption(EditorOption.fontInfo); this._inputField.style.fontFamily = fontInfo.fontFamily; this._inputField.style.fontWeight = fontInfo.fontWeight; this._inputField.style.fontSize = `${fontInfo.fontSize}px`; diff --git a/src/vs/editor/contrib/suggest/suggestWidget.ts b/src/vs/editor/contrib/suggest/suggestWidget.ts index 3a9a8eec06f..fa7198d184c 100644 --- a/src/vs/editor/contrib/suggest/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/suggestWidget.ts @@ -16,7 +16,7 @@ import { List } from 'vs/base/browser/ui/list/listWidget'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { Context as SuggestContext, CompletionItem } from './suggest'; import { CompletionModel } from './completionModel'; @@ -124,12 +124,12 @@ class Renderer implements IListRenderer data.readMore.title = nls.localize('readMore', "Read More...{0}", this.triggerKeybindingLabel); const configureFont = () => { - const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); - const fontFamily = configuration.fontInfo.fontFamily; - const fontSize = options.get(EditorOption.suggestFontSize) || configuration.fontInfo.fontSize; - const lineHeight = options.get(EditorOption.suggestLineHeight) || configuration.fontInfo.lineHeight; - const fontWeight = configuration.fontInfo.fontWeight; + const fontInfo = options.get(EditorOption.fontInfo); + const fontFamily = fontInfo.fontFamily; + const fontSize = options.get(EditorOption.suggestFontSize) || fontInfo.fontSize; + const lineHeight = options.get(EditorOption.suggestLineHeight) || fontInfo.lineHeight; + const fontWeight = fontInfo.fontWeight; const fontSizePx = `${fontSize}px`; const lineHeightPx = `${lineHeight}px`; @@ -145,8 +145,8 @@ class Renderer implements IListRenderer configureFont(); - data.disposables.add(Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) - .filter(e => e.fontInfo || e.hasChanged(EditorOption.suggestFontSize) || e.hasChanged(EditorOption.suggestLineHeight)) + data.disposables.add(Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) + .filter(e => e.hasChanged(EditorOption.fontInfo) || e.hasChanged(EditorOption.suggestFontSize) || e.hasChanged(EditorOption.suggestLineHeight)) .on(configureFont, null)); return data; @@ -277,8 +277,8 @@ class SuggestionDetails { this.configureFont(); - Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) - .filter(e => e.fontInfo) + Event.chain(this.editor.onDidChangeConfiguration.bind(this.editor)) + .filter(e => e.hasChanged(EditorOption.fontInfo)) .on(this.configureFont, this, this.disposables); markdownRenderer.onDidRenderCodeBlock(() => this.scrollbar.scanDomNode(), this, this.disposables); @@ -390,12 +390,12 @@ class SuggestionDetails { } private configureFont() { - const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); - const fontFamily = configuration.fontInfo.fontFamily; - const fontSize = options.get(EditorOption.suggestFontSize) || configuration.fontInfo.fontSize; - const lineHeight = options.get(EditorOption.suggestLineHeight) || configuration.fontInfo.lineHeight; - const fontWeight = configuration.fontInfo.fontWeight; + const fontInfo = options.get(EditorOption.fontInfo); + const fontFamily = fontInfo.fontFamily; + const fontSize = options.get(EditorOption.suggestFontSize) || fontInfo.fontSize; + const lineHeight = options.get(EditorOption.suggestLineHeight) || fontInfo.lineHeight; + const fontWeight = fontInfo.fontWeight; const fontSizePx = `${fontSize}px`; const lineHeightPx = `${lineHeight}px`; @@ -1071,7 +1071,7 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegateeditorOptions.InternalEditorOptions, + ConfigurationChangedEvent: ConfigurationChangedEvent, BareFontInfo: BareFontInfo, FontInfo: FontInfo, TextModelResolvedOptions: TextModelResolvedOptions, @@ -381,7 +381,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor { // vars EditorType: editorCommon.EditorType, - EditorOptions: editorOptions.EditorOptions, + EditorOptions: EditorOptions, }; } diff --git a/src/vs/editor/test/common/config/commonEditorConfig.test.ts b/src/vs/editor/test/common/config/commonEditorConfig.test.ts index f2ab0bbbd41..0608fa6476e 100644 --- a/src/vs/editor/test/common/config/commonEditorConfig.test.ts +++ b/src/vs/editor/test/common/config/commonEditorConfig.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig'; -import { IEditorHoverOptions, EditorOption, IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { IEditorHoverOptions, EditorOption, ConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; @@ -193,7 +193,7 @@ suite('Common Editor Config', () => { test('does not emit event when nothing changes', () => { const config = new TestConfiguration({ glyphMargin: true, roundedSelection: false }); - let event: IConfigurationChangedEvent | null = null; + let event: ConfigurationChangedEvent | null = null; config.onDidChange(e => event = e); assert.equal(config.options.get(EditorOption.glyphMargin), true); diff --git a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts index 2ecf905ed35..d57bcaecded 100644 --- a/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts +++ b/src/vs/editor/test/common/viewModel/splitLinesCollection.test.ts @@ -92,6 +92,7 @@ suite('Editor ViewModel - SplitLinesCollection', () => { function withSplitLinesCollection(text: string, callback: (model: TextModel, linesCollection: SplitLinesCollection) => void): void { const config = new TestConfiguration({}); const wrappingInfo = config.options.get(EditorOption.wrappingInfo); + const fontInfo = config.options.get(EditorOption.fontInfo); const wordWrapBreakAfterCharacters = config.options.get(EditorOption.wordWrapBreakAfterCharacters); const wordWrapBreakBeforeCharacters = config.options.get(EditorOption.wordWrapBreakBeforeCharacters); const wordWrapBreakObtrusiveCharacters = config.options.get(EditorOption.wordWrapBreakObtrusiveCharacters); @@ -117,7 +118,7 @@ suite('Editor ViewModel - SplitLinesCollection', () => { hardWrappingLineMapperFactory, model.getOptions().tabSize, wrappingInfo.wrappingColumn, - config.editor.fontInfo.typicalFullwidthCharacterWidth / config.editor.fontInfo.typicalHalfwidthCharacterWidth, + fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent ); @@ -745,6 +746,7 @@ suite('SplitLinesCollection', () => { wrappingIndent: 'indent' }); const wrappingInfo = configuration.options.get(EditorOption.wrappingInfo); + const fontInfo = configuration.options.get(EditorOption.fontInfo); const wordWrapBreakAfterCharacters = configuration.options.get(EditorOption.wordWrapBreakAfterCharacters); const wordWrapBreakBeforeCharacters = configuration.options.get(EditorOption.wordWrapBreakBeforeCharacters); const wordWrapBreakObtrusiveCharacters = configuration.options.get(EditorOption.wordWrapBreakObtrusiveCharacters); @@ -761,7 +763,7 @@ suite('SplitLinesCollection', () => { factory, model.getOptions().tabSize, wrappingInfo.wrappingColumn, - configuration.editor.fontInfo.typicalFullwidthCharacterWidth / configuration.editor.fontInfo.typicalHalfwidthCharacterWidth, + fontInfo.typicalFullwidthCharacterWidth / fontInfo.typicalHalfwidthCharacterWidth, wrappingIndent ); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 59b8f512f19..b6afdd0aafb 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3093,7 +3093,7 @@ declare namespace monaco.editor { /** * The font weight */ - fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | 'initial' | 'inherit' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'; + fontWeight?: string; /** * The font size */ @@ -3121,6 +3121,10 @@ declare namespace monaco.editor { * Do not use, this is a computed option. */ pixelRatio?: undefined; + /** + * Do not use, this is a computed option. + */ + fontInfo?: undefined; /** * Do not use, this is a computed option. */ @@ -3256,20 +3260,11 @@ declare namespace monaco.editor { UnderlineThin = 6 } - /** - * Internal configuration options (transformed or computed) for the editor. - */ - export class InternalEditorOptions { - readonly _internalEditorOptionsBrand: void; - readonly fontInfo: FontInfo; - } - /** * An event describing that the configuration of the editor has changed. */ - export interface IConfigurationChangedEvent { + export class ConfigurationChangedEvent { hasChanged(id: EditorOption): boolean; - readonly fontInfo: boolean; } export interface IEnvironmentalOptions { @@ -3517,76 +3512,81 @@ declare namespace monaco.editor { fixedOverflowWidgets = 24, folding = 25, foldingStrategy = 26, - fontLigatures = 27, - formatOnPaste = 28, - formatOnType = 29, - glyphMargin = 30, - gotoLocation = 31, - hideCursorInOverviewRuler = 32, - highlightActiveIndentGuide = 33, - hover = 34, - inDiffEditor = 35, - lightbulb = 36, - lineDecorationsWidth = 37, - lineHeight = 38, - lineNumbers = 39, - lineNumbersMinChars = 40, - links = 41, - matchBrackets = 42, - minimap = 43, - mouseStyle = 44, - mouseWheelScrollSensitivity = 45, - mouseWheelZoom = 46, - multiCursorMergeOverlapping = 47, - multiCursorModifier = 48, - occurrencesHighlight = 49, - overviewRulerBorder = 50, - overviewRulerLanes = 51, - parameterHints = 52, - quickSuggestions = 53, - quickSuggestionsDelay = 54, - readOnly = 55, - renderControlCharacters = 56, - renderIndentGuides = 57, - renderFinalNewline = 58, - renderLineHighlight = 59, - renderWhitespace = 60, - revealHorizontalRightPadding = 61, - roundedSelection = 62, - rulers = 63, - scrollbar = 64, - scrollBeyondLastColumn = 65, - scrollBeyondLastLine = 66, - selectionClipboard = 67, - selectionHighlight = 68, - selectOnLineNumbers = 69, - showFoldingControls = 70, - showUnused = 71, - snippetSuggestions = 72, - smoothScrolling = 73, - stopRenderingLineAfter = 74, - suggestFontSize = 75, - suggestLineHeight = 76, - suggestOnTriggerCharacters = 77, - suggestSelection = 78, - tabCompletion = 79, - useTabStops = 80, - wordSeparators = 81, - wordWrap = 82, - wordWrapBreakAfterCharacters = 83, - wordWrapBreakBeforeCharacters = 84, - wordWrapBreakObtrusiveCharacters = 85, - wordWrapColumn = 86, - wordWrapMinified = 87, - wrappingIndent = 88, - ariaLabel = 89, - disableMonospaceOptimizations = 90, - editorClassName = 91, - pixelRatio = 92, - tabFocusMode = 93, - suggest = 94, - layoutInfo = 95, - wrappingInfo = 96 + fontFamily = 27, + fontInfo = 28, + fontLigatures = 29, + fontSize = 30, + fontWeight = 31, + formatOnPaste = 32, + formatOnType = 33, + glyphMargin = 34, + gotoLocation = 35, + hideCursorInOverviewRuler = 36, + highlightActiveIndentGuide = 37, + hover = 38, + inDiffEditor = 39, + letterSpacing = 40, + lightbulb = 41, + lineDecorationsWidth = 42, + lineHeight = 43, + lineNumbers = 44, + lineNumbersMinChars = 45, + links = 46, + matchBrackets = 47, + minimap = 48, + mouseStyle = 49, + mouseWheelScrollSensitivity = 50, + mouseWheelZoom = 51, + multiCursorMergeOverlapping = 52, + multiCursorModifier = 53, + occurrencesHighlight = 54, + overviewRulerBorder = 55, + overviewRulerLanes = 56, + parameterHints = 57, + quickSuggestions = 58, + quickSuggestionsDelay = 59, + readOnly = 60, + renderControlCharacters = 61, + renderIndentGuides = 62, + renderFinalNewline = 63, + renderLineHighlight = 64, + renderWhitespace = 65, + revealHorizontalRightPadding = 66, + roundedSelection = 67, + rulers = 68, + scrollbar = 69, + scrollBeyondLastColumn = 70, + scrollBeyondLastLine = 71, + selectionClipboard = 72, + selectionHighlight = 73, + selectOnLineNumbers = 74, + showFoldingControls = 75, + showUnused = 76, + snippetSuggestions = 77, + smoothScrolling = 78, + stopRenderingLineAfter = 79, + suggestFontSize = 80, + suggestLineHeight = 81, + suggestOnTriggerCharacters = 82, + suggestSelection = 83, + tabCompletion = 84, + useTabStops = 85, + wordSeparators = 86, + wordWrap = 87, + wordWrapBreakAfterCharacters = 88, + wordWrapBreakBeforeCharacters = 89, + wordWrapBreakObtrusiveCharacters = 90, + wordWrapColumn = 91, + wordWrapMinified = 92, + wrappingIndent = 93, + ariaLabel = 94, + disableMonospaceOptimizations = 95, + editorClassName = 96, + pixelRatio = 97, + tabFocusMode = 98, + suggest = 99, + layoutInfo = 100, + wrappingInfo = 101 } export const EditorOptions: { @@ -3617,7 +3617,11 @@ declare namespace monaco.editor { fixedOverflowWidgets: IEditorOption; folding: IEditorOption; foldingStrategy: IEditorOption; + fontFamily: IEditorOption; + fontInfo: IEditorOption; fontLigatures: IEditorOption; + fontSize: IEditorOption; + fontWeight: IEditorOption; formatOnPaste: IEditorOption; formatOnType: IEditorOption; glyphMargin: IEditorOption; @@ -3626,6 +3630,7 @@ declare namespace monaco.editor { highlightActiveIndentGuide: IEditorOption; hover: IEditorOption; inDiffEditor: IEditorOption; + letterSpacing: IEditorOption; lightbulb: IEditorOption; lineDecorationsWidth: IEditorOption; lineHeight: IEditorOption; @@ -4019,7 +4024,7 @@ declare namespace monaco.editor { * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) * @event */ - onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; + onDidChangeConfiguration(listener: (e: ConfigurationChangedEvent) => void): IDisposable; /** * An event emitted when the cursor position has changed. * @event @@ -4147,7 +4152,6 @@ declare namespace monaco.editor { /** * Returns the current editor's configuration */ - getConfiguration(): InternalEditorOptions; getOptions(): IComputedEditorOptions; getOption(id: T): FindComputedEditorOptionValueById; /** @@ -4392,6 +4396,7 @@ declare namespace monaco.editor { readonly spaceWidth: number; readonly maxDigitWidth: number; } + export class BareFontInfo { readonly _bareFontInfoBrand: void; readonly zoomLevel: number; diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index b167f3ea8df..67940979ba6 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -35,7 +35,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ITextFileService, SUPPORTED_ENCODINGS } from 'vs/workbench/services/textfile/common/textfiles'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; -import { IConfigurationChangedEvent, IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { deepClone } from 'vs/base/common/objects'; @@ -583,7 +583,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { if (activeCodeEditor) { // Hook Listener for Configuration changes - this.activeEditorListeners.add(activeCodeEditor.onDidChangeConfiguration((event: IConfigurationChangedEvent) => { + this.activeEditorListeners.add(activeCodeEditor.onDidChangeConfiguration((event: ConfigurationChangedEvent) => { if (event.hasChanged(EditorOption.accessibilitySupport)) { this.onScreenReaderModeChange(activeCodeEditor); } diff --git a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts index 32133496349..ebf9955db2a 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/selectionClipboard.ts @@ -9,7 +9,7 @@ import * as process from 'vs/base/common/process'; import * as platform from 'vs/base/common/platform'; import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { IConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { Range } from 'vs/editor/common/core/range'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; @@ -26,7 +26,7 @@ export class SelectionClipboard extends Disposable implements IEditorContributio if (platform.isLinux) { let isEnabled = editor.getOption(EditorOption.selectionClipboard); - this._register(editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { + this._register(editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { if (e.hasChanged(EditorOption.selectionClipboard)) { isEnabled = editor.getOption(EditorOption.selectionClipboard); } diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 42d3d7a8a14..8691a8105d5 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -129,7 +129,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget this._styleElement = dom.createStyleSheet(this.domNode); this._globalToDispose.add(this.themeService.onThemeChange(this._applyTheme, this)); this._globalToDispose.add(this.editor.onDidChangeConfiguration(e => { - if (e.fontInfo) { + if (e.hasChanged(EditorOption.fontInfo)) { this._applyTheme(this.themeService.getTheme()); } })); @@ -855,7 +855,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget content.push(`.monaco-editor .review-widget .body .comment-form .validation-error { color: ${errorForeground}; }`); } - const fontInfo = this.editor.getConfiguration().fontInfo; + const fontInfo = this.editor.getOption(EditorOption.fontInfo); content.push(`.monaco-editor .review-widget .body code { font-family: ${fontInfo.fontFamily}; font-size: ${fontInfo.fontSize}px; diff --git a/src/vs/workbench/contrib/debug/browser/debugHover.ts b/src/vs/workbench/contrib/debug/browser/debugHover.ts index e4f23037af0..2c7dd35cf15 100644 --- a/src/vs/workbench/contrib/debug/browser/debugHover.ts +++ b/src/vs/workbench/contrib/debug/browser/debugHover.ts @@ -9,7 +9,7 @@ import { KeyCode } from 'vs/base/common/keyCodes'; import { ScrollbarVisibility } from 'vs/base/common/scrollable'; import * as dom from 'vs/base/browser/dom'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions'; +import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; import { IContentWidget, ICodeEditor, IContentWidgetPosition, ContentWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; @@ -114,8 +114,8 @@ export class DebugHoverWidget implements IContentWidget { this.hide(); } })); - this.toDispose.push(this.editor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => { - if (e.fontInfo) { + this.toDispose.push(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { + if (e.hasChanged(EditorOption.fontInfo)) { this.editor.applyFontInfo(this.domNode); } })); diff --git a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts index 9191e39728b..913eaefc26c 100644 --- a/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts +++ b/src/vs/workbench/contrib/debug/browser/exceptionWidget.ts @@ -63,7 +63,7 @@ export class ExceptionWidget extends ZoneWidget { protected _fillContainer(container: HTMLElement): void { this.setCssClass('exception-widget'); // Set the font size and line height to the one from the editor configuration. - const fontInfo = this.editor.getConfiguration().fontInfo; + const fontInfo = this.editor.getOption(EditorOption.fontInfo); container.style.fontSize = `${fontInfo.fontSize}px`; container.style.lineHeight = `${fontInfo.lineHeight}px`; diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts index 2697f1a9e02..a6c6b87cf15 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesWidgets.ts @@ -85,9 +85,9 @@ export class SettingsHeaderWidget extends Widget implements IViewZone { } private layout(): void { - const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); - this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; + const fontInfo = options.get(EditorOption.fontInfo); + this.titleContainer.style.fontSize = fontInfo.fontSize + 'px'; if (!options.get(EditorOption.folding)) { this.titleContainer.style.paddingLeft = '6px'; } @@ -201,18 +201,18 @@ export class SettingsGroupTitleWidget extends Widget implements IViewZone { } private layout(): void { - const configuration = this.editor.getConfiguration(); const options = this.editor.getOptions(); + const fontInfo = options.get(EditorOption.fontInfo); const layoutInfo = this.editor.getLayoutInfo(); this._domNode.style.width = layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth + 'px'; this.titleContainer.style.lineHeight = options.get(EditorOption.lineHeight) + 3 + 'px'; this.titleContainer.style.height = options.get(EditorOption.lineHeight) + 3 + 'px'; - this.titleContainer.style.fontSize = configuration.fontInfo.fontSize + 'px'; + this.titleContainer.style.fontSize = fontInfo.fontSize + 'px'; this.icon.style.minWidth = `${this.getIconSize(16)}px`; } private getIconSize(minSize: number): number { - const fontSize = this.editor.getConfiguration().fontInfo.fontSize; + const fontSize = this.editor.getOption(EditorOption.fontInfo).fontSize; return fontSize > 8 ? Math.max(fontSize, minSize) : 12; } From e9581bcbd6c68a8777245ea0ddefb27224cb4689 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 15:25:41 +0200 Subject: [PATCH 015/109] Add EditorFontSize --- src/vs/editor/common/config/editorOptions.ts | 20 +++++++++++++++++++- src/vs/editor/common/config/fontInfo.ts | 11 ++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index a5ff1b80768..702d1aa9f0a 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -1556,12 +1556,30 @@ class EditorPixelRatio> extends EditorIntOption { public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + // The lineHeight is computed from the fontSize if it is 0 and the result of that computation is in the env.fontInfo return env.fontInfo.lineHeight; } } //#endregion +//#region fontSize + +class EditorFontSize> extends BaseEditorOption { + public validate(input: number | undefined): number { + let r = _float(input, this.defaultValue); + if (r === 0) { + return EDITOR_FONT_DEFAULTS.fontSize; + } + return _clamp(r, 8, 100); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + return value; + } +} + +//#endregion + //#region fontInfo class EditorFontInfo> extends BaseEditorOption { @@ -2414,7 +2432,7 @@ export const EditorOptions = { fontFamily: registerEditorOption(new EditorStringOption(EditorOption.fontFamily, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily)), fontInfo: registerEditorOption(new EditorFontInfo(EditorOption.fontInfo, 'fontInfo', undefined)), fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), - fontSize: registerEditorOption(new EditorFloatOption(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize, x => _clamp(x, 0, 100))), + fontSize: registerEditorOption(new EditorFontSize(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize)), fontWeight: registerEditorOption(new EditorStringOption(EditorOption.fontWeight, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight)), formatOnPaste: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnPaste, 'formatOnPaste', false)), formatOnType: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnType, 'formatOnType', false)), diff --git a/src/vs/editor/common/config/fontInfo.ts b/src/vs/editor/common/config/fontInfo.ts index b23edab7d90..6aa495b1d82 100644 --- a/src/vs/editor/common/config/fontInfo.ts +++ b/src/vs/editor/common/config/fontInfo.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as platform from 'vs/base/common/platform'; -import { EDITOR_FONT_DEFAULTS, EditorOptions, ValidatedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { EditorOptions, ValidatedEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; /** @@ -14,9 +14,8 @@ import { EditorZoom } from 'vs/editor/common/config/editorZoom'; const GOLDEN_LINE_HEIGHT_RATIO = platform.isMacintosh ? 1.5 : 1.35; /** - * Font settings maximum and minimum limits + * @internal */ -const MINIMUM_FONT_SIZE = 8; const MINIMUM_LINE_HEIGHT = 8; export class BareFontInfo { @@ -50,12 +49,6 @@ export class BareFontInfo { * @internal */ private static _create(fontFamily: string, fontWeight: string, fontSize: number, lineHeight: number, letterSpacing: number, zoomLevel: number, ignoreEditorZoom: boolean): BareFontInfo { - if (fontSize === 0) { - fontSize = EDITOR_FONT_DEFAULTS.fontSize; - } else if (fontSize < MINIMUM_FONT_SIZE) { - fontSize = MINIMUM_FONT_SIZE; - } - if (lineHeight === 0) { lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize); } else if (lineHeight < MINIMUM_LINE_HEIGHT) { From bcd154cc32b0b52050e14ce4e9d71d20d181b7b9 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 16:01:19 +0200 Subject: [PATCH 016/109] Keep mixin of the raw options --- src/vs/editor/browser/config/configuration.ts | 2 +- .../common/config/commonEditorConfig.ts | 97 +++++++------------ src/vs/editor/common/config/editorOptions.ts | 8 +- 3 files changed, 42 insertions(+), 65 deletions(-) diff --git a/src/vs/editor/browser/config/configuration.ts b/src/vs/editor/browser/config/configuration.ts index 8e8a71d3345..9078c4fe7cf 100644 --- a/src/vs/editor/browser/config/configuration.ts +++ b/src/vs/editor/browser/config/configuration.ts @@ -320,7 +320,7 @@ export class Configuration extends CommonEditorConfiguration { this._register(CSSBasedConfiguration.INSTANCE.onDidChange(() => this._onCSSBasedConfigurationChanged())); - if (this._validatedOptions2.get(EditorOption.automaticLayout)) { + if (this._validatedOptions.get(EditorOption.automaticLayout)) { this._elementSizeObserver.startObserving(); } diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index f751b1bcbcf..73c1e7669c7 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -81,31 +81,7 @@ class EditorConfiguration2 { return result; } - private static _mix(a: any, b: any): any { - switch (typeof b) { - case 'bigint': return b; - case 'boolean': return b; - case 'function': return b; - case 'number': return b; - case 'object': return (Array.isArray(b) || typeof a !== 'object' ? b : objects.mixin(objects.mixin({}, a), b)); - case 'string': return b; - default: - return a; - } - } - - public static mixOptions(a: RawEditorOptions, _b: IEditorOptions): RawEditorOptions { - const b: { [key: string]: any; } = _b; - const result = new RawEditorOptions(); - for (const editorOption of editorOptionsRegistry) { - const bValue = b[editorOption.name]; - result._write(editorOption.id, EditorConfiguration2._mix(a._read(editorOption.id), bValue)); - } - return result; - } - public static validateOptions(options: RawEditorOptions): ValidatedEditorOptions { - // console.log(`validateOptions`, options); const result = new ValidatedEditorOptions(); for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.validate(options._read(editorOption.id))); @@ -114,7 +90,6 @@ class EditorConfiguration2 { } public static computeOptions(options: ValidatedEditorOptions, env: IEnvironmentalOptions): ComputedEditorOptions { - // console.log(`computeOptions`, options, env); const result = new ComputedEditorOptions(); for (const editorOption of editorOptionsRegistry) { result._write(editorOption.id, editorOption.compute(env, result, options._read(editorOption.id))); @@ -123,7 +98,6 @@ class EditorConfiguration2 { } public static checkEquals(a: ComputedEditorOptions, b: ComputedEditorOptions): ConfigurationChangedEvent | null { - // console.log(`equals`, a, b); const result: boolean[] = []; let somethingChanged = false; for (const editorOption of editorOptionsRegistry) { @@ -207,40 +181,38 @@ function migrateOptions(options: IEditorOptions): void { } } -export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { +function deepCloneAndMigrateOptions(_options: IEditorOptions): IEditorOptions { + const options = objects.deepClone(_options); + migrateOptions(options); + return options; +} - public readonly isSimpleWidget: boolean; - protected _rawOptions: IEditorOptions; - private _isDominatedByLongLines: boolean; - private _lineNumbersDigitCount: number; +export abstract class CommonEditorConfiguration extends Disposable implements editorCommon.IConfiguration { private _onDidChange = this._register(new Emitter()); public readonly onDidChange: Event = this._onDidChange.event; - private _rawOptions2: RawEditorOptions; - protected _validatedOptions2: ValidatedEditorOptions; + public readonly isSimpleWidget: boolean; public options!: ComputedEditorOptions; - constructor(isSimpleWidget: boolean, options: IEditorOptions) { + private _isDominatedByLongLines: boolean; + private _lineNumbersDigitCount: number; + + private _rawOptions: IEditorOptions; + private _readOptions: RawEditorOptions; + protected _validatedOptions: ValidatedEditorOptions; + + constructor(isSimpleWidget: boolean, _options: IEditorOptions) { super(); - migrateOptions(options); - this.isSimpleWidget = isSimpleWidget; - // Do a "deep clone of sorts" on the incoming options - this._rawOptions = objects.mixin({}, options || {}); - this._rawOptions.scrollbar = objects.mixin({}, this._rawOptions.scrollbar || {}); - this._rawOptions.minimap = objects.mixin({}, this._rawOptions.minimap || {}); - this._rawOptions.find = objects.mixin({}, this._rawOptions.find || {}); - this._rawOptions.hover = objects.mixin({}, this._rawOptions.hover || {}); - this._rawOptions.parameterHints = objects.mixin({}, this._rawOptions.parameterHints || {}); - - this._rawOptions2 = EditorConfiguration2.readOptions(options); - this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); - this._isDominatedByLongLines = false; this._lineNumbersDigitCount = 1; + this._rawOptions = deepCloneAndMigrateOptions(_options); + this._readOptions = EditorConfiguration2.readOptions(this._rawOptions); + this._validatedOptions = EditorConfiguration2.validateOptions(this._readOptions); + this._register(EditorZoom.onDidChangeZoomLevel(_ => this._recomputeOptions())); this._register(TabFocus.onDidChangeTabFocus(_ => this._recomputeOptions())); } @@ -256,15 +228,17 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed const oldOptions = this.options; const newOptions = this._computeInternalOptions(); - const changeEvent = (oldOptions ? EditorConfiguration2.checkEquals(oldOptions, newOptions) : null); + if (!oldOptions) { + this.options = newOptions; + } else { + const changeEvent = EditorConfiguration2.checkEquals(oldOptions, newOptions); - if (oldOptions && changeEvent === null) { - return; - } + if (changeEvent === null) { + // nothing changed! + return; + } - this.options = newOptions; - - if (changeEvent) { + this.options = newOptions; this._onDidChange.fire(changeEvent); } } @@ -275,7 +249,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed private _computeInternalOptions(): ComputedEditorOptions { const partialEnv = this._getEnvConfiguration(); - const bareFontInfo = BareFontInfo.createFromValidatedSettings(this._validatedOptions2, partialEnv.zoomLevel, this.isSimpleWidget); + const bareFontInfo = BareFontInfo.createFromValidatedSettings(this._validatedOptions, partialEnv.zoomLevel, this.isSimpleWidget); const env: IEnvironmentalOptions = { outerWidth: partialEnv.outerWidth, outerHeight: partialEnv.outerHeight, @@ -288,7 +262,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed tabFocusMode: TabFocus.getTabFocusMode(), accessibilitySupport: partialEnv.accessibilitySupport }; - return EditorConfiguration2.computeOptions(this._validatedOptions2, env); + return EditorConfiguration2.computeOptions(this._validatedOptions, env); } private static _primitiveArrayEquals(a: any[], b: any[]): boolean { @@ -331,18 +305,17 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed return true; } - public updateOptions(newOptions: IEditorOptions): void { - if (typeof newOptions === 'undefined') { + public updateOptions(_newOptions: IEditorOptions): void { + if (typeof _newOptions === 'undefined') { return; } - migrateOptions(newOptions); + const newOptions = deepCloneAndMigrateOptions(_newOptions); if (CommonEditorConfiguration._subsetEquals(this._rawOptions, newOptions)) { return; } this._rawOptions = objects.mixin(this._rawOptions, newOptions || {}); - this._rawOptions2 = EditorConfiguration2.mixOptions(this._rawOptions2, newOptions); - - this._validatedOptions2 = EditorConfiguration2.validateOptions(this._rawOptions2); + this._readOptions = EditorConfiguration2.readOptions(this._rawOptions); + this._validatedOptions = EditorConfiguration2.validateOptions(this._readOptions); this._recomputeOptions(); } diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 702d1aa9f0a..8fb99020115 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -1556,7 +1556,9 @@ class EditorPixelRatio> extends EditorIntOption { public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { - // The lineHeight is computed from the fontSize if it is 0 and the result of that computation is in the env.fontInfo + // 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; } } @@ -1574,7 +1576,9 @@ class EditorFontSize return _clamp(r, 8, 100); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { - return value; + // The final fontSize respects the editor zoom level. + // So take the result from env.fontInfo + return env.fontInfo.fontSize; } } From ad3289c0eb1fc59b2f575716aa2e05ec5f8f91e0 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 5 Sep 2019 16:21:36 +0200 Subject: [PATCH 017/109] Remove IEditorOption.equals --- .../common/config/commonEditorConfig.ts | 18 ++- src/vs/editor/common/config/editorOptions.ts | 146 ------------------ 2 files changed, 17 insertions(+), 147 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 73c1e7669c7..a6442a9038c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -7,6 +7,7 @@ import * as nls from 'vs/nls'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; +import * as arrays from 'vs/base/common/arrays'; import * as platform from 'vs/base/common/platform'; import { IEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; @@ -97,11 +98,26 @@ class EditorConfiguration2 { return result; } + private static _deepEquals(a: T, b: T): boolean { + if (typeof a !== 'object' || typeof b !== 'object') { + return (a === b); + } + if (Array.isArray(a) || Array.isArray(b)) { + return (Array.isArray(a) && Array.isArray(b) ? arrays.equals(a, b) : false); + } + for (let key in a) { + if (!EditorConfiguration2._deepEquals(a[key], b[key])) { + return false; + } + } + return true; + } + public static checkEquals(a: ComputedEditorOptions, b: ComputedEditorOptions): ConfigurationChangedEvent | null { const result: boolean[] = []; let somethingChanged = false; for (const editorOption of editorOptionsRegistry) { - const changed = !editorOption.equals(a._read(editorOption.id), b._read(editorOption.id)); + const changed = !EditorConfiguration2._deepEquals(a._read(editorOption.id), b._read(editorOption.id)); result[editorOption.id] = changed; if (changed) { somethingChanged = true; diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 8fb99020115..13c42151c9d 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -5,8 +5,6 @@ import * as nls from 'vs/nls'; import * as assert from 'vs/base/common/assert'; -import * as arrays from 'vs/base/common/arrays'; -import * as objects from 'vs/base/common/objects'; import * as platform from 'vs/base/common/platform'; import { ScrollbarVisibility } from 'vs/base/common/scrollable'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; @@ -1144,10 +1142,6 @@ export interface IEditorOption> extends BaseEditorOption { @@ -1296,12 +1287,6 @@ class EditorRenderLineNumbersOption public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number[]): number[] { return value; } - public equals(a: number[], b: number[]): boolean { - return arrays.equals(a, b); - } } //#endregion @@ -1593,9 +1543,6 @@ class EditorFontInfo Date: Thu, 5 Sep 2019 19:53:12 +0200 Subject: [PATCH 018/109] wip --- src/vs/base/browser/ui/tree/asyncDataTree.ts | 9 ++++-- src/vs/base/browser/ui/tree/indexTreeModel.ts | 10 +++++++ .../browser/ui/tree/asyncDataTree.test.ts | 28 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/vs/base/browser/ui/tree/asyncDataTree.ts b/src/vs/base/browser/ui/tree/asyncDataTree.ts index f9380aaf243..04549cb817a 100644 --- a/src/vs/base/browser/ui/tree/asyncDataTree.ts +++ b/src/vs/base/browser/ui/tree/asyncDataTree.ts @@ -451,7 +451,7 @@ export class AsyncDataTree implements IDisposable const viewStateContext = viewState && { viewState, focus: [], selection: [] } as IAsyncDataTreeViewStateContext; - await this.updateChildren(input, true, viewStateContext); + await this._updateChildren(input, true, viewStateContext); if (viewStateContext) { this.tree.setFocus(viewStateContext.focus); @@ -463,7 +463,11 @@ export class AsyncDataTree implements IDisposable } } - async updateChildren(element: TInput | T = this.root.element, recursive = true, viewStateContext?: IAsyncDataTreeViewStateContext): Promise { + async updateChildren(element: TInput | T = this.root.element, recursive = true): Promise { + await this._updateChildren(element, recursive); + } + + private async _updateChildren(element: TInput | T = this.root.element, recursive = true, viewStateContext?: IAsyncDataTreeViewStateContext): Promise { if (typeof this.root.element === 'undefined') { throw new TreeError(this.user, 'Tree input not set'); } @@ -873,6 +877,7 @@ export class AsyncDataTree implements IDisposable private render(node: IAsyncDataTreeNode, viewStateContext?: IAsyncDataTreeViewStateContext): void { const children = node.children.map(c => asTreeElement(c, viewStateContext)); + this.tree.setCollapsible(node.hasChildren); // TODO this.tree.setChildren(node === this.root ? null : node, children); this._onDidRender.fire(); } diff --git a/src/vs/base/browser/ui/tree/indexTreeModel.ts b/src/vs/base/browser/ui/tree/indexTreeModel.ts index 022d612c0a3..720138dd3e9 100644 --- a/src/vs/base/browser/ui/tree/indexTreeModel.ts +++ b/src/vs/base/browser/ui/tree/indexTreeModel.ts @@ -205,6 +205,16 @@ export class IndexTreeModel, TFilterData = voi return this.getTreeNode(location).collapsible; } + setCollapsible(location: number[], collapsible?: boolean): boolean { + const node = this.getTreeNode(location); + + if (typeof collapsible === 'undefined') { + collapsible = !node.collapsible; + } + + throw new Error('To be implemented'); + } + isCollapsed(location: number[]): boolean { return this.getTreeNode(location).collapsed; } diff --git a/src/vs/base/test/browser/ui/tree/asyncDataTree.test.ts b/src/vs/base/test/browser/ui/tree/asyncDataTree.test.ts index 3192f789ac1..e26c5c66cb1 100644 --- a/src/vs/base/test/browser/ui/tree/asyncDataTree.test.ts +++ b/src/vs/base/test/browser/ui/tree/asyncDataTree.test.ts @@ -355,4 +355,32 @@ suite('AsyncDataTree', function () { race = await Promise.race([pExpandA.then(() => 'expand'), timeout(1).then(() => 'timeout')]); assert.equal(race, 'expand', 'expand(a) should now be done'); }); + + test('issue #78388 - tree should react to hasChildren toggles', async () => { + const container = document.createElement('div'); + const model = new Model({ + id: 'root', + children: [{ + id: 'a' + }] + }); + + const tree = new AsyncDataTree('test', container, new VirtualDelegate(), [new Renderer()], new DataSource(), { identityProvider: new IdentityProvider() }); + tree.layout(200); + + await tree.setInput(model.root); + assert.equal(container.querySelectorAll('.monaco-list-row').length, 1); + + let twistie = container.querySelector('.monaco-list-row:first-child .monaco-tl-twistie') as HTMLElement; + assert(!hasClass(twistie, 'collapsible')); + assert(!hasClass(twistie, 'collapsed')); + + model.get('a').children = [{ id: 'aa' }]; + await tree.updateChildren(model.get('a'), false); + assert.equal(container.querySelectorAll('.monaco-list-row').length, 1); + + twistie = container.querySelector('.monaco-list-row:first-child .monaco-tl-twistie') as HTMLElement; + assert(hasClass(twistie, 'collapsible')); + assert(hasClass(twistie, 'collapsed')); + }); }); From 3d8aa73a312b377ab748504b842d079793a7eb02 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 6 Sep 2019 11:01:06 +0200 Subject: [PATCH 019/109] wip: tree model setCollapsible --- src/vs/base/browser/ui/tree/abstractTree.ts | 4 ++++ src/vs/base/browser/ui/tree/asyncDataTree.ts | 6 +++++- src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts | 9 +++++++++ src/vs/base/browser/ui/tree/indexTreeModel.ts | 8 ++++++-- src/vs/base/browser/ui/tree/objectTreeModel.ts | 5 +++++ src/vs/base/browser/ui/tree/tree.ts | 1 + 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/vs/base/browser/ui/tree/abstractTree.ts b/src/vs/base/browser/ui/tree/abstractTree.ts index 410368f5f49..885e6bc5baf 100644 --- a/src/vs/base/browser/ui/tree/abstractTree.ts +++ b/src/vs/base/browser/ui/tree/abstractTree.ts @@ -1418,6 +1418,10 @@ export abstract class AbstractTree implements IDisposable return this.model.isCollapsible(location); } + setCollapsible(location: TRef, collapsible?: boolean): boolean { + return this.model.setCollapsible(location, collapsible); + } + isCollapsed(location: TRef): boolean { return this.model.isCollapsed(location); } diff --git a/src/vs/base/browser/ui/tree/asyncDataTree.ts b/src/vs/base/browser/ui/tree/asyncDataTree.ts index 04549cb817a..a15bbb11c8b 100644 --- a/src/vs/base/browser/ui/tree/asyncDataTree.ts +++ b/src/vs/base/browser/ui/tree/asyncDataTree.ts @@ -877,7 +877,11 @@ export class AsyncDataTree implements IDisposable private render(node: IAsyncDataTreeNode, viewStateContext?: IAsyncDataTreeViewStateContext): void { const children = node.children.map(c => asTreeElement(c, viewStateContext)); - this.tree.setCollapsible(node.hasChildren); // TODO + + if (node !== this.root) { + this.tree.setCollapsible(node, node.hasChildren); + } + this.tree.setChildren(node === this.root ? null : node, children); this._onDidRender.fire(); } diff --git a/src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts b/src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts index 81cae3bcd0c..22f9ce43205 100644 --- a/src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts +++ b/src/vs/base/browser/ui/tree/compressedObjectTreeModel.ts @@ -231,6 +231,11 @@ export class CompressedTreeModel, TFilterData extends return this.model.isCollapsible(compressedNode); } + setCollapsible(location: T | null, collapsible?: boolean): boolean { + const compressedNode = this.getCompressedNode(location); + return this.model.setCollapsible(compressedNode, collapsible); + } + isCollapsed(location: T | null): boolean { const compressedNode = this.getCompressedNode(location); return this.model.isCollapsed(compressedNode); @@ -397,6 +402,10 @@ export class CompressedObjectTreeModel, TFilterData e return this.model.isCollapsible(location); } + setCollapsible(location: T | null, collapsed?: boolean): boolean { + return this.model.setCollapsible(location, collapsed); + } + isCollapsed(location: T | null): boolean { return this.model.isCollapsed(location); } diff --git a/src/vs/base/browser/ui/tree/indexTreeModel.ts b/src/vs/base/browser/ui/tree/indexTreeModel.ts index 720138dd3e9..de1f03d3b37 100644 --- a/src/vs/base/browser/ui/tree/indexTreeModel.ts +++ b/src/vs/base/browser/ui/tree/indexTreeModel.ts @@ -210,9 +210,13 @@ export class IndexTreeModel, TFilterData = voi if (typeof collapsible === 'undefined') { collapsible = !node.collapsible; + } else if (node.collapsible === collapsible) { + return false; } - throw new Error('To be implemented'); + node.collapsible = collapsible; + this.eventBufferer.bufferEvents(() => this._setCollapsed(location, node.collapsed)); + return true; } isCollapsed(location: number[]): boolean { @@ -397,7 +401,7 @@ export class IndexTreeModel, TFilterData = voi result.push(node); node.renderNodeCount = 1; - if (!node.collapsed) { + if (node.collapsible && !node.collapsed) { for (const child of node.children) { node.renderNodeCount += this._updateNodeAfterCollapseChange(child, result); } diff --git a/src/vs/base/browser/ui/tree/objectTreeModel.ts b/src/vs/base/browser/ui/tree/objectTreeModel.ts index df4dabcdbc6..e2f78b9ebea 100644 --- a/src/vs/base/browser/ui/tree/objectTreeModel.ts +++ b/src/vs/base/browser/ui/tree/objectTreeModel.ts @@ -216,6 +216,11 @@ export class ObjectTreeModel, TFilterData extends Non return this.model.isCollapsible(location); } + setCollapsible(element: T | null, collapsible?: boolean): boolean { + const location = this.getElementLocation(element); + return this.model.setCollapsible(location, collapsible); + } + isCollapsed(element: T | null): boolean { const location = this.getElementLocation(element); return this.model.isCollapsed(location); diff --git a/src/vs/base/browser/ui/tree/tree.ts b/src/vs/base/browser/ui/tree/tree.ts index 930e76634bb..5be49ab229f 100644 --- a/src/vs/base/browser/ui/tree/tree.ts +++ b/src/vs/base/browser/ui/tree/tree.ts @@ -120,6 +120,7 @@ export interface ITreeModel { getLastElementAncestor(location?: TRef): T | undefined; isCollapsible(location: TRef): boolean; + setCollapsible(location: TRef, collapsible?: boolean): boolean; isCollapsed(location: TRef): boolean; setCollapsed(location: TRef, collapsed?: boolean, recursive?: boolean): boolean; expandTo(location: TRef): void; From b11d96fedecd31283ae373cbcc4ec28bcddb6074 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 6 Sep 2019 11:06:12 +0200 Subject: [PATCH 020/109] Simplify editor options --- .../common/config/commonEditorConfig.ts | 8 +- src/vs/editor/common/config/editorOptions.ts | 413 +++++++++--------- src/vs/editor/editor.api.ts | 4 +- src/vs/monaco.d.ts | 214 +++++---- 4 files changed, 323 insertions(+), 316 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index a6442a9038c..a778496a278 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -76,7 +76,7 @@ class EditorConfiguration2 { const options: { [key: string]: any; } = _options; const result = new RawEditorOptions(); for (const editorOption of editorOptionsRegistry) { - const value = options[editorOption.name]; + const value = (editorOption.name === '_never_' ? undefined : options[editorOption.name]); result._write(editorOption.id, value); } return result; @@ -1023,7 +1023,7 @@ const editorConfiguration: IConfigurationNode = { 'editor.cursorBlinking': { 'type': 'string', 'enum': ['blink', 'smooth', 'phase', 'expand', 'solid'], - 'default': EditorOptions.cursorBlinking.defaultValue, + 'default': 'blink', 'description': nls.localize('cursorBlinking', "Control the cursor animation style.") }, 'editor.mouseWheelZoom': { @@ -1039,7 +1039,7 @@ const editorConfiguration: IConfigurationNode = { 'editor.cursorStyle': { 'type': 'string', 'enum': ['block', 'block-outline', 'line', 'line-thin', 'underline', 'underline-thin'], - 'default': EditorOptions.cursorStyle.defaultValue, + 'default': 'line', 'description': nls.localize('cursorStyle', "Controls the cursor style.") }, 'editor.cursorWidth': { @@ -1156,7 +1156,7 @@ const editorConfiguration: IConfigurationNode = { nls.localize('accessibilitySupport.on', "The editor will be permanently optimized for usage with a Screen Reader."), nls.localize('accessibilitySupport.off', "The editor will never be optimized for usage with a Screen Reader."), ], - 'default': EditorOptions.accessibilitySupport.defaultValue, + 'default': 'auto', 'description': nls.localize('accessibilitySupport', "Controls whether the editor should run in a mode where it is optimized for screen readers.") }, 'editor.showUnused': { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 13c42151c9d..af15232a310 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; -import * as assert from 'vs/base/common/assert'; import * as platform from 'vs/base/common/platform'; import { ScrollbarVisibility } from 'vs/base/common/scrollable'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; @@ -938,7 +937,7 @@ function _string(value: any, defaultValue: string): string { return value; } -function _stringSet(value: T | undefined, defaultValue: T, allowedValues: T[]): T { +function _stringSet(value: T | undefined, defaultValue: T, allowedValues: ReadonlyArray): T { if (typeof value !== 'string') { return defaultValue; } @@ -1121,6 +1120,20 @@ export class ComputedEditorOptions implements IComputedEditorOptions { //#region IEditorOption +export interface IEditorOption { + readonly id: K1; + readonly name: string; + readonly defaultValue: V; + /** + * @internal + */ + validate(input: any): V; + /** + * @internal + */ + compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V; +} + /** * @internal */ @@ -1130,116 +1143,149 @@ type PossibleKeyName0 = { [K in keyof IExtendedEditorOptions]: IExtendedEdito */ type PossibleKeyName = NonNullable>; -export interface IEditorOption, T3 = T2> { - readonly id: K1; - readonly name: K2; - readonly defaultValue: T2; - /** - * @internal - */ - validate(input: IExtendedEditorOptions[K2] | undefined): T2; - /** - * @internal - */ - compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; +/** + * @internal + */ +abstract class BaseEditorOption implements IEditorOption { + + public readonly id: K1; + public readonly name: K2; + public readonly defaultValue: V; + public readonly deps: EditorOption[] | null; + + 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; + } } /** * @internal */ -abstract class BaseEditorOption implements IEditorOption { +abstract class ComputedEditorOption implements IEditorOption { public readonly id: K1; - public readonly name: K2; - public readonly defaultValue: T2; + public readonly name: '_never_'; + public readonly defaultValue: V; + public readonly deps: EditorOption[] | null; - constructor(id: K1, name: K2, defaultValue: T2, deps: EditorOption[] = []) { + constructor(id: K1, deps: EditorOption[] | null = null) { + this.id = id; + this.name = '_never_'; + this.defaultValue = undefined; + this.deps = deps; + } + + public validate(input: any): V { + return this.defaultValue; + } + + public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V; +} + +/** + * @internal + */ +class SimpleEditorOption implements IEditorOption { + + public readonly id: K1; + public readonly name: PossibleKeyName; + public readonly defaultValue: V; + public readonly deps: EditorOption[] | null; + + constructor(id: K1, name: PossibleKeyName, defaultValue: V, deps: EditorOption[] | null = null) { this.id = id; this.name = name; this.defaultValue = defaultValue; - for (const dep of deps) { - assert.ok(dep < id); - } + this.deps = deps; } - public abstract validate(input: IExtendedEditorOptions[K2] | undefined): T2; - public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T2): T3; -} -class EditorBooleanOption> extends BaseEditorOption { - public validate(input: boolean | undefined): boolean { - return _boolean(input, this.defaultValue); + public validate(input: any): V { + if (typeof input === 'undefined') { + return this.defaultValue; + } + return input as any; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { + + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V { return value; } } -class EditorIntOption> extends BaseEditorOption { +class EditorBooleanOption extends SimpleEditorOption { + public validate(input: any): boolean { + return _boolean(input, this.defaultValue); + } +} + +class EditorIntOption extends SimpleEditorOption { public readonly minimum: number; public readonly maximum: number; - constructor(id: K1, name: K2, defaultValue: number, minimum: number, maximum: number, deps: EditorOption[] = []) { - super(id, name, defaultValue, deps); + constructor(id: K1, name: PossibleKeyName, defaultValue: number, minimum: number, maximum: number) { + super(id, name, defaultValue); this.minimum = minimum; this.maximum = maximum; } - public validate(input: number | undefined): number { + public validate(input: any): number { return _clampedInt(input, this.defaultValue, this.minimum, this.maximum); } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { - return value; - } } -class EditorFloatOption> extends BaseEditorOption { +class EditorFloatOption extends SimpleEditorOption { public readonly validationFn: (value: number) => number; - constructor(id: K1, name: K2, defaultValue: number, validationFn: (value: number) => number, deps: EditorOption[] = []) { - super(id, name, defaultValue, deps); + constructor(id: K1, name: PossibleKeyName, defaultValue: number, validationFn: (value: number) => number) { + super(id, name, defaultValue); this.validationFn = validationFn; } - public validate(input: number | undefined): number { + public validate(input: any): number { return this.validationFn(_float(input, this.defaultValue)); } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { - return value; - } } -class EditorStringOption> extends BaseEditorOption { - public validate(input: string | undefined): string { +class EditorStringOption extends SimpleEditorOption { + public validate(input: any): string { return _string(input, this.defaultValue); } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { - return value; +} + +class EditorStringEnumOption extends SimpleEditorOption { + public readonly allowedValues: ReadonlyArray; + constructor(id: K1, name: PossibleKeyName, defaultValue: V, allowedValues: ReadonlyArray) { + super(id, name, defaultValue); + this.allowedValues = allowedValues; + } + public validate(input: any): V { + return _stringSet(input, this.defaultValue, this.allowedValues); } } -class EditorEnumOption, T1 extends string, T2 = T1> extends BaseEditorOption { - public readonly allowedValues: T1[]; - public readonly convert: (value: T1) => T2; - constructor(id: K1, name: K2, defaultValue: T1, allowedValues: T1[], convert: (value: T1) => T2, deps: EditorOption[] = []) { +class EditorEnumOption extends BaseEditorOption, V> { + public readonly allowedValues: T[]; + public readonly convert: (value: T) => V; + constructor(id: K1, name: PossibleKeyName, defaultValue: V, allowedValues: T[], convert: (value: T) => V, deps: EditorOption[] = []) { super(id, name, defaultValue, deps); this.allowedValues = allowedValues; this.convert = convert; } - public validate(input: IExtendedEditorOptions[K2] | undefined): T1 { - return _stringSet(input, this.defaultValue, this.allowedValues); - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: T1): T2 { - return this.convert(value); + public validate(input: any): V { + if (typeof input !== 'string') { + return this.defaultValue; + } + if (this.allowedValues.indexOf(input) === -1) { + return this.defaultValue; + } + return this.convert(input); } } -class EditorPassthroughOption extends BaseEditorOption { - public validate(input: IExtendedEditorOptions[K2] | undefined): IExtendedEditorOptions[K2] { - if (typeof input === 'undefined') { - return this.defaultValue; - } - return input; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: IExtendedEditorOptions[K2]): IExtendedEditorOptions[K2] { - return value; - } -} //#endregion //#region renderLineNumbers @@ -1259,8 +1305,8 @@ export interface InternalEditorRenderLineNumbersOptions { readonly renderFn: ((lineNumber: number) => string) | null; } -class EditorRenderLineNumbersOption> extends BaseEditorOption { - public validate(lineNumbers: LineNumbersType | undefined): InternalEditorRenderLineNumbersOptions { +class EditorRenderLineNumbersOption> extends BaseEditorOption { + public validate(lineNumbers: any): InternalEditorRenderLineNumbersOptions { let renderType: RenderLineNumbersType = this.defaultValue.renderType; let renderFn: ((lineNumber: number) => string) | null = this.defaultValue.renderFn; @@ -1284,9 +1330,6 @@ class EditorRenderLineNumbersOption> extends BaseEditorOption { - public validate(input: IEditorMinimapOptions | undefined): InternalEditorMinimapOptions { - if (typeof input !== 'object') { +class EditorMinimap> extends BaseEditorOption { + public validate(_input: any): InternalEditorMinimapOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorMinimapOptions; return { enabled: _boolean(input.enabled, this.defaultValue.enabled), side: _stringSet<'right' | 'left'>(input.side, this.defaultValue.side, ['right', 'left']), @@ -1314,9 +1358,6 @@ class EditorMinimap> extends BaseEditorOption { - public validate(input: IEditorHoverOptions | undefined): InternalEditorHoverOptions { - if (typeof input !== 'object') { + public validate(_input: any): InternalEditorHoverOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorHoverOptions; return { enabled: _boolean(input.enabled, this.defaultValue.enabled), delay: _clampedInt(input.delay, this.defaultValue.delay, 0, 10000), sticky: _boolean(input.sticky, this.defaultValue.sticky) }; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalEditorHoverOptions): InternalEditorHoverOptions { - return value; - } } //#endregion @@ -1356,11 +1395,12 @@ class EditorQuickSuggestions>) { super(id, name, defaultValue); } - public validate(input: boolean | IQuickSuggestionsOptions | undefined): ValidQuickSuggestionsOptions { - if (typeof input === 'boolean') { - return input; + public validate(_input: any): ValidQuickSuggestionsOptions { + if (typeof _input === 'boolean') { + return _input; } - if (typeof input === 'object') { + if (typeof _input === 'object') { + const input = _input as IQuickSuggestionsOptions; return { other: _boolean(input.other, this.defaultValue.other), comments: _boolean(input.comments, this.defaultValue.comments), @@ -1369,28 +1409,27 @@ class EditorQuickSuggestions> extends BaseEditorOption { - public validate(input: 'auto' | 'off' | 'on' | undefined): 'auto' | 'off' | 'on' { - return _stringSet<'auto' | 'off' | 'on'>(input, this.defaultValue, ['auto', 'off', 'on']); +class EditorAccessibilitySupportOption> extends BaseEditorOption { + 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; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: 'auto' | 'off' | 'on'): AccessibilitySupport { - if (value === 'auto') { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: AccessibilitySupport): AccessibilitySupport { + if (value === AccessibilitySupport.Unknown) { // The editor reads the `accessibilitySupport` from the environment return env.accessibilitySupport; - } else if (value === 'on') { - return AccessibilitySupport.Enabled; - } else { - return AccessibilitySupport.Disabled; } + return value; } } @@ -1398,8 +1437,8 @@ class EditorAccessibilitySupportOption> extends BaseEditorOption { - public validate(input: number[] | undefined): number[] { +class EditorRulers extends SimpleEditorOption { + public validate(input: any): number[] { if (Array.isArray(input)) { let rulers: number[] = []; for (let value of input) { @@ -1410,17 +1449,14 @@ class EditorRulers } return this.defaultValue; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number[]): number[] { - return value; - } } //#endregion //#region ariaLabel -class EditorAriaLabel> extends BaseEditorOption { - public validate(input: string | undefined): string { +class EditorAriaLabel extends SimpleEditorOption { + public validate(input: any): string { return _string(input, this.defaultValue); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: string): string { @@ -1436,12 +1472,12 @@ class EditorAriaLabel> extends BaseEditorOption { - public validate(input: boolean | undefined): boolean { +class EditorDisableMonospaceOptimizations extends SimpleEditorOption { + public validate(input: any): boolean { return _boolean(input, this.defaultValue); } public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { - return (value || options.get(EditorOption.folding)); + return (value || options.get(EditorOption.fontLigatures)); } } @@ -1449,11 +1485,8 @@ class EditorDisableMonospaceOptimizations> extends BaseEditorOption { - public validate(input: undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): string { +class EditorClassName extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: string): string { let className = 'monaco-editor'; if (options.get(EditorOption.extraEditorClassName)) { className += ' ' + options.get(EditorOption.extraEditorClassName); @@ -1477,11 +1510,8 @@ class EditorClassName> extends BaseEditorOption { - public validate(input: undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): boolean { +class EditorTabFocusMode extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: boolean): boolean { const readOnly = options.get(EditorOption.readOnly); return (readOnly ? true : env.tabFocusMode); } @@ -1491,11 +1521,8 @@ class EditorTabFocusMode> extends BaseEditorOption { - public validate(input: undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): number { +class EditorPixelRatio extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: number): number { return env.pixelRatio; } } @@ -1504,7 +1531,7 @@ class EditorPixelRatio> extends EditorIntOption { +class EditorLineHeight> extends EditorIntOption { 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. @@ -1517,8 +1544,8 @@ class EditorLineHeight> extends BaseEditorOption { - public validate(input: number | undefined): number { +class EditorFontSize extends SimpleEditorOption { + public validate(input: any): number { let r = _float(input, this.defaultValue); if (r === 0) { return EDITOR_FONT_DEFAULTS.fontSize; @@ -1536,11 +1563,8 @@ class EditorFontSize //#region fontInfo -class EditorFontInfo> extends BaseEditorOption { - public validate(input: number | undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): FontInfo { +class EditorFontInfo extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: FontInfo): FontInfo { return env.fontInfo; } } @@ -1549,7 +1573,7 @@ class EditorFontInfo> extends EditorBooleanOption { +class EditorEmptySelectionClipboard extends EditorBooleanOption { public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: boolean): boolean { return value && env.emptySelectionClipboard; } @@ -1562,17 +1586,15 @@ class EditorEmptySelectionClipboard; class EditorLightbulb> extends BaseEditorOption { - public validate(input: IEditorLightbulbOptions | undefined): ValidEditorLightbulbOptions { - if (typeof input !== 'object') { + public validate(_input: any): ValidEditorLightbulbOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorLightbulbOptions; return { enabled: _boolean(input.enabled, this.defaultValue.enabled) }; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: ValidEditorLightbulbOptions): ValidEditorLightbulbOptions { - return value; - } } //#endregion @@ -1593,11 +1615,12 @@ export interface InternalEditorScrollbarOptions { readonly verticalSliderSize: number; } -class EditorScrollbar> extends BaseEditorOption { - public validate(input: IEditorScrollbarOptions | undefined): InternalEditorScrollbarOptions { - if (typeof input !== 'object') { +class EditorScrollbar> extends BaseEditorOption { + public validate(_input: any): InternalEditorScrollbarOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorScrollbarOptions; const horizontalScrollbarSize = _clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000); const verticalScrollbarSize = _clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000); return { @@ -1614,17 +1637,12 @@ class EditorScrollbar>; - export interface InternalSuggestOptions { readonly filterGraceful: boolean; readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; @@ -1636,13 +1654,15 @@ export interface InternalSuggestOptions { readonly filteredTypes: Record; } -class EditorSuggest> extends BaseEditorOption { - public validate(input: ISuggestOptions | undefined): ValidSuggestOptions { - if (typeof input !== 'object') { +class EditorSuggest> extends BaseEditorOption { + public validate(_input: any): InternalSuggestOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as ISuggestOptions; return { filterGraceful: _boolean(input.filterGraceful, this.defaultValue.filterGraceful), + snippets: EditorOptions.snippetSuggestions.defaultValue, snippetsPreventQuickSuggestions: _boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful), localityBonus: _boolean(input.localityBonus, this.defaultValue.localityBonus), shareSuggestSelections: _boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections), @@ -1651,7 +1671,7 @@ class EditorSuggest> extends BaseEditorOption { - public validate(input: IEditorParameterHintOptions | undefined): InternalParameterHintOptions { - if (typeof input !== 'object') { + public validate(_input: any): InternalParameterHintOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorParameterHintOptions; return { enabled: _boolean(input.enabled, this.defaultValue.enabled), cycle: _boolean(input.cycle, this.defaultValue.cycle) }; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalParameterHintOptions): InternalParameterHintOptions { - return value; - } } //#endregion @@ -1705,10 +1723,11 @@ export interface InternalEditorFindOptions { } class EditorFind> extends BaseEditorOption { - public validate(input: IEditorFindOptions | undefined): InternalEditorFindOptions { - if (typeof input !== 'object') { + public validate(_input: any): InternalEditorFindOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IEditorFindOptions; return { seedSearchStringFromSelection: _boolean(input.seedSearchStringFromSelection, this.defaultValue.seedSearchStringFromSelection), autoFindInSelection: _boolean(input.autoFindInSelection, this.defaultValue.autoFindInSelection), @@ -1716,9 +1735,6 @@ class EditorFind> extends BaseEditorOption { - public validate(input: IGotoLocationOptions | undefined): InternalGoToLocationOptions { - if (typeof input !== 'object') { + public validate(_input: any): InternalGoToLocationOptions { + if (typeof _input !== 'object') { return this.defaultValue; } + const input = _input as IGotoLocationOptions; return { multiple: _stringSet<'peek' | 'gotoAndPeek' | 'goto'>(input.multiple, this.defaultValue.multiple, ['peek', 'gotoAndPeek', 'goto']) }; } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalGoToLocationOptions): InternalGoToLocationOptions { - return value; - } } //#endregion @@ -1872,11 +1886,8 @@ export interface EditorLayoutInfo { /** * @internal */ -export class EditorLayoutInfoComputer> extends BaseEditorOption { - public validate(input: undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorLayoutInfo { +export class EditorLayoutInfoComputer extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: EditorLayoutInfo): EditorLayoutInfo { const glyphMargin = options.get(EditorOption.glyphMargin); const lineNumbersMinChars = options.get(EditorOption.lineNumbersMinChars); const rawLineDecorationsWidth = options.get(EditorOption.lineDecorationsWidth); @@ -2063,11 +2074,8 @@ export interface EditorWrappingInfo { readonly wrappingColumn: number; } -class EditorWrappingInfoComputer> extends BaseEditorOption { - public validate(input: undefined): undefined { - return undefined; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: undefined): EditorWrappingInfo { +class EditorWrappingInfoComputer extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: EditorWrappingInfo): EditorWrappingInfo { const wordWrap = options.get(EditorOption.wordWrap); const wordWrapColumn = options.get(EditorOption.wordWrapColumn); const wordWrapMinified = options.get(EditorOption.wordWrapMinified); @@ -2143,7 +2151,7 @@ function _multiCursorModifierFromString(multiCursorModifier: 'ctrlCmd' | 'alt'): */ export const editorOptionsRegistry: IEditorOption[] = []; -function registerEditorOption(option: IEditorOption): IEditorOption { +function registerEditorOption(option: IEditorOption): IEditorOption { editorOptionsRegistry[option.id] = option; return option; } @@ -2256,21 +2264,21 @@ export const enum EditorOption { export const EditorOptions = { acceptSuggestionOnCommitCharacter: registerEditorOption(new EditorBooleanOption(EditorOption.acceptSuggestionOnCommitCharacter, 'acceptSuggestionOnCommitCharacter', true)), - acceptSuggestionOnEnter: registerEditorOption(new EditorEnumOption(EditorOption.acceptSuggestionOnEnter, 'acceptSuggestionOnEnter', 'on', ['on', 'smart', 'off'], (x: 'on' | 'smart' | 'off') => x)), - accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOption.accessibilitySupport, 'accessibilitySupport', 'auto')), - autoClosingBrackets: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingBrackets, 'autoClosingBrackets', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], (x: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never') => x)), - autoClosingOvertype: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingOvertype, 'autoClosingOvertype', 'auto', ['always', 'auto', 'never'], (x: 'always' | 'auto' | 'never') => x)), - autoClosingQuotes: registerEditorOption(new EditorEnumOption(EditorOption.autoClosingQuotes, 'autoClosingQuotes', 'languageDefined', ['always', 'languageDefined', 'beforeWhitespace', 'never'], (x: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never') => x)), + acceptSuggestionOnEnter: registerEditorOption(new EditorStringEnumOption(EditorOption.acceptSuggestionOnEnter, 'acceptSuggestionOnEnter', 'on' as 'on' | 'smart' | 'off', ['on', 'smart', 'off'] as const)), + accessibilitySupport: registerEditorOption(new EditorAccessibilitySupportOption(EditorOption.accessibilitySupport, 'accessibilitySupport', AccessibilitySupport.Unknown)), + autoClosingBrackets: registerEditorOption(new EditorStringEnumOption(EditorOption.autoClosingBrackets, 'autoClosingBrackets', 'languageDefined' as 'always' | 'languageDefined' | 'beforeWhitespace' | 'never', ['always', 'languageDefined', 'beforeWhitespace', 'never'] as const)), + autoClosingOvertype: registerEditorOption(new EditorStringEnumOption(EditorOption.autoClosingOvertype, 'autoClosingOvertype', 'auto' as 'always' | 'auto' | 'never', ['always', 'auto', 'never'] as const)), + autoClosingQuotes: registerEditorOption(new EditorStringEnumOption(EditorOption.autoClosingQuotes, 'autoClosingQuotes', 'languageDefined' as 'always' | 'languageDefined' | 'beforeWhitespace' | 'never', ['always', 'languageDefined', 'beforeWhitespace', 'never'] as const)), autoIndent: registerEditorOption(new EditorBooleanOption(EditorOption.autoIndent, 'autoIndent', true)), automaticLayout: registerEditorOption(new EditorBooleanOption(EditorOption.automaticLayout, 'automaticLayout', false)), - autoSurround: registerEditorOption(new EditorEnumOption(EditorOption.autoSurround, 'autoSurround', 'languageDefined', ['languageDefined', 'quotes', 'brackets', 'never'], (x: 'languageDefined' | 'quotes' | 'brackets' | 'never') => x)), + autoSurround: registerEditorOption(new EditorStringEnumOption(EditorOption.autoSurround, 'autoSurround', 'languageDefined' as 'languageDefined' | 'quotes' | 'brackets' | 'never', ['languageDefined', 'quotes', 'brackets', 'never'] as const)), codeLens: registerEditorOption(new EditorBooleanOption(EditorOption.codeLens, 'codeLens', true)), colorDecorators: registerEditorOption(new EditorBooleanOption(EditorOption.colorDecorators, 'colorDecorators', true)), contextmenu: registerEditorOption(new EditorBooleanOption(EditorOption.contextmenu, 'contextmenu', true)), copyWithSyntaxHighlighting: registerEditorOption(new EditorBooleanOption(EditorOption.copyWithSyntaxHighlighting, 'copyWithSyntaxHighlighting', true)), - cursorBlinking: registerEditorOption(new EditorEnumOption(EditorOption.cursorBlinking, 'cursorBlinking', 'blink', ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString)), + cursorBlinking: registerEditorOption(new EditorEnumOption(EditorOption.cursorBlinking, 'cursorBlinking', TextEditorCursorBlinkingStyle.Blink, ['blink', 'smooth', 'phase', 'expand', 'solid'], _cursorBlinkingStyleFromString)), cursorSmoothCaretAnimation: registerEditorOption(new EditorBooleanOption(EditorOption.cursorSmoothCaretAnimation, 'cursorSmoothCaretAnimation', false)), - cursorStyle: registerEditorOption(new EditorEnumOption(EditorOption.cursorStyle, 'cursorStyle', 'line', ['line', 'block', 'underline', 'line-thin', 'block-outline', 'underline-thin'], _cursorStyleFromString)), + cursorStyle: registerEditorOption(new EditorEnumOption(EditorOption.cursorStyle, 'cursorStyle', TextEditorCursorStyle.Line, ['line', 'block', 'underline', 'line-thin', 'block-outline', 'underline-thin'], _cursorStyleFromString)), cursorSurroundingLines: registerEditorOption(new EditorIntOption(EditorOption.cursorSurroundingLines, 'cursorSurroundingLines', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)), cursorWidth: registerEditorOption(new EditorIntOption(EditorOption.cursorWidth, 'cursorWidth', 0, 0, Constants.MAX_SAFE_SMALL_INTEGER)), disableLayerHinting: registerEditorOption(new EditorBooleanOption(EditorOption.disableLayerHinting, 'disableLayerHinting', false)), @@ -2286,9 +2294,9 @@ export const EditorOptions = { })), fixedOverflowWidgets: registerEditorOption(new EditorBooleanOption(EditorOption.fixedOverflowWidgets, 'fixedOverflowWidgets', false)), folding: registerEditorOption(new EditorBooleanOption(EditorOption.folding, 'folding', true)), - foldingStrategy: registerEditorOption(new EditorEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto', ['auto', 'indentation'], (x: 'auto' | 'indentation') => x)), + foldingStrategy: registerEditorOption(new EditorStringEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto' as 'auto' | 'indentation', ['auto', 'indentation'] as const)), fontFamily: registerEditorOption(new EditorStringOption(EditorOption.fontFamily, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily)), - fontInfo: registerEditorOption(new EditorFontInfo(EditorOption.fontInfo, 'fontInfo', undefined)), + fontInfo: registerEditorOption(new EditorFontInfo(EditorOption.fontInfo)), fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), fontSize: registerEditorOption(new EditorFontSize(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize)), fontWeight: registerEditorOption(new EditorStringOption(EditorOption.fontWeight, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight)), @@ -2310,7 +2318,7 @@ export const EditorOptions = { lightbulb: registerEditorOption(new EditorLightbulb(EditorOption.lightbulb, 'lightbulb', { enabled: true })), - lineDecorationsWidth: registerEditorOption(new EditorPassthroughOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10)), + lineDecorationsWidth: registerEditorOption(new SimpleEditorOption(EditorOption.lineDecorationsWidth, 'lineDecorationsWidth', 10 as number | string)), lineHeight: registerEditorOption(new EditorLineHeight(EditorOption.lineHeight, 'lineHeight', EDITOR_FONT_DEFAULTS.lineHeight, 0, 150)), lineNumbers: registerEditorOption(new EditorRenderLineNumbersOption(EditorOption.lineNumbers, 'lineNumbers', { renderType: RenderLineNumbersType.On, renderFn: null })), lineNumbersMinChars: registerEditorOption(new EditorIntOption(EditorOption.lineNumbersMinChars, 'lineNumbersMinChars', 5, 1, 10)), @@ -2323,11 +2331,11 @@ export const EditorOptions = { renderCharacters: true, maxColumn: 120, })), - mouseStyle: registerEditorOption(new EditorEnumOption(EditorOption.mouseStyle, 'mouseStyle', 'text', ['text', 'default', 'copy'], (x: 'text' | 'default' | 'copy') => x)), + mouseStyle: registerEditorOption(new EditorStringEnumOption(EditorOption.mouseStyle, 'mouseStyle', 'text' as 'text' | 'default' | 'copy', ['text', 'default', 'copy'] as const)), mouseWheelScrollSensitivity: registerEditorOption(new EditorFloatOption(EditorOption.mouseWheelScrollSensitivity, 'mouseWheelScrollSensitivity', 1, x => (x === 0 ? 1 : x))), mouseWheelZoom: registerEditorOption(new EditorBooleanOption(EditorOption.mouseWheelZoom, 'mouseWheelZoom', false)), multiCursorMergeOverlapping: registerEditorOption(new EditorBooleanOption(EditorOption.multiCursorMergeOverlapping, 'multiCursorMergeOverlapping', true)), - multiCursorModifier: registerEditorOption(new EditorEnumOption(EditorOption.multiCursorModifier, 'multiCursorModifier', 'alt', ['ctrlCmd', 'alt'], _multiCursorModifierFromString)), + multiCursorModifier: registerEditorOption(new EditorEnumOption(EditorOption.multiCursorModifier, 'multiCursorModifier', 'altKey', ['ctrlCmd', 'alt'], _multiCursorModifierFromString)), occurrencesHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.occurrencesHighlight, 'occurrencesHighlight', true)), overviewRulerBorder: registerEditorOption(new EditorBooleanOption(EditorOption.overviewRulerBorder, 'overviewRulerBorder', true)), overviewRulerLanes: registerEditorOption(new EditorIntOption(EditorOption.overviewRulerLanes, 'overviewRulerLanes', 2, 0, 3)), @@ -2345,8 +2353,8 @@ export const EditorOptions = { renderControlCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.renderControlCharacters, 'renderControlCharacters', false)), renderIndentGuides: registerEditorOption(new EditorBooleanOption(EditorOption.renderIndentGuides, 'renderIndentGuides', true)), renderFinalNewline: registerEditorOption(new EditorBooleanOption(EditorOption.renderFinalNewline, 'renderFinalNewline', true)), - renderLineHighlight: registerEditorOption(new EditorEnumOption(EditorOption.renderLineHighlight, 'renderLineHighlight', 'line', ['none', 'gutter', 'line', 'all'], (x: 'none' | 'gutter' | 'line' | 'all') => x)), - renderWhitespace: registerEditorOption(new EditorEnumOption(EditorOption.renderWhitespace, 'renderWhitespace', 'none', ['none', 'boundary', 'selection', 'all'], (x: 'none' | 'boundary' | 'selection' | 'all') => x)), + renderLineHighlight: registerEditorOption(new EditorStringEnumOption(EditorOption.renderLineHighlight, 'renderLineHighlight', 'line' as 'none' | 'gutter' | 'line' | 'all', ['none', 'gutter', 'line', 'all'] as const)), + renderWhitespace: registerEditorOption(new EditorStringEnumOption(EditorOption.renderWhitespace, 'renderWhitespace', 'none' as 'none' | 'boundary' | 'selection' | 'all', ['none', 'boundary', 'selection', 'all'] as const)), revealHorizontalRightPadding: registerEditorOption(new EditorIntOption(EditorOption.revealHorizontalRightPadding, 'revealHorizontalRightPadding', 30, 0, 1000)), roundedSelection: registerEditorOption(new EditorBooleanOption(EditorOption.roundedSelection, 'roundedSelection', true)), rulers: registerEditorOption(new EditorRulers(EditorOption.rulers, 'rulers', [])), @@ -2368,34 +2376,35 @@ export const EditorOptions = { selectionClipboard: registerEditorOption(new EditorBooleanOption(EditorOption.selectionClipboard, 'selectionClipboard', true)), selectionHighlight: registerEditorOption(new EditorBooleanOption(EditorOption.selectionHighlight, 'selectionHighlight', true)), selectOnLineNumbers: registerEditorOption(new EditorBooleanOption(EditorOption.selectOnLineNumbers, 'selectOnLineNumbers', true)), - showFoldingControls: registerEditorOption(new EditorEnumOption(EditorOption.showFoldingControls, 'showFoldingControls', 'mouseover', ['always', 'mouseover'], (x: 'always' | 'mouseover') => x)), + showFoldingControls: registerEditorOption(new EditorStringEnumOption(EditorOption.showFoldingControls, 'showFoldingControls', 'mouseover' as 'always' | 'mouseover', ['always', 'mouseover'] as const)), showUnused: registerEditorOption(new EditorBooleanOption(EditorOption.showUnused, 'showUnused', true)), - snippetSuggestions: registerEditorOption(new EditorEnumOption(EditorOption.snippetSuggestions, 'snippetSuggestions', 'inline', ['top', 'bottom', 'inline', 'none'], x => x)), + snippetSuggestions: registerEditorOption(new EditorStringEnumOption(EditorOption.snippetSuggestions, 'snippetSuggestions', 'inline' as 'top' | 'bottom' | 'inline' | 'none', ['top', 'bottom', 'inline', 'none'] as const)), smoothScrolling: registerEditorOption(new EditorBooleanOption(EditorOption.smoothScrolling, 'smoothScrolling', false)), stopRenderingLineAfter: registerEditorOption(new EditorIntOption(EditorOption.stopRenderingLineAfter, 'stopRenderingLineAfter', 10000, -1, Constants.MAX_SAFE_SMALL_INTEGER)), suggestFontSize: registerEditorOption(new EditorIntOption(EditorOption.suggestFontSize, 'suggestFontSize', 0, 0, 1000)), suggestLineHeight: registerEditorOption(new EditorIntOption(EditorOption.suggestLineHeight, 'suggestLineHeight', 0, 0, 1000)), suggestOnTriggerCharacters: registerEditorOption(new EditorBooleanOption(EditorOption.suggestOnTriggerCharacters, 'suggestOnTriggerCharacters', true)), - suggestSelection: registerEditorOption(new EditorEnumOption(EditorOption.suggestSelection, 'suggestSelection', 'recentlyUsed', ['first', 'recentlyUsed', 'recentlyUsedByPrefix'], (x: 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix') => x)), - tabCompletion: registerEditorOption(new EditorEnumOption(EditorOption.tabCompletion, 'tabCompletion', 'off', ['on', 'off', 'onlySnippets'], (x: 'on' | 'off' | 'onlySnippets') => x)), + suggestSelection: registerEditorOption(new EditorStringEnumOption(EditorOption.suggestSelection, 'suggestSelection', 'recentlyUsed' as 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix', ['first', 'recentlyUsed', 'recentlyUsedByPrefix'] as const)), + tabCompletion: registerEditorOption(new EditorStringEnumOption(EditorOption.tabCompletion, 'tabCompletion', 'off' as 'on' | 'off' | 'onlySnippets', ['on', 'off', 'onlySnippets'] as const)), useTabStops: registerEditorOption(new EditorBooleanOption(EditorOption.useTabStops, 'useTabStops', true)), wordSeparators: registerEditorOption(new EditorStringOption(EditorOption.wordSeparators, 'wordSeparators', USUAL_WORD_SEPARATORS)), - wordWrap: registerEditorOption(new EditorEnumOption(EditorOption.wordWrap, 'wordWrap', 'off', ['off', 'on', 'wordWrapColumn', 'bounded'], (x: 'off' | 'on' | 'wordWrapColumn' | 'bounded') => x)), + wordWrap: registerEditorOption(new EditorStringEnumOption(EditorOption.wordWrap, 'wordWrap', 'off' as 'off' | 'on' | 'wordWrapColumn' | 'bounded', ['off', 'on', 'wordWrapColumn', 'bounded'] as const)), wordWrapBreakAfterCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakAfterCharacters, 'wordWrapBreakAfterCharacters', ' \t})]?|/&,;¢°′″‰℃、。。、¢,.:;?!%・・ゝゞヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻ァィゥェォャュョッー”〉》」』】〕)]}」')), wordWrapBreakBeforeCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakBeforeCharacters, 'wordWrapBreakBeforeCharacters', '([{‘“〈《「『【〔([{「£¥$£¥++')), wordWrapBreakObtrusiveCharacters: registerEditorOption(new EditorStringOption(EditorOption.wordWrapBreakObtrusiveCharacters, 'wordWrapBreakObtrusiveCharacters', '.')), wordWrapColumn: registerEditorOption(new EditorIntOption(EditorOption.wordWrapColumn, 'wordWrapColumn', 80, 1, Constants.MAX_SAFE_SMALL_INTEGER)), wordWrapMinified: registerEditorOption(new EditorBooleanOption(EditorOption.wordWrapMinified, 'wordWrapMinified', true)), - wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', 'same', ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), + wrappingIndent: registerEditorOption(new EditorEnumOption(EditorOption.wrappingIndent, 'wrappingIndent', WrappingIndent.Same, ['none', 'same', 'indent', 'deepIndent'], _wrappingIndentFromString)), // Leave these at the end (because they have dependencies!) ariaLabel: registerEditorOption(new EditorAriaLabel(EditorOption.ariaLabel, 'ariaLabel', nls.localize('editorViewAccessibleLabel', "Editor content"), [EditorOption.accessibilitySupport])), disableMonospaceOptimizations: registerEditorOption(new EditorDisableMonospaceOptimizations(EditorOption.disableMonospaceOptimizations, 'disableMonospaceOptimizations', false, [EditorOption.fontLigatures])), - editorClassName: registerEditorOption(new EditorClassName(EditorOption.editorClassName, 'editorClassName', undefined, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])), - pixelRatio: registerEditorOption(new EditorPixelRatio(EditorOption.pixelRatio, 'pixelRatio', undefined)), - tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, 'tabFocusMode', undefined, [EditorOption.readOnly])), + editorClassName: registerEditorOption(new EditorClassName(EditorOption.editorClassName, [EditorOption.mouseStyle, EditorOption.fontLigatures, EditorOption.extraEditorClassName])), + pixelRatio: registerEditorOption(new EditorPixelRatio(EditorOption.pixelRatio)), + tabFocusMode: registerEditorOption(new EditorTabFocusMode(EditorOption.tabFocusMode, [EditorOption.readOnly])), suggest: registerEditorOption(new EditorSuggest(EditorOption.suggest, 'suggest', { filterGraceful: true, + snippets: 'inline', snippetsPreventQuickSuggestions: true, localityBonus: false, shareSuggestSelections: false, @@ -2403,11 +2412,11 @@ export const EditorOptions = { maxVisibleSuggestions: 12, filteredTypes: Object.create(null) }, [EditorOption.snippetSuggestions])), - layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, 'layoutInfo', undefined, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers])), - wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, 'wrappingInfo', undefined, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), + layoutInfo: registerEditorOption(new EditorLayoutInfoComputer(EditorOption.layoutInfo, [EditorOption.glyphMargin, EditorOption.lineDecorationsWidth, EditorOption.folding, EditorOption.minimap, EditorOption.scrollbar, EditorOption.lineNumbers])), + wrappingInfo: registerEditorOption(new EditorWrappingInfoComputer(EditorOption.wrappingInfo, [EditorOption.wordWrap, EditorOption.wordWrapColumn, EditorOption.wordWrapMinified, EditorOption.layoutInfo, EditorOption.accessibilitySupport])), }; export type EditorOptionsType = typeof EditorOptions; export type FindEditorOptionsKeyById = { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never }[keyof EditorOptionsType]; -export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; +export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; export type FindComputedEditorOptionValueById = NonNullable]>>; diff --git a/src/vs/editor/editor.api.ts b/src/vs/editor/editor.api.ts index a4e36c33fe0..5989b9a09eb 100644 --- a/src/vs/editor/editor.api.ts +++ b/src/vs/editor/editor.api.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { EditorOptions } from 'vs/editor/common/config/editorOptions'; +import { EditorOptions, WrappingIndent } from 'vs/editor/common/config/editorOptions'; import { createMonacoBaseAPI } from 'vs/editor/common/standalone/standaloneBase'; import { createMonacoEditorAPI } from 'vs/editor/standalone/browser/standaloneEditor'; import { createMonacoLanguagesAPI } from 'vs/editor/standalone/browser/standaloneLanguages'; @@ -11,7 +11,7 @@ import { createMonacoLanguagesAPI } from 'vs/editor/standalone/browser/standalon const global: any = self; // Set defaults for standalone editor -(EditorOptions.wrappingIndent).defaultValue = 'none'; +(EditorOptions.wrappingIndent).defaultValue = WrappingIndent.None; (EditorOptions.glyphMargin).defaultValue = false; (EditorOptions.autoIndent).defaultValue = false; diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index b6afdd0aafb..c698ce3ad5a 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3284,10 +3284,10 @@ declare namespace monaco.editor { get(id: T): FindComputedEditorOptionValueById; } - export interface IEditorOption, T3 = T2> { + export interface IEditorOption { readonly id: K1; - readonly name: K2; - readonly defaultValue: T2; + readonly name: string; + readonly defaultValue: V; } export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); @@ -3337,8 +3337,6 @@ declare namespace monaco.editor { readonly verticalSliderSize: number; } - export type ValidSuggestOptions = Readonly>; - export interface InternalSuggestOptions { readonly filterGraceful: boolean; readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; @@ -3590,108 +3588,108 @@ declare namespace monaco.editor { } export const EditorOptions: { - acceptSuggestionOnCommitCharacter: IEditorOption; - acceptSuggestionOnEnter: IEditorOption; - accessibilitySupport: IEditorOption; - autoClosingBrackets: IEditorOption; - autoClosingOvertype: IEditorOption; - autoClosingQuotes: IEditorOption; - autoIndent: IEditorOption; - automaticLayout: IEditorOption; - autoSurround: IEditorOption; - codeLens: IEditorOption; - colorDecorators: IEditorOption; - contextmenu: IEditorOption; - copyWithSyntaxHighlighting: IEditorOption; - cursorBlinking: IEditorOption; - cursorSmoothCaretAnimation: IEditorOption; - cursorStyle: IEditorOption; - cursorSurroundingLines: IEditorOption; - cursorWidth: IEditorOption; - disableLayerHinting: IEditorOption; - dragAndDrop: IEditorOption; - emptySelectionClipboard: IEditorOption; - extraEditorClassName: IEditorOption; - fastScrollSensitivity: IEditorOption; - find: IEditorOption; - fixedOverflowWidgets: IEditorOption; - folding: IEditorOption; - foldingStrategy: IEditorOption; - fontFamily: IEditorOption; - fontInfo: IEditorOption; - fontLigatures: IEditorOption; - fontSize: IEditorOption; - fontWeight: IEditorOption; - formatOnPaste: IEditorOption; - formatOnType: IEditorOption; - glyphMargin: IEditorOption; - gotoLocation: IEditorOption; - hideCursorInOverviewRuler: IEditorOption; - highlightActiveIndentGuide: IEditorOption; - hover: IEditorOption; - inDiffEditor: IEditorOption; - letterSpacing: IEditorOption; - lightbulb: IEditorOption; - lineDecorationsWidth: IEditorOption; - lineHeight: IEditorOption; - lineNumbers: IEditorOption; - lineNumbersMinChars: IEditorOption; - links: IEditorOption; - matchBrackets: IEditorOption; - minimap: IEditorOption; - mouseStyle: IEditorOption; - mouseWheelScrollSensitivity: IEditorOption; - mouseWheelZoom: IEditorOption; - multiCursorMergeOverlapping: IEditorOption; - multiCursorModifier: IEditorOption; - occurrencesHighlight: IEditorOption; - overviewRulerBorder: IEditorOption; - overviewRulerLanes: IEditorOption; - parameterHints: IEditorOption; - quickSuggestions: IEditorOption; - quickSuggestionsDelay: IEditorOption; - readOnly: IEditorOption; - renderControlCharacters: IEditorOption; - renderIndentGuides: IEditorOption; - renderFinalNewline: IEditorOption; - renderLineHighlight: IEditorOption; - renderWhitespace: IEditorOption; - revealHorizontalRightPadding: IEditorOption; - roundedSelection: IEditorOption; - rulers: IEditorOption; - scrollbar: IEditorOption; - scrollBeyondLastColumn: IEditorOption; - scrollBeyondLastLine: IEditorOption; - selectionClipboard: IEditorOption; - selectionHighlight: IEditorOption; - selectOnLineNumbers: IEditorOption; - showFoldingControls: IEditorOption; - showUnused: IEditorOption; - snippetSuggestions: IEditorOption; - smoothScrolling: IEditorOption; - stopRenderingLineAfter: IEditorOption; - suggestFontSize: IEditorOption; - suggestLineHeight: IEditorOption; - suggestOnTriggerCharacters: IEditorOption; - suggestSelection: IEditorOption; - tabCompletion: IEditorOption; - useTabStops: IEditorOption; - wordSeparators: IEditorOption; - wordWrap: IEditorOption; - wordWrapBreakAfterCharacters: IEditorOption; - wordWrapBreakBeforeCharacters: IEditorOption; - wordWrapBreakObtrusiveCharacters: IEditorOption; - wordWrapColumn: IEditorOption; - wordWrapMinified: IEditorOption; - wrappingIndent: IEditorOption; - ariaLabel: IEditorOption; - disableMonospaceOptimizations: IEditorOption; - editorClassName: IEditorOption; - pixelRatio: IEditorOption; - tabFocusMode: IEditorOption; - suggest: IEditorOption; - layoutInfo: IEditorOption; - wrappingInfo: IEditorOption; + acceptSuggestionOnCommitCharacter: IEditorOption; + acceptSuggestionOnEnter: IEditorOption; + accessibilitySupport: IEditorOption; + autoClosingBrackets: IEditorOption; + autoClosingOvertype: IEditorOption; + autoClosingQuotes: IEditorOption; + autoIndent: IEditorOption; + automaticLayout: IEditorOption; + autoSurround: IEditorOption; + codeLens: IEditorOption; + colorDecorators: IEditorOption; + contextmenu: IEditorOption; + copyWithSyntaxHighlighting: IEditorOption; + cursorBlinking: IEditorOption; + cursorSmoothCaretAnimation: IEditorOption; + cursorStyle: IEditorOption; + cursorSurroundingLines: IEditorOption; + cursorWidth: IEditorOption; + disableLayerHinting: IEditorOption; + dragAndDrop: IEditorOption; + emptySelectionClipboard: IEditorOption; + extraEditorClassName: IEditorOption; + fastScrollSensitivity: IEditorOption; + find: IEditorOption; + fixedOverflowWidgets: IEditorOption; + folding: IEditorOption; + foldingStrategy: IEditorOption; + fontFamily: IEditorOption; + fontInfo: IEditorOption; + fontLigatures: IEditorOption; + fontSize: IEditorOption; + fontWeight: IEditorOption; + formatOnPaste: IEditorOption; + formatOnType: IEditorOption; + glyphMargin: IEditorOption; + gotoLocation: IEditorOption; + hideCursorInOverviewRuler: IEditorOption; + highlightActiveIndentGuide: IEditorOption; + hover: IEditorOption; + inDiffEditor: IEditorOption; + letterSpacing: IEditorOption; + lightbulb: IEditorOption; + lineDecorationsWidth: IEditorOption; + lineHeight: IEditorOption; + lineNumbers: IEditorOption; + lineNumbersMinChars: IEditorOption; + links: IEditorOption; + matchBrackets: IEditorOption; + minimap: IEditorOption; + mouseStyle: IEditorOption; + mouseWheelScrollSensitivity: IEditorOption; + mouseWheelZoom: IEditorOption; + multiCursorMergeOverlapping: IEditorOption; + multiCursorModifier: IEditorOption; + occurrencesHighlight: IEditorOption; + overviewRulerBorder: IEditorOption; + overviewRulerLanes: IEditorOption; + parameterHints: IEditorOption; + quickSuggestions: IEditorOption; + quickSuggestionsDelay: IEditorOption; + readOnly: IEditorOption; + renderControlCharacters: IEditorOption; + renderIndentGuides: IEditorOption; + renderFinalNewline: IEditorOption; + renderLineHighlight: IEditorOption; + renderWhitespace: IEditorOption; + revealHorizontalRightPadding: IEditorOption; + roundedSelection: IEditorOption; + rulers: IEditorOption; + scrollbar: IEditorOption; + scrollBeyondLastColumn: IEditorOption; + scrollBeyondLastLine: IEditorOption; + selectionClipboard: IEditorOption; + selectionHighlight: IEditorOption; + selectOnLineNumbers: IEditorOption; + showFoldingControls: IEditorOption; + showUnused: IEditorOption; + snippetSuggestions: IEditorOption; + smoothScrolling: IEditorOption; + stopRenderingLineAfter: IEditorOption; + suggestFontSize: IEditorOption; + suggestLineHeight: IEditorOption; + suggestOnTriggerCharacters: IEditorOption; + suggestSelection: IEditorOption; + tabCompletion: IEditorOption; + useTabStops: IEditorOption; + wordSeparators: IEditorOption; + wordWrap: IEditorOption; + wordWrapBreakAfterCharacters: IEditorOption; + wordWrapBreakBeforeCharacters: IEditorOption; + wordWrapBreakObtrusiveCharacters: IEditorOption; + wordWrapColumn: IEditorOption; + wordWrapMinified: IEditorOption; + wrappingIndent: IEditorOption; + ariaLabel: IEditorOption; + disableMonospaceOptimizations: IEditorOption; + editorClassName: IEditorOption; + pixelRatio: IEditorOption; + tabFocusMode: IEditorOption; + suggest: IEditorOption; + layoutInfo: IEditorOption; + wrappingInfo: IEditorOption; }; export type EditorOptionsType = typeof EditorOptions; @@ -3700,7 +3698,7 @@ declare namespace monaco.editor { [K in keyof EditorOptionsType]: EditorOptionsType[K]['id'] extends T ? K : never; }[keyof EditorOptionsType]; - export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; + export type ComputedEditorOptionValue> = T extends IEditorOption ? R : never; export type FindComputedEditorOptionValueById = NonNullable]>>; From 45017f34b0259f5601311fb397b05e86e7bb73e9 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 6 Sep 2019 11:19:32 +0200 Subject: [PATCH 021/109] IndexTreeModel: complete setCollapsible() related to #78388 --- src/vs/base/browser/ui/tree/indexTreeModel.ts | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/vs/base/browser/ui/tree/indexTreeModel.ts b/src/vs/base/browser/ui/tree/indexTreeModel.ts index de1f03d3b37..359b4ff4e06 100644 --- a/src/vs/base/browser/ui/tree/indexTreeModel.ts +++ b/src/vs/base/browser/ui/tree/indexTreeModel.ts @@ -210,13 +210,9 @@ export class IndexTreeModel, TFilterData = voi if (typeof collapsible === 'undefined') { collapsible = !node.collapsible; - } else if (node.collapsible === collapsible) { - return false; } - node.collapsible = collapsible; - this.eventBufferer.bufferEvents(() => this._setCollapsed(location, node.collapsed)); - return true; + return this.eventBufferer.bufferEvents(() => this._setCollapseState(location, collapsible!, node.collapsed)); } isCollapsed(location: number[]): boolean { @@ -230,13 +226,13 @@ export class IndexTreeModel, TFilterData = voi collapsed = !node.collapsed; } - return this.eventBufferer.bufferEvents(() => this._setCollapsed(location, collapsed!, recursive)); + return this.eventBufferer.bufferEvents(() => this._setCollapseState(location, node.collapsible, collapsed!, recursive)); } - private _setCollapsed(location: number[], collapsed: boolean, recursive?: boolean): boolean { + private _setCollapseState(location: number[], collapsible: boolean, collapsed: boolean, recursive?: boolean): boolean { const { node, listIndex, revealed } = this.getTreeNodeWithListIndex(location); - const result = this._setListNodeCollapsed(node, listIndex, revealed, collapsed!, recursive || false); + const result = this._setListNodeCollapseState(node, listIndex, revealed, collapsible, collapsed, recursive || false); if (node !== this.root && this.autoExpandSingleChildren && !collapsed! && !recursive) { let onlyVisibleChildIndex = -1; @@ -255,15 +251,15 @@ export class IndexTreeModel, TFilterData = voi } if (onlyVisibleChildIndex > -1) { - this._setCollapsed([...location, onlyVisibleChildIndex], false, false); + this._setCollapseState([...location, onlyVisibleChildIndex], false, false); } } return result; } - private _setListNodeCollapsed(node: IMutableTreeNode, listIndex: number, revealed: boolean, collapsed: boolean, recursive: boolean): boolean { - const result = this._setNodeCollapsed(node, collapsed, recursive, false); + private _setListNodeCollapseState(node: IMutableTreeNode, listIndex: number, revealed: boolean, collapsible: boolean, collapsed: boolean, recursive: boolean): boolean { + const result = this._setNodeCollapseState(node, collapsible, collapsed, recursive, false); if (!revealed || !node.visible) { return result; @@ -277,20 +273,19 @@ export class IndexTreeModel, TFilterData = voi return result; } - private _setNodeCollapsed(node: IMutableTreeNode, collapsed: boolean, recursive: boolean, deep: boolean): boolean { - let result = node.collapsible && node.collapsed !== collapsed; + private _setNodeCollapseState(node: IMutableTreeNode, collapsible: boolean, collapsed: boolean, recursive: boolean, deep: boolean): boolean { + let result = node.collapsible !== collapsible || node.collapsed !== collapsed; - if (node.collapsible) { - node.collapsed = collapsed; + node.collapsible = collapsible; + node.collapsed = collapsed; - if (result) { - this._onDidChangeCollapseState.fire({ node, deep }); - } + if (result) { + this._onDidChangeCollapseState.fire({ node, deep }); } if (recursive) { for (const child of node.children) { - result = this._setNodeCollapsed(child, collapsed, true, true) || result; + result = this._setNodeCollapseState(child, collapsible, collapsed, true, true) || result; } } @@ -306,7 +301,7 @@ export class IndexTreeModel, TFilterData = voi location = location.slice(0, location.length - 1); if (node.collapsed) { - this._setCollapsed(location, false); + this._setCollapseState(location, node.collapsible, false); } } }); From b01cb4f8c05bdcfe499ca8162d3bce7050efd28c Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 6 Sep 2019 11:51:06 +0200 Subject: [PATCH 022/109] Fix default value --- src/vs/editor/common/config/editorOptions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index af15232a310..5fbca25c2a8 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -2297,7 +2297,7 @@ export const EditorOptions = { foldingStrategy: registerEditorOption(new EditorStringEnumOption(EditorOption.foldingStrategy, 'foldingStrategy', 'auto' as 'auto' | 'indentation', ['auto', 'indentation'] as const)), fontFamily: registerEditorOption(new EditorStringOption(EditorOption.fontFamily, 'fontFamily', EDITOR_FONT_DEFAULTS.fontFamily)), fontInfo: registerEditorOption(new EditorFontInfo(EditorOption.fontInfo)), - fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', true)), + fontLigatures: registerEditorOption(new EditorBooleanOption(EditorOption.fontLigatures, 'fontLigatures', false)), fontSize: registerEditorOption(new EditorFontSize(EditorOption.fontSize, 'fontSize', EDITOR_FONT_DEFAULTS.fontSize)), fontWeight: registerEditorOption(new EditorStringOption(EditorOption.fontWeight, 'fontWeight', EDITOR_FONT_DEFAULTS.fontWeight)), formatOnPaste: registerEditorOption(new EditorBooleanOption(EditorOption.formatOnPaste, 'formatOnPaste', false)), From 61d0aa4d05cd09cb56c2963d37870c11ca52eaf5 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 6 Sep 2019 12:05:51 +0200 Subject: [PATCH 023/109] Fix tests --- src/vs/editor/test/browser/testCodeEditor.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/test/browser/testCodeEditor.ts b/src/vs/editor/test/browser/testCodeEditor.ts index bf7ceae25a5..39a84d3acb2 100644 --- a/src/vs/editor/test/browser/testCodeEditor.ts +++ b/src/vs/editor/test/browser/testCodeEditor.ts @@ -91,7 +91,12 @@ export function withTestCodeEditor(text: string | string[] | null, options: Test export function createTestCodeEditor(options: TestCodeEditorCreationOptions): TestCodeEditor { + const model = options.model; + delete options.model; + const services: ServiceCollection = options.serviceCollection || new ServiceCollection(); + delete options.serviceCollection; + const instantiationService: IInstantiationService = new InstantiationService(services); if (!services.has(ICodeEditorService)) { @@ -119,6 +124,6 @@ export function createTestCodeEditor(options: TestCodeEditorCreationOptions): Te options, codeEditorWidgetOptions ); - editor.setModel(options.model); + editor.setModel(model); return editor; } From 292f3ab2852269e192e13751c76993404e15b07d Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 6 Sep 2019 12:20:25 +0200 Subject: [PATCH 024/109] Reorder options --- src/vs/editor/common/config/editorOptions.ts | 808 +++++++++--------- .../common/standalone/standaloneEnums.ts | 60 +- src/vs/monaco.d.ts | 224 +++-- 3 files changed, 524 insertions(+), 568 deletions(-) diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 5fbca25c2a8..f736287cc76 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -143,7 +143,7 @@ export interface IEditorMinimapOptions { } /** - * Configuration options for editor minimap + * Configuration options for editor lightbulb */ export interface IEditorLightbulbOptions { /** @@ -190,6 +190,9 @@ export interface IEditorParameterHintOptions { cycle?: boolean; } +/** + * Configuration options for editor suggest widget + */ export interface ISuggestOptions { /** * Enable graceful matching. Defaults to true. @@ -221,6 +224,9 @@ export interface ISuggestOptions { filteredTypes?: Record; } +/** + * Configuration options for go to location + */ export interface IGotoLocationOptions { /** * Control how goto-command work when having multiple results. @@ -228,6 +234,9 @@ export interface IGotoLocationOptions { multiple?: 'peek' | 'gotoAndPeek' | 'goto'; } +/** + * Configuration options for quick suggestions + */ export interface IQuickSuggestionsOptions { other: boolean; comments: boolean; @@ -716,33 +725,6 @@ export interface IEditorOptions { showUnused?: boolean; } -export type IExtendedEditorOptions = IEditorOptions & { - /** - * Do not use, this is a computed option. - */ - editorClassName?: undefined; - /** - * Do not use, this is a computed option. - */ - pixelRatio?: undefined; - /** - * Do not use, this is a computed option. - */ - fontInfo?: undefined; - /** - * Do not use, this is a computed option. - */ - tabFocusMode?: undefined; - /** - * Do not use, this is a computed option. - */ - layoutInfo?: undefined; - /** - * Do not use, this is a computed option. - */ - wrappingInfo?: undefined; -}; - /** * Configuration options for the diff editor. */ @@ -774,36 +756,6 @@ export interface IDiffEditorOptions extends IEditorOptions { originalEditable?: boolean; } -export const enum RenderMinimap { - None = 0, - Small = 1, - Large = 2, - SmallBlocks = 3, - LargeBlocks = 4, -} - -/** - * 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 -} - /** * The kind of animation in which the editor's cursor should be rendered. */ @@ -983,15 +935,6 @@ function _float(value: any, defaultValue: number): number { return (isNaN(r) ? defaultValue : r); } -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; - } -} - function _cursorBlinkingStyleFromString(cursorBlinkingStyle: 'blink' | 'smooth' | 'phase' | 'expand' | 'solid'): TextEditorCursorBlinkingStyle { switch (cursorBlinkingStyle) { case 'blink': return TextEditorCursorBlinkingStyle.Blink; @@ -1078,7 +1021,7 @@ export const EDITOR_MODEL_DEFAULTS = { /** * @internal */ -export interface IRawEditorOptionsBag extends IExtendedEditorOptions { +export interface IRawEditorOptionsBag extends IEditorOptions { [key: string]: any; } @@ -1134,19 +1077,10 @@ export interface IEditorOption { compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V; } -/** - * @internal - */ -type PossibleKeyName0 = { [K in keyof IExtendedEditorOptions]: IExtendedEditorOptions[K] extends V | undefined ? K : never }[keyof IExtendedEditorOptions]; -/** - * @internal - */ +type PossibleKeyName0 = { [K in keyof IEditorOptions]: IEditorOptions[K] extends V | undefined ? K : never }[keyof IEditorOptions]; type PossibleKeyName = NonNullable>; -/** - * @internal - */ -abstract class BaseEditorOption implements IEditorOption { +abstract class BaseEditorOption implements IEditorOption { public readonly id: K1; public readonly name: K2; @@ -1191,9 +1125,6 @@ abstract class ComputedEditorOption implements IEdit public abstract compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: V): V; } -/** - * @internal - */ class SimpleEditorOption implements IEditorOption { public readonly id: K1; @@ -1288,131 +1219,6 @@ class EditorEnumOption extends Bas //#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> extends BaseEditorOption { - 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 minimap - -export interface InternalEditorMinimapOptions { - readonly enabled: boolean; - readonly side: 'right' | 'left'; - readonly showSlider: 'always' | 'mouseover'; - readonly renderCharacters: boolean; - readonly maxColumn: number; -} - -class EditorMinimap> extends BaseEditorOption { - public validate(_input: any): InternalEditorMinimapOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as IEditorMinimapOptions; - return { - enabled: _boolean(input.enabled, this.defaultValue.enabled), - side: _stringSet<'right' | 'left'>(input.side, this.defaultValue.side, ['right', 'left']), - showSlider: _stringSet<'always' | 'mouseover'>(input.showSlider, this.defaultValue.showSlider, ['always', 'mouseover']), - renderCharacters: _boolean(input.renderCharacters, this.defaultValue.renderCharacters), - maxColumn: _clampedInt(input.maxColumn, this.defaultValue.maxColumn, 1, 10000), - }; - } -} - -//#endregion - -//#region hover - -export interface InternalEditorHoverOptions { - readonly enabled: boolean; - readonly delay: number; - readonly sticky: boolean; -} - -class EditorHover> extends BaseEditorOption { - public validate(_input: any): InternalEditorHoverOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as IEditorHoverOptions; - return { - enabled: _boolean(input.enabled, this.defaultValue.enabled), - delay: _clampedInt(input.delay, this.defaultValue.delay, 0, 10000), - sticky: _boolean(input.sticky, this.defaultValue.sticky) - }; - } -} - -//#endregion - -//#region quickSuggestions - -export type ValidQuickSuggestionsOptions = boolean | Readonly>; - -class EditorQuickSuggestions> extends BaseEditorOption { - public readonly defaultValue: Readonly>; - constructor(id: K1, name: K2, defaultValue: Readonly>) { - 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 { - other: _boolean(input.other, this.defaultValue.other), - comments: _boolean(input.comments, this.defaultValue.comments), - strings: _boolean(input.strings, this.defaultValue.strings), - }; - } - return this.defaultValue; - } -} - -//#endregion - //#region accessibilitySupport class EditorAccessibilitySupportOption> extends BaseEditorOption { @@ -1435,24 +1241,6 @@ class EditorAccessibilitySupportOption extends SimpleEditorOption { - public validate(input: any): number[] { - if (Array.isArray(input)) { - let rulers: number[] = []; - for (let value of input) { - rulers.push(_clampedInt(value, 0, 0, 10000)); - } - rulers.sort(); - return rulers; - } - return this.defaultValue; - } -} - -//#endregion - //#region ariaLabel class EditorAriaLabel extends SimpleEditorOption { @@ -1508,69 +1296,6 @@ class EditorClassName extends ComputedEditorOption extends ComputedEditorOption { - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: boolean): boolean { - const readOnly = options.get(EditorOption.readOnly); - return (readOnly ? true : env.tabFocusMode); - } -} - -//#endregion - -//#region pixelRatio - -class EditorPixelRatio extends ComputedEditorOption { - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: number): number { - return env.pixelRatio; - } -} - -//#endregion - -//#region lineHeight - -class EditorLineHeight> extends EditorIntOption { - 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 fontSize - -class EditorFontSize extends SimpleEditorOption { - public validate(input: any): number { - let r = _float(input, this.defaultValue); - if (r === 0) { - return EDITOR_FONT_DEFAULTS.fontSize; - } - return _clamp(r, 8, 100); - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { - // The final fontSize respects the editor zoom level. - // So take the result from env.fontInfo - return env.fontInfo.fontSize; - } -} - -//#endregion - -//#region fontInfo - -class EditorFontInfo extends ComputedEditorOption { - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: FontInfo): FontInfo { - return env.fontInfo; - } -} - -//#endregion - //#region emptySelectionClipboard class EditorEmptySelectionClipboard extends EditorBooleanOption { @@ -1581,135 +1306,6 @@ class EditorEmptySelectionClipboard extends EditorBoole //#endregion -//#region lightbulb - -export type ValidEditorLightbulbOptions = Required; - -class EditorLightbulb> extends BaseEditorOption { - public validate(_input: any): ValidEditorLightbulbOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as IEditorLightbulbOptions; - return { - enabled: _boolean(input.enabled, this.defaultValue.enabled) - }; - } -} - -//#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; -} - -class EditorScrollbar> extends BaseEditorOption { - public validate(_input: any): InternalEditorScrollbarOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as IEditorScrollbarOptions; - const horizontalScrollbarSize = _clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000); - const verticalScrollbarSize = _clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000); - return { - arrowSize: _clampedInt(input.arrowSize, this.defaultValue.arrowSize, 0, 1000), - vertical: _scrollbarVisibilityFromString(input.vertical, this.defaultValue.vertical), - horizontal: _scrollbarVisibilityFromString(input.horizontal, this.defaultValue.horizontal), - useShadows: _boolean(input.useShadows, this.defaultValue.useShadows), - verticalHasArrows: _boolean(input.verticalHasArrows, this.defaultValue.verticalHasArrows), - horizontalHasArrows: _boolean(input.horizontalHasArrows, this.defaultValue.horizontalHasArrows), - handleMouseWheel: _boolean(input.handleMouseWheel, this.defaultValue.handleMouseWheel), - horizontalScrollbarSize: horizontalScrollbarSize, - horizontalSliderSize: _clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000), - verticalScrollbarSize: verticalScrollbarSize, - verticalSliderSize: _clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000), - }; - } -} - -//#endregion - -//#region suggest - -export interface InternalSuggestOptions { - readonly filterGraceful: boolean; - readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; - readonly snippetsPreventQuickSuggestions: boolean; - readonly localityBonus: boolean; - readonly shareSuggestSelections: boolean; - readonly showIcons: boolean; - readonly maxVisibleSuggestions: number; - readonly filteredTypes: Record; -} - -class EditorSuggest> extends BaseEditorOption { - public validate(_input: any): InternalSuggestOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as ISuggestOptions; - return { - filterGraceful: _boolean(input.filterGraceful, this.defaultValue.filterGraceful), - snippets: EditorOptions.snippetSuggestions.defaultValue, - snippetsPreventQuickSuggestions: _boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful), - localityBonus: _boolean(input.localityBonus, this.defaultValue.localityBonus), - shareSuggestSelections: _boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections), - showIcons: _boolean(input.showIcons, this.defaultValue.showIcons), - maxVisibleSuggestions: _clampedInt(input.maxVisibleSuggestions, this.defaultValue.maxVisibleSuggestions, 1, 15), - filteredTypes: isObject(input.filteredTypes) ? input.filteredTypes : Object.create(null) - }; - } - public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalSuggestOptions): InternalSuggestOptions { - const snippetSuggestions = options.get(EditorOption.snippetSuggestions); - return { - filterGraceful: value.filterGraceful, - snippets: snippetSuggestions, - snippetsPreventQuickSuggestions: value.snippetsPreventQuickSuggestions, - localityBonus: value.localityBonus, - shareSuggestSelections: value.shareSuggestSelections, - showIcons: value.showIcons, - maxVisibleSuggestions: value.maxVisibleSuggestions, - filteredTypes: value.filteredTypes, - }; - } -} - -//#endregion - -//#region parameterHints - -export interface InternalParameterHintOptions { - readonly enabled: boolean; - readonly cycle: boolean; -} - -class EditorParameterHints> extends BaseEditorOption { - public validate(_input: any): InternalParameterHintOptions { - if (typeof _input !== 'object') { - return this.defaultValue; - } - const input = _input as IEditorParameterHintOptions; - return { - enabled: _boolean(input.enabled, this.defaultValue.enabled), - cycle: _boolean(input.cycle, this.defaultValue.cycle) - }; - } -} - -//#endregion - //#region find export interface InternalEditorFindOptions { @@ -1739,6 +1335,35 @@ class EditorFind extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: FontInfo): FontInfo { + return env.fontInfo; + } +} + +//#endregion + +//#region fontSize + +class EditorFontSize extends SimpleEditorOption { + public validate(input: any): number { + let r = _float(input, this.defaultValue); + if (r === 0) { + return EDITOR_FONT_DEFAULTS.fontSize; + } + return _clamp(r, 8, 100); + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: number): number { + // The final fontSize respects the editor zoom level. + // So take the result from env.fontInfo + return env.fontInfo.fontSize; + } +} + +//#endregion + //#region gotoLocation export interface InternalGoToLocationOptions { @@ -1759,6 +1384,30 @@ class EditorGoToLocation> extends BaseEditorOption { + public validate(_input: any): InternalEditorHoverOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as IEditorHoverOptions; + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + delay: _clampedInt(input.delay, this.defaultValue.delay, 0, 10000), + sticky: _boolean(input.sticky, this.defaultValue.sticky) + }; + } +} + +//#endregion + //#region layoutInfo /** @@ -1783,6 +1432,14 @@ export interface OverviewRulerPosition { readonly right: number; } +export const enum RenderMinimap { + None = 0, + Small = 1, + Large = 2, + SmallBlocks = 3, + LargeBlocks = 4, +} + /** * The internal layout details of the editor. */ @@ -2065,6 +1722,323 @@ export class EditorLayoutInfoComputer extends ComputedE //#endregion +//#region lightbulb + +export type ValidEditorLightbulbOptions = Required; + +class EditorLightbulb> extends BaseEditorOption { + public validate(_input: any): ValidEditorLightbulbOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as IEditorLightbulbOptions; + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled) + }; + } +} + +//#endregion + +//#region lineHeight + +class EditorLineHeight> extends EditorIntOption { + 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 + +export interface InternalEditorMinimapOptions { + readonly enabled: boolean; + readonly side: 'right' | 'left'; + readonly showSlider: 'always' | 'mouseover'; + readonly renderCharacters: boolean; + readonly maxColumn: number; +} + +class EditorMinimap> extends BaseEditorOption { + public validate(_input: any): InternalEditorMinimapOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as IEditorMinimapOptions; + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + side: _stringSet<'right' | 'left'>(input.side, this.defaultValue.side, ['right', 'left']), + showSlider: _stringSet<'always' | 'mouseover'>(input.showSlider, this.defaultValue.showSlider, ['always', 'mouseover']), + renderCharacters: _boolean(input.renderCharacters, this.defaultValue.renderCharacters), + maxColumn: _clampedInt(input.maxColumn, this.defaultValue.maxColumn, 1, 10000), + }; + } +} + +//#endregion + +//#region parameterHints + +export interface InternalParameterHintOptions { + readonly enabled: boolean; + readonly cycle: boolean; +} + +class EditorParameterHints> extends BaseEditorOption { + public validate(_input: any): InternalParameterHintOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as IEditorParameterHintOptions; + return { + enabled: _boolean(input.enabled, this.defaultValue.enabled), + cycle: _boolean(input.cycle, this.defaultValue.cycle) + }; + } +} + +//#endregion + +//#region pixelRatio + +class EditorPixelRatio extends ComputedEditorOption { + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, _: number): number { + return env.pixelRatio; + } +} + +//#endregion + +//#region quickSuggestions + +export type ValidQuickSuggestionsOptions = boolean | Readonly>; + +class EditorQuickSuggestions> extends BaseEditorOption { + public readonly defaultValue: Readonly>; + constructor(id: K1, name: K2, defaultValue: Readonly>) { + 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 { + other: _boolean(input.other, this.defaultValue.other), + comments: _boolean(input.comments, this.defaultValue.comments), + strings: _boolean(input.strings, this.defaultValue.strings), + }; + } + 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> extends BaseEditorOption { + 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 extends SimpleEditorOption { + public validate(input: any): number[] { + if (Array.isArray(input)) { + let rulers: number[] = []; + for (let value of input) { + rulers.push(_clampedInt(value, 0, 0, 10000)); + } + 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; +} + +class EditorScrollbar> extends BaseEditorOption { + public validate(_input: any): InternalEditorScrollbarOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as IEditorScrollbarOptions; + const horizontalScrollbarSize = _clampedInt(input.horizontalScrollbarSize, this.defaultValue.horizontalScrollbarSize, 0, 1000); + const verticalScrollbarSize = _clampedInt(input.verticalScrollbarSize, this.defaultValue.verticalScrollbarSize, 0, 1000); + return { + arrowSize: _clampedInt(input.arrowSize, this.defaultValue.arrowSize, 0, 1000), + vertical: _scrollbarVisibilityFromString(input.vertical, this.defaultValue.vertical), + horizontal: _scrollbarVisibilityFromString(input.horizontal, this.defaultValue.horizontal), + useShadows: _boolean(input.useShadows, this.defaultValue.useShadows), + verticalHasArrows: _boolean(input.verticalHasArrows, this.defaultValue.verticalHasArrows), + horizontalHasArrows: _boolean(input.horizontalHasArrows, this.defaultValue.horizontalHasArrows), + handleMouseWheel: _boolean(input.handleMouseWheel, this.defaultValue.handleMouseWheel), + horizontalScrollbarSize: horizontalScrollbarSize, + horizontalSliderSize: _clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000), + verticalScrollbarSize: verticalScrollbarSize, + verticalSliderSize: _clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000), + }; + } +} + +//#endregion + +//#region suggest + +export interface InternalSuggestOptions { + readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; + readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; + readonly shareSuggestSelections: boolean; + readonly showIcons: boolean; + readonly maxVisibleSuggestions: number; + readonly filteredTypes: Record; +} + +class EditorSuggest> extends BaseEditorOption { + public validate(_input: any): InternalSuggestOptions { + if (typeof _input !== 'object') { + return this.defaultValue; + } + const input = _input as ISuggestOptions; + return { + filterGraceful: _boolean(input.filterGraceful, this.defaultValue.filterGraceful), + snippets: EditorOptions.snippetSuggestions.defaultValue, + snippetsPreventQuickSuggestions: _boolean(input.snippetsPreventQuickSuggestions, this.defaultValue.filterGraceful), + localityBonus: _boolean(input.localityBonus, this.defaultValue.localityBonus), + shareSuggestSelections: _boolean(input.shareSuggestSelections, this.defaultValue.shareSuggestSelections), + showIcons: _boolean(input.showIcons, this.defaultValue.showIcons), + maxVisibleSuggestions: _clampedInt(input.maxVisibleSuggestions, this.defaultValue.maxVisibleSuggestions, 1, 15), + filteredTypes: isObject(input.filteredTypes) ? input.filteredTypes : Object.create(null) + }; + } + public compute(env: IEnvironmentalOptions, options: IComputedEditorOptions, value: InternalSuggestOptions): InternalSuggestOptions { + const snippetSuggestions = options.get(EditorOption.snippetSuggestions); + return { + filterGraceful: value.filterGraceful, + snippets: snippetSuggestions, + snippetsPreventQuickSuggestions: value.snippetsPreventQuickSuggestions, + localityBonus: value.localityBonus, + shareSuggestSelections: value.shareSuggestSelections, + showIcons: value.showIcons, + maxVisibleSuggestions: value.maxVisibleSuggestions, + filteredTypes: value.filteredTypes, + }; + } +} + +//#endregion + +//#region tabFocusMode + +class EditorTabFocusMode extends ComputedEditorOption { + 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 + //#region wrappingInfo export interface EditorWrappingInfo { diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 9a5f179dfab..89350c4f9a7 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -341,36 +341,6 @@ export enum AccessibilitySupport { Enabled = 2 } -export enum RenderMinimap { - None = 0, - Small = 1, - Large = 2, - SmallBlocks = 3, - LargeBlocks = 4 -} - -/** - * Describes how to indent wrapped lines. - */ -export 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 -} - /** * The kind of animation in which the editor's cursor should be rendered. */ @@ -431,6 +401,14 @@ export enum TextEditorCursorStyle { UnderlineThin = 6 } +export enum RenderMinimap { + None = 0, + Small = 1, + Large = 2, + SmallBlocks = 3, + LargeBlocks = 4 +} + export enum RenderLineNumbersType { Off = 0, On = 1, @@ -439,6 +417,28 @@ export enum RenderLineNumbersType { Custom = 4 } +/** + * Describes how to indent wrapped lines. + */ +export 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 +} + export enum EditorOption { acceptSuggestionOnCommitCharacter = 0, acceptSuggestionOnEnter = 1, diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index c698ce3ad5a..b56a37e69a2 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2540,7 +2540,7 @@ declare namespace monaco.editor { } /** - * Configuration options for editor minimap + * Configuration options for editor lightbulb */ export interface IEditorLightbulbOptions { /** @@ -2587,6 +2587,9 @@ declare namespace monaco.editor { cycle?: boolean; } + /** + * Configuration options for editor suggest widget + */ export interface ISuggestOptions { /** * Enable graceful matching. Defaults to true. @@ -2618,6 +2621,9 @@ declare namespace monaco.editor { filteredTypes?: Record; } + /** + * Configuration options for go to location + */ export interface IGotoLocationOptions { /** * Control how goto-command work when having multiple results. @@ -2625,6 +2631,9 @@ declare namespace monaco.editor { multiple?: 'peek' | 'gotoAndPeek' | 'goto'; } + /** + * Configuration options for quick suggestions + */ export interface IQuickSuggestionsOptions { other: boolean; comments: boolean; @@ -3112,33 +3121,6 @@ declare namespace monaco.editor { showUnused?: boolean; } - export type IExtendedEditorOptions = IEditorOptions & { - /** - * Do not use, this is a computed option. - */ - editorClassName?: undefined; - /** - * Do not use, this is a computed option. - */ - pixelRatio?: undefined; - /** - * Do not use, this is a computed option. - */ - fontInfo?: undefined; - /** - * Do not use, this is a computed option. - */ - tabFocusMode?: undefined; - /** - * Do not use, this is a computed option. - */ - layoutInfo?: undefined; - /** - * Do not use, this is a computed option. - */ - wrappingInfo?: undefined; - }; - /** * Configuration options for the diff editor. */ @@ -3170,36 +3152,6 @@ declare namespace monaco.editor { originalEditable?: boolean; } - export enum RenderMinimap { - None = 0, - Small = 1, - Large = 2, - SmallBlocks = 3, - LargeBlocks = 4 - } - - /** - * Describes how to indent wrapped lines. - */ - export 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 - } - /** * The kind of animation in which the editor's cursor should be rendered. */ @@ -3290,69 +3242,6 @@ declare namespace monaco.editor { readonly defaultValue: V; } - export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); - - export enum RenderLineNumbersType { - Off = 0, - On = 1, - Relative = 2, - Interval = 3, - Custom = 4 - } - - export interface InternalEditorRenderLineNumbersOptions { - readonly renderType: RenderLineNumbersType; - readonly renderFn: ((lineNumber: number) => string) | null; - } - - export interface InternalEditorMinimapOptions { - readonly enabled: boolean; - readonly side: 'right' | 'left'; - readonly showSlider: 'always' | 'mouseover'; - readonly renderCharacters: boolean; - readonly maxColumn: number; - } - - export interface InternalEditorHoverOptions { - readonly enabled: boolean; - readonly delay: number; - readonly sticky: boolean; - } - - export type ValidQuickSuggestionsOptions = boolean | Readonly>; - - export type ValidEditorLightbulbOptions = Required; - - 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; - } - - export interface InternalSuggestOptions { - readonly filterGraceful: boolean; - readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; - readonly snippetsPreventQuickSuggestions: boolean; - readonly localityBonus: boolean; - readonly shareSuggestSelections: boolean; - readonly showIcons: boolean; - readonly maxVisibleSuggestions: number; - readonly filteredTypes: Record; - } - - export interface InternalParameterHintOptions { - readonly enabled: boolean; - readonly cycle: boolean; - } - export interface InternalEditorFindOptions { readonly seedSearchStringFromSelection: boolean; readonly autoFindInSelection: boolean; @@ -3363,6 +3252,12 @@ declare namespace monaco.editor { readonly multiple: 'peek' | 'gotoAndPeek' | 'goto'; } + export interface InternalEditorHoverOptions { + readonly enabled: boolean; + readonly delay: number; + readonly sticky: boolean; + } + /** * A description for the overview ruler position. */ @@ -3385,6 +3280,14 @@ declare namespace monaco.editor { readonly right: number; } + export enum RenderMinimap { + None = 0, + Small = 1, + Large = 2, + SmallBlocks = 3, + LargeBlocks = 4 + } + /** * The internal layout details of the editor. */ @@ -3475,6 +3378,85 @@ declare namespace monaco.editor { readonly overviewRuler: OverviewRulerPosition; } + export type ValidEditorLightbulbOptions = Required; + + export interface InternalEditorMinimapOptions { + readonly enabled: boolean; + readonly side: 'right' | 'left'; + readonly showSlider: 'always' | 'mouseover'; + readonly renderCharacters: boolean; + readonly maxColumn: number; + } + + export interface InternalParameterHintOptions { + readonly enabled: boolean; + readonly cycle: boolean; + } + + export type ValidQuickSuggestionsOptions = boolean | Readonly>; + + export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string); + + export enum RenderLineNumbersType { + Off = 0, + On = 1, + Relative = 2, + Interval = 3, + Custom = 4 + } + + export interface InternalEditorRenderLineNumbersOptions { + readonly renderType: RenderLineNumbersType; + readonly renderFn: ((lineNumber: number) => string) | null; + } + + 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; + } + + export interface InternalSuggestOptions { + readonly filterGraceful: boolean; + readonly snippets: 'top' | 'bottom' | 'inline' | 'none'; + readonly snippetsPreventQuickSuggestions: boolean; + readonly localityBonus: boolean; + readonly shareSuggestSelections: boolean; + readonly showIcons: boolean; + readonly maxVisibleSuggestions: number; + readonly filteredTypes: Record; + } + + /** + * Describes how to indent wrapped lines. + */ + export 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 + } + export interface EditorWrappingInfo { readonly isDominatedByLongLines: boolean; readonly isWordWrapMinified: boolean; From 959c017811a137868e62838036a5286c11d0d4f9 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 6 Sep 2019 12:28:13 +0200 Subject: [PATCH 025/109] Rearrange editor options --- .../common/config/commonEditorConfig.ts | 15 +- src/vs/editor/common/config/editorOptions.ts | 307 +++++++++--------- src/vs/monaco.d.ts | 53 ++- 3 files changed, 186 insertions(+), 189 deletions(-) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index a778496a278..5f99d84bf59 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -9,7 +9,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as arrays from 'vs/base/common/arrays'; import * as platform from 'vs/base/common/platform'; -import { IEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, ComputedEditorOptions, ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, EditorOption } from 'vs/editor/common/config/editorOptions'; +import { IEditorOptions, editorOptionsRegistry, ValidatedEditorOptions, IEnvironmentalOptions, IComputedEditorOptions, ConfigurationChangedEvent, EDITOR_FONT_DEFAULTS, EditorOptions, EDITOR_MODEL_DEFAULTS, EditorOption, FindComputedEditorOptionValueById } from 'vs/editor/common/config/editorOptions'; import { EditorZoom } from 'vs/editor/common/config/editorZoom'; import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -61,6 +61,19 @@ export interface IEnvConfiguration { const hasOwnProperty = Object.hasOwnProperty; +class ComputedEditorOptions implements IComputedEditorOptions { + private readonly _values: any[] = []; + public _read(id: EditorOption): T { + return this._values[id]; + } + public get(id: T): FindComputedEditorOptionValueById { + return this._values[id]; + } + public _write(id: EditorOption, value: T): void { + this._values[id] = value; + } +} + class RawEditorOptions { private readonly _values: any[] = []; public _read(id: EditorOption): T | undefined { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index f736287cc76..cb44b48319c 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -756,91 +756,6 @@ export interface IDiffEditorOptions extends IEditorOptions { originalEditable?: boolean; } -/** - * 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 -} - -/** - * 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; - } -} - /** * An event describing that the configuration of the editor has changed. */ @@ -858,6 +773,9 @@ export class ConfigurationChangedEvent { } } +/** + * @internal + */ export interface IEnvironmentalOptions { readonly outerWidth: number; readonly outerHeight: number; @@ -935,27 +853,6 @@ function _float(value: any, defaultValue: number): number { return (isNaN(r) ? defaultValue : r); } -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; - } -} - -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; - } -} - /** * @internal */ @@ -987,36 +884,6 @@ export interface IEditorLayoutProviderOpts { readonly pixelRatio: number; } -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 -}; /** * @internal @@ -1045,22 +912,6 @@ export interface IComputedEditorOptions { get(id: T): FindComputedEditorOptionValueById; } -/** - * @internal - */ -export class ComputedEditorOptions implements IComputedEditorOptions { - private readonly _values: any[] = []; - public _read(id: EditorOption): T { - return this._values[id]; - } - public get(id: T): FindComputedEditorOptionValueById { - return this._values[id]; - } - public _write(id: EditorOption, value: T): void { - this._values[id] = value; - } -} - //#region IEditorOption export interface IEditorOption { @@ -1258,6 +1109,109 @@ class EditorAriaLabel extends SimpleEditorOption