From c35b4b42900a7d100fa8ed8f24ac0e75adca418b Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 24 May 2017 16:43:49 +0200 Subject: [PATCH] Introduce `multicursorModifier` editor options --- .../common/config/commonEditorConfig.ts | 6 ++++ src/vs/editor/common/config/editorOptions.ts | 34 +++++++++++++++++++ src/vs/monaco.d.ts | 7 ++++ 3 files changed, 47 insertions(+) diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 6fca4c237d0..bf24f6608be 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -321,6 +321,12 @@ const editorConfiguration: IConfigurationNode = { 'default': EDITOR_DEFAULTS.viewInfo.scrollbar.mouseWheelScrollSensitivity, 'description': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events") }, + 'editor.multicursorModifier': { + 'type': 'string', + 'enum': (platform.isMacintosh ? ['cmd', 'alt'] : ['ctrl', 'alt']), + 'default': 'alt', + 'description': nls.localize('multicursorModifier', "The modifier to be used to add multiple cursors with the mouse.") + }, 'editor.quickSuggestions': { 'anyOf': [ { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 59056ff8227..720302d227e 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -331,6 +331,11 @@ export interface IEditorOptions { * Defaults to 1. */ mouseWheelScrollSensitivity?: number; + /** + * The modifier to be used to add multiple cursors with the mouse. + * Defaults to 'alt' + */ + multicursorModifier?: 'cmd' | 'ctrl' | 'alt'; /** * Enable quick suggestions (shadow suggestions) * Defaults to true. @@ -783,6 +788,7 @@ export interface IValidatedEditorOptions { readonly dragAndDrop: boolean; readonly emptySelectionClipboard: boolean; readonly useTabStops: boolean; + readonly multicursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; readonly viewInfo: InternalEditorViewOptions; readonly contribInfo: EditorContribOptions; @@ -803,6 +809,7 @@ export class InternalEditorOptions { * @internal */ readonly accessibilitySupport: platform.AccessibilitySupport; + readonly multicursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; // ---- cursor options readonly wordSeparators: string; @@ -829,6 +836,7 @@ export class InternalEditorOptions { lineHeight: number; readOnly: boolean; accessibilitySupport: platform.AccessibilitySupport; + multicursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; wordSeparators: string; autoClosingBrackets: boolean; useTabStops: boolean; @@ -847,6 +855,7 @@ export class InternalEditorOptions { this.lineHeight = source.lineHeight | 0; this.readOnly = source.readOnly; this.accessibilitySupport = source.accessibilitySupport; + this.multicursorModifier = source.multicursorModifier; this.wordSeparators = source.wordSeparators; this.autoClosingBrackets = source.autoClosingBrackets; this.useTabStops = source.useTabStops; @@ -871,6 +880,7 @@ export class InternalEditorOptions { && this.lineHeight === other.lineHeight && this.readOnly === other.readOnly && this.accessibilitySupport === other.accessibilitySupport + && this.multicursorModifier === other.multicursorModifier && this.wordSeparators === other.wordSeparators && this.autoClosingBrackets === other.autoClosingBrackets && this.useTabStops === other.useTabStops @@ -896,6 +906,7 @@ export class InternalEditorOptions { lineHeight: (this.lineHeight !== newOpts.lineHeight), readOnly: (this.readOnly !== newOpts.readOnly), accessibilitySupport: (this.accessibilitySupport !== newOpts.accessibilitySupport), + multicursorModifier: (this.multicursorModifier !== newOpts.multicursorModifier), wordSeparators: (this.wordSeparators !== newOpts.wordSeparators), autoClosingBrackets: (this.autoClosingBrackets !== newOpts.autoClosingBrackets), useTabStops: (this.useTabStops !== newOpts.useTabStops), @@ -1233,6 +1244,7 @@ export interface IConfigurationChangedEvent { readonly lineHeight: boolean; readonly readOnly: boolean; readonly accessibilitySupport: boolean; + readonly multicursorModifier: boolean; readonly wordSeparators: boolean; readonly autoClosingBrackets: boolean; readonly useTabStops: boolean; @@ -1386,6 +1398,24 @@ export class EditorOptionsValidator { const viewInfo = this._sanitizeViewInfo(opts, defaults.viewInfo); const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo); + let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey'; + if (typeof opts.multicursorModifier === 'string') { + if (platform.isMacintosh) { + if (opts.multicursorModifier === 'cmd') { + configuredMulticursorModifier = 'metaKey'; + } else { + configuredMulticursorModifier = 'altKey'; + } + } else { + if (opts.multicursorModifier === 'ctrl') { + configuredMulticursorModifier = 'ctrlKey'; + } else { + configuredMulticursorModifier = 'altKey'; + } + } + } + const multicursorModifier = _stringSet<'altKey' | 'metaKey' | 'ctrlKey'>(configuredMulticursorModifier, defaults.multicursorModifier, ['altKey', 'metaKey', 'ctrlKey']); + return { inDiffEditor: _boolean(opts.inDiffEditor, defaults.inDiffEditor), wordSeparators: _string(opts.wordSeparators, defaults.wordSeparators), @@ -1406,6 +1436,7 @@ export class EditorOptionsValidator { dragAndDrop: _boolean(opts.dragAndDrop, defaults.dragAndDrop), emptySelectionClipboard: _boolean(opts.emptySelectionClipboard, defaults.emptySelectionClipboard), useTabStops: _boolean(opts.useTabStops, defaults.useTabStops), + multicursorModifier: multicursorModifier, viewInfo: viewInfo, contribInfo: contribInfo, }; @@ -1629,6 +1660,7 @@ export class InternalEditorOptionsFactory { dragAndDrop: opts.dragAndDrop, emptySelectionClipboard: opts.emptySelectionClipboard, useTabStops: opts.useTabStops, + multicursorModifier: opts.multicursorModifier, viewInfo: { extraEditorClassName: opts.viewInfo.extraEditorClassName, @@ -1805,6 +1837,7 @@ export class InternalEditorOptionsFactory { lineHeight: env.fontInfo.lineHeight, readOnly: opts.readOnly, accessibilitySupport: env.accessibilitySupport, + multicursorModifier: opts.multicursorModifier, wordSeparators: opts.wordSeparators, autoClosingBrackets: opts.autoClosingBrackets, useTabStops: opts.useTabStops, @@ -2023,6 +2056,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = { dragAndDrop: false, emptySelectionClipboard: true, useTabStops: true, + multicursorModifier: 'altKey', viewInfo: { extraEditorClassName: '', diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 707cb1047fa..7f3c80b83fa 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2876,6 +2876,11 @@ declare module monaco.editor { * Defaults to 1. */ mouseWheelScrollSensitivity?: number; + /** + * The modifier to be used to add multiple cursors with the mouse. + * Defaults to 'alt' + */ + multicursorModifier?: 'cmd' | 'ctrl' | 'alt'; /** * Enable quick suggestions (shadow suggestions) * Defaults to true. @@ -3257,6 +3262,7 @@ declare module monaco.editor { readonly editorClassName: string; readonly lineHeight: number; readonly readOnly: boolean; + readonly multicursorModifier: 'altKey' | 'ctrlKey' | 'metaKey'; readonly wordSeparators: string; readonly autoClosingBrackets: boolean; readonly useTabStops: boolean; @@ -3388,6 +3394,7 @@ declare module monaco.editor { readonly lineHeight: boolean; readonly readOnly: boolean; readonly accessibilitySupport: boolean; + readonly multicursorModifier: boolean; readonly wordSeparators: boolean; readonly autoClosingBrackets: boolean; readonly useTabStops: boolean;