diff --git a/src/vs/editor/browser/controller/coreCommands.ts b/src/vs/editor/browser/controller/coreCommands.ts index 567b9cdc08a0a..ca00039a59243 100644 --- a/src/vs/editor/browser/controller/coreCommands.ts +++ b/src/vs/editor/browser/controller/coreCommands.ts @@ -24,7 +24,7 @@ import { MenuId } from 'vs/platform/actions/common/actions'; import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { KeybindingWeight, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { EditorOption } from 'vs/editor/common/config/editorOptions'; const CORE_WEIGHT = KeybindingWeight.EditorCore; @@ -1530,6 +1530,26 @@ export namespace CoreNavigationCommands { }); } +const columnSelectionCondition = ContextKeyExpr.and( + EditorContextKeys.textInputFocus, + EditorContextKeys.columnSelection +); +function registerColumnSelection(id: string, keybinding: number): void { + KeybindingsRegistry.registerKeybindingRule({ + id: id, + primary: keybinding, + when: columnSelectionCondition, + weight: CORE_WEIGHT + 1 + }); +} + +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectLeft.id, KeyMod.Shift | KeyCode.LeftArrow); +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectRight.id, KeyMod.Shift | KeyCode.RightArrow); +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectUp.id, KeyMod.Shift | KeyCode.UpArrow); +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageUp.id, KeyMod.Shift | KeyCode.PageUp); +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectDown.id, KeyMod.Shift | KeyCode.DownArrow); +registerColumnSelection(CoreNavigationCommands.CursorColumnSelectPageDown.id, KeyMod.Shift | KeyCode.PageDown); + /** * A command that will: * 1. invoke a command on the focused editor. diff --git a/src/vs/editor/browser/controller/mouseHandler.ts b/src/vs/editor/browser/controller/mouseHandler.ts index 0e5f6b0d45426..5bab90e5eb1b5 100644 --- a/src/vs/editor/browser/controller/mouseHandler.ts +++ b/src/vs/editor/browser/controller/mouseHandler.ts @@ -352,6 +352,7 @@ class MouseDownOperation extends Disposable { if (!options.get(EditorOption.readOnly) && options.get(EditorOption.dragAndDrop) + && !options.get(EditorOption.columnSelection) && !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/view/viewController.ts b/src/vs/editor/browser/view/viewController.ts index d2eb4bdd1f14c..d99af7b2b6648 100644 --- a/src/vs/editor/browser/view/viewController.ts +++ b/src/vs/editor/browser/view/viewController.ts @@ -133,7 +133,9 @@ export class ViewController { } public dispatchMouse(data: IMouseDispatchData): void { - const selectionClipboardIsOn = (platform.isLinux && this.configuration.options.get(EditorOption.selectionClipboard)); + const options = this.configuration.options; + const selectionClipboardIsOn = (platform.isLinux && options.get(EditorOption.selectionClipboard)); + const columnSelection = options.get(EditorOption.columnSelection); if (data.middleButton && !selectionClipboardIsOn) { this._columnSelect(data.position, data.mouseColumn, data.inSelectionMode); } else if (data.startedOnLineNumbers) { @@ -196,7 +198,11 @@ export class ViewController { if (data.altKey) { this._columnSelect(data.position, data.mouseColumn, true); } else { - this._moveToSelect(data.position); + if (columnSelection) { + this._columnSelect(data.position, data.mouseColumn, true); + } else { + this._moveToSelect(data.position); + } } } else { this.moveTo(data.position); diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 5262d8003b968..c8be02dfba7e7 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -1666,6 +1666,7 @@ class EditorContextKeysManager extends Disposable { private readonly _editorTextFocus: IContextKey; private readonly _editorTabMovesFocus: IContextKey; private readonly _editorReadonly: IContextKey; + private readonly _editorColumnSelection: IContextKey; private readonly _hasMultipleSelections: IContextKey; private readonly _hasNonEmptySelection: IContextKey; private readonly _canUndo: IContextKey; @@ -1687,6 +1688,7 @@ class EditorContextKeysManager extends Disposable { this._editorTextFocus = EditorContextKeys.editorTextFocus.bindTo(contextKeyService); this._editorTabMovesFocus = EditorContextKeys.tabMovesFocus.bindTo(contextKeyService); this._editorReadonly = EditorContextKeys.readOnly.bindTo(contextKeyService); + this._editorColumnSelection = EditorContextKeys.columnSelection.bindTo(contextKeyService); this._hasMultipleSelections = EditorContextKeys.hasMultipleSelections.bindTo(contextKeyService); this._hasNonEmptySelection = EditorContextKeys.hasNonEmptySelection.bindTo(contextKeyService); this._canUndo = EditorContextKeys.canUndo.bindTo(contextKeyService); @@ -1714,6 +1716,7 @@ class EditorContextKeysManager extends Disposable { this._editorTabMovesFocus.set(options.get(EditorOption.tabFocusMode)); this._editorReadonly.set(options.get(EditorOption.readOnly)); + this._editorColumnSelection.set(options.get(EditorOption.columnSelection)); } private _updateFromSelection(): void { diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index a187f9718e518..eb7a44e4089ce 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -324,6 +324,11 @@ export interface IEditorOptions { * Defaults to true. */ scrollPredominantAxis?: boolean; + /** + * Enable that the selection with the mouse and keys is doing column selection. + * Defaults to false. + */ + columnSelection?: boolean; /** * The modifier to be used to add multiple cursors with the mouse. * Defaults to 'alt' @@ -3294,6 +3299,7 @@ export const enum EditorOption { autoSurround, codeLens, colorDecorators, + columnSelection, comments, contextmenu, copyWithSyntaxHighlighting, @@ -3518,6 +3524,10 @@ export const EditorOptions = { EditorOption.colorDecorators, 'colorDecorators', true, { description: nls.localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") } )), + columnSelection: register(new EditorBooleanOption( + EditorOption.columnSelection, 'columnSelection', false, + { description: nls.localize('columnSelection', "Enable that the selection with the mouse and keys is doing column selection.") } + )), comments: register(new EditorComments()), contextmenu: register(new EditorBooleanOption( EditorOption.contextmenu, 'contextmenu', true, diff --git a/src/vs/editor/common/editorContextKeys.ts b/src/vs/editor/common/editorContextKeys.ts index f15b80910736f..0166842056904 100644 --- a/src/vs/editor/common/editorContextKeys.ts +++ b/src/vs/editor/common/editorContextKeys.ts @@ -23,6 +23,7 @@ export namespace EditorContextKeys { export const textInputFocus = new RawContextKey('textInputFocus', false); export const readOnly = new RawContextKey('editorReadonly', false); + export const columnSelection = new RawContextKey('editorColumnSelection', false); export const writable: ContextKeyExpr = readOnly.toNegated(); export const hasNonEmptySelection = new RawContextKey('editorHasSelection', false); export const hasOnlyEmptySelection: ContextKeyExpr = hasNonEmptySelection.toNegated(); diff --git a/src/vs/editor/common/standalone/standaloneEnums.ts b/src/vs/editor/common/standalone/standaloneEnums.ts index 90a9fe1b99697..14e4cfb12fc2a 100644 --- a/src/vs/editor/common/standalone/standaloneEnums.ts +++ b/src/vs/editor/common/standalone/standaloneEnums.ts @@ -178,105 +178,106 @@ export enum EditorOption { autoSurround = 10, codeLens = 11, colorDecorators = 12, - comments = 13, - contextmenu = 14, - copyWithSyntaxHighlighting = 15, - cursorBlinking = 16, - cursorSmoothCaretAnimation = 17, - cursorStyle = 18, - cursorSurroundingLines = 19, - cursorSurroundingLinesStyle = 20, - cursorWidth = 21, - disableLayerHinting = 22, - disableMonospaceOptimizations = 23, - dragAndDrop = 24, - emptySelectionClipboard = 25, - extraEditorClassName = 26, - fastScrollSensitivity = 27, - find = 28, - fixedOverflowWidgets = 29, - folding = 30, - foldingStrategy = 31, - foldingHighlight = 32, - fontFamily = 33, - fontInfo = 34, - fontLigatures = 35, - fontSize = 36, - fontWeight = 37, - formatOnPaste = 38, - formatOnType = 39, - glyphMargin = 40, - gotoLocation = 41, - hideCursorInOverviewRuler = 42, - highlightActiveIndentGuide = 43, - hover = 44, - inDiffEditor = 45, - letterSpacing = 46, - lightbulb = 47, - lineDecorationsWidth = 48, - lineHeight = 49, - lineNumbers = 50, - lineNumbersMinChars = 51, - links = 52, - matchBrackets = 53, - minimap = 54, - mouseStyle = 55, - mouseWheelScrollSensitivity = 56, - mouseWheelZoom = 57, - multiCursorMergeOverlapping = 58, - multiCursorModifier = 59, - multiCursorPaste = 60, - occurrencesHighlight = 61, - overviewRulerBorder = 62, - overviewRulerLanes = 63, - padding = 64, - parameterHints = 65, - peekWidgetDefaultFocus = 66, - definitionLinkOpensInPeek = 67, - quickSuggestions = 68, - quickSuggestionsDelay = 69, - readOnly = 70, - renderControlCharacters = 71, - renderIndentGuides = 72, - renderFinalNewline = 73, - renderLineHighlight = 74, - renderValidationDecorations = 75, - renderWhitespace = 76, - revealHorizontalRightPadding = 77, - roundedSelection = 78, - rulers = 79, - scrollbar = 80, - scrollBeyondLastColumn = 81, - scrollBeyondLastLine = 82, - scrollPredominantAxis = 83, - selectionClipboard = 84, - selectionHighlight = 85, - selectOnLineNumbers = 86, - showFoldingControls = 87, - showUnused = 88, - snippetSuggestions = 89, - smoothScrolling = 90, - stopRenderingLineAfter = 91, - suggest = 92, - suggestFontSize = 93, - suggestLineHeight = 94, - suggestOnTriggerCharacters = 95, - suggestSelection = 96, - tabCompletion = 97, - useTabStops = 98, - wordSeparators = 99, - wordWrap = 100, - wordWrapBreakAfterCharacters = 101, - wordWrapBreakBeforeCharacters = 102, - wordWrapColumn = 103, - wordWrapMinified = 104, - wrappingIndent = 105, - wrappingStrategy = 106, - editorClassName = 107, - pixelRatio = 108, - tabFocusMode = 109, - layoutInfo = 110, - wrappingInfo = 111 + columnSelection = 13, + comments = 14, + contextmenu = 15, + copyWithSyntaxHighlighting = 16, + cursorBlinking = 17, + cursorSmoothCaretAnimation = 18, + cursorStyle = 19, + cursorSurroundingLines = 20, + cursorSurroundingLinesStyle = 21, + cursorWidth = 22, + disableLayerHinting = 23, + disableMonospaceOptimizations = 24, + dragAndDrop = 25, + emptySelectionClipboard = 26, + extraEditorClassName = 27, + fastScrollSensitivity = 28, + find = 29, + fixedOverflowWidgets = 30, + folding = 31, + foldingStrategy = 32, + foldingHighlight = 33, + fontFamily = 34, + fontInfo = 35, + fontLigatures = 36, + fontSize = 37, + fontWeight = 38, + formatOnPaste = 39, + formatOnType = 40, + glyphMargin = 41, + gotoLocation = 42, + hideCursorInOverviewRuler = 43, + highlightActiveIndentGuide = 44, + hover = 45, + inDiffEditor = 46, + letterSpacing = 47, + lightbulb = 48, + lineDecorationsWidth = 49, + lineHeight = 50, + lineNumbers = 51, + lineNumbersMinChars = 52, + links = 53, + matchBrackets = 54, + minimap = 55, + mouseStyle = 56, + mouseWheelScrollSensitivity = 57, + mouseWheelZoom = 58, + multiCursorMergeOverlapping = 59, + multiCursorModifier = 60, + multiCursorPaste = 61, + occurrencesHighlight = 62, + overviewRulerBorder = 63, + overviewRulerLanes = 64, + padding = 65, + parameterHints = 66, + peekWidgetDefaultFocus = 67, + definitionLinkOpensInPeek = 68, + quickSuggestions = 69, + quickSuggestionsDelay = 70, + readOnly = 71, + renderControlCharacters = 72, + renderIndentGuides = 73, + renderFinalNewline = 74, + renderLineHighlight = 75, + renderValidationDecorations = 76, + renderWhitespace = 77, + revealHorizontalRightPadding = 78, + roundedSelection = 79, + rulers = 80, + scrollbar = 81, + scrollBeyondLastColumn = 82, + scrollBeyondLastLine = 83, + scrollPredominantAxis = 84, + selectionClipboard = 85, + selectionHighlight = 86, + selectOnLineNumbers = 87, + showFoldingControls = 88, + showUnused = 89, + snippetSuggestions = 90, + smoothScrolling = 91, + stopRenderingLineAfter = 92, + suggest = 93, + suggestFontSize = 94, + suggestLineHeight = 95, + suggestOnTriggerCharacters = 96, + suggestSelection = 97, + tabCompletion = 98, + useTabStops = 99, + wordSeparators = 100, + wordWrap = 101, + wordWrapBreakAfterCharacters = 102, + wordWrapBreakBeforeCharacters = 103, + wordWrapColumn = 104, + wordWrapMinified = 105, + wrappingIndent = 106, + wrappingStrategy = 107, + editorClassName = 108, + pixelRatio = 109, + tabFocusMode = 110, + layoutInfo = 111, + wrappingInfo = 112 } /** diff --git a/src/vs/editor/contrib/dnd/dnd.ts b/src/vs/editor/contrib/dnd/dnd.ts index ea3cda654bc32..599e804eb05df 100644 --- a/src/vs/editor/contrib/dnd/dnd.ts +++ b/src/vs/editor/contrib/dnd/dnd.ts @@ -68,7 +68,7 @@ export class DragAndDropController extends Disposable implements IEditorContribu } private onEditorKeyDown(e: IKeyboardEvent): void { - if (!this._editor.getOption(EditorOption.dragAndDrop)) { + if (!this._editor.getOption(EditorOption.dragAndDrop) || this._editor.getOption(EditorOption.columnSelection)) { return; } @@ -84,7 +84,7 @@ export class DragAndDropController extends Disposable implements IEditorContribu } private onEditorKeyUp(e: IKeyboardEvent): void { - if (!this._editor.getOption(EditorOption.dragAndDrop)) { + if (!this._editor.getOption(EditorOption.dragAndDrop) || this._editor.getOption(EditorOption.columnSelection)) { return; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 9fb1bf00712b1..4ca0cb14c1208 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2849,6 +2849,11 @@ declare namespace monaco.editor { * Defaults to true. */ scrollPredominantAxis?: boolean; + /** + * Enable that the selection with the mouse and keys is doing column selection. + * Defaults to false. + */ + columnSelection?: boolean; /** * The modifier to be used to add multiple cursors with the mouse. * Defaults to 'alt' @@ -3794,105 +3799,106 @@ declare namespace monaco.editor { autoSurround = 10, codeLens = 11, colorDecorators = 12, - comments = 13, - contextmenu = 14, - copyWithSyntaxHighlighting = 15, - cursorBlinking = 16, - cursorSmoothCaretAnimation = 17, - cursorStyle = 18, - cursorSurroundingLines = 19, - cursorSurroundingLinesStyle = 20, - cursorWidth = 21, - disableLayerHinting = 22, - disableMonospaceOptimizations = 23, - dragAndDrop = 24, - emptySelectionClipboard = 25, - extraEditorClassName = 26, - fastScrollSensitivity = 27, - find = 28, - fixedOverflowWidgets = 29, - folding = 30, - foldingStrategy = 31, - foldingHighlight = 32, - fontFamily = 33, - fontInfo = 34, - fontLigatures = 35, - fontSize = 36, - fontWeight = 37, - formatOnPaste = 38, - formatOnType = 39, - glyphMargin = 40, - gotoLocation = 41, - hideCursorInOverviewRuler = 42, - highlightActiveIndentGuide = 43, - hover = 44, - inDiffEditor = 45, - letterSpacing = 46, - lightbulb = 47, - lineDecorationsWidth = 48, - lineHeight = 49, - lineNumbers = 50, - lineNumbersMinChars = 51, - links = 52, - matchBrackets = 53, - minimap = 54, - mouseStyle = 55, - mouseWheelScrollSensitivity = 56, - mouseWheelZoom = 57, - multiCursorMergeOverlapping = 58, - multiCursorModifier = 59, - multiCursorPaste = 60, - occurrencesHighlight = 61, - overviewRulerBorder = 62, - overviewRulerLanes = 63, - padding = 64, - parameterHints = 65, - peekWidgetDefaultFocus = 66, - definitionLinkOpensInPeek = 67, - quickSuggestions = 68, - quickSuggestionsDelay = 69, - readOnly = 70, - renderControlCharacters = 71, - renderIndentGuides = 72, - renderFinalNewline = 73, - renderLineHighlight = 74, - renderValidationDecorations = 75, - renderWhitespace = 76, - revealHorizontalRightPadding = 77, - roundedSelection = 78, - rulers = 79, - scrollbar = 80, - scrollBeyondLastColumn = 81, - scrollBeyondLastLine = 82, - scrollPredominantAxis = 83, - selectionClipboard = 84, - selectionHighlight = 85, - selectOnLineNumbers = 86, - showFoldingControls = 87, - showUnused = 88, - snippetSuggestions = 89, - smoothScrolling = 90, - stopRenderingLineAfter = 91, - suggest = 92, - suggestFontSize = 93, - suggestLineHeight = 94, - suggestOnTriggerCharacters = 95, - suggestSelection = 96, - tabCompletion = 97, - useTabStops = 98, - wordSeparators = 99, - wordWrap = 100, - wordWrapBreakAfterCharacters = 101, - wordWrapBreakBeforeCharacters = 102, - wordWrapColumn = 103, - wordWrapMinified = 104, - wrappingIndent = 105, - wrappingStrategy = 106, - editorClassName = 107, - pixelRatio = 108, - tabFocusMode = 109, - layoutInfo = 110, - wrappingInfo = 111 + columnSelection = 13, + comments = 14, + contextmenu = 15, + copyWithSyntaxHighlighting = 16, + cursorBlinking = 17, + cursorSmoothCaretAnimation = 18, + cursorStyle = 19, + cursorSurroundingLines = 20, + cursorSurroundingLinesStyle = 21, + cursorWidth = 22, + disableLayerHinting = 23, + disableMonospaceOptimizations = 24, + dragAndDrop = 25, + emptySelectionClipboard = 26, + extraEditorClassName = 27, + fastScrollSensitivity = 28, + find = 29, + fixedOverflowWidgets = 30, + folding = 31, + foldingStrategy = 32, + foldingHighlight = 33, + fontFamily = 34, + fontInfo = 35, + fontLigatures = 36, + fontSize = 37, + fontWeight = 38, + formatOnPaste = 39, + formatOnType = 40, + glyphMargin = 41, + gotoLocation = 42, + hideCursorInOverviewRuler = 43, + highlightActiveIndentGuide = 44, + hover = 45, + inDiffEditor = 46, + letterSpacing = 47, + lightbulb = 48, + lineDecorationsWidth = 49, + lineHeight = 50, + lineNumbers = 51, + lineNumbersMinChars = 52, + links = 53, + matchBrackets = 54, + minimap = 55, + mouseStyle = 56, + mouseWheelScrollSensitivity = 57, + mouseWheelZoom = 58, + multiCursorMergeOverlapping = 59, + multiCursorModifier = 60, + multiCursorPaste = 61, + occurrencesHighlight = 62, + overviewRulerBorder = 63, + overviewRulerLanes = 64, + padding = 65, + parameterHints = 66, + peekWidgetDefaultFocus = 67, + definitionLinkOpensInPeek = 68, + quickSuggestions = 69, + quickSuggestionsDelay = 70, + readOnly = 71, + renderControlCharacters = 72, + renderIndentGuides = 73, + renderFinalNewline = 74, + renderLineHighlight = 75, + renderValidationDecorations = 76, + renderWhitespace = 77, + revealHorizontalRightPadding = 78, + roundedSelection = 79, + rulers = 80, + scrollbar = 81, + scrollBeyondLastColumn = 82, + scrollBeyondLastLine = 83, + scrollPredominantAxis = 84, + selectionClipboard = 85, + selectionHighlight = 86, + selectOnLineNumbers = 87, + showFoldingControls = 88, + showUnused = 89, + snippetSuggestions = 90, + smoothScrolling = 91, + stopRenderingLineAfter = 92, + suggest = 93, + suggestFontSize = 94, + suggestLineHeight = 95, + suggestOnTriggerCharacters = 96, + suggestSelection = 97, + tabCompletion = 98, + useTabStops = 99, + wordSeparators = 100, + wordWrap = 101, + wordWrapBreakAfterCharacters = 102, + wordWrapBreakBeforeCharacters = 103, + wordWrapColumn = 104, + wordWrapMinified = 105, + wrappingIndent = 106, + wrappingStrategy = 107, + editorClassName = 108, + pixelRatio = 109, + tabFocusMode = 110, + layoutInfo = 111, + wrappingInfo = 112 } export const EditorOptions: { acceptSuggestionOnCommitCharacter: IEditorOption; @@ -3908,6 +3914,7 @@ declare namespace monaco.editor { autoSurround: IEditorOption; codeLens: IEditorOption; colorDecorators: IEditorOption; + columnSelection: IEditorOption; comments: IEditorOption; contextmenu: IEditorOption; copyWithSyntaxHighlighting: IEditorOption; diff --git a/src/vs/workbench/contrib/codeEditor/browser/codeEditor.contribution.ts b/src/vs/workbench/contrib/codeEditor/browser/codeEditor.contribution.ts index 49cf081d9675c..eae8927c9126f 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/codeEditor.contribution.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/codeEditor.contribution.ts @@ -10,6 +10,7 @@ import './inspectKeybindings'; import './largeFileOptimizations'; import './inspectEditorTokens/inspectEditorTokens'; import './saveParticipants'; +import './toggleColumnSelection'; import './toggleMinimap'; import './toggleMultiCursorModifier'; import './toggleRenderControlCharacter'; diff --git a/src/vs/workbench/contrib/codeEditor/browser/toggleColumnSelection.ts b/src/vs/workbench/contrib/codeEditor/browser/toggleColumnSelection.ts new file mode 100644 index 0000000000000..6624e94c7bdb2 --- /dev/null +++ b/src/vs/workbench/contrib/codeEditor/browser/toggleColumnSelection.ts @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as nls from 'vs/nls'; +import { Action } from 'vs/base/common/actions'; +import { MenuId, MenuRegistry, SyncActionDescriptor } from 'vs/platform/actions/common/actions'; +import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions'; + +export class ToggleColumnSelectionAction extends Action { + public static readonly ID = 'editor.action.toggleColumnSelection'; + public static readonly LABEL = nls.localize('toggleColumnSelection', "Toggle Column Selection Mode"); + + constructor( + id: string, + label: string, + @IConfigurationService private readonly _configurationService: IConfigurationService + ) { + super(id, label); + } + + public run(): Promise { + const newValue = !this._configurationService.getValue('editor.columnSelection'); + return this._configurationService.updateValue('editor.columnSelection', newValue, ConfigurationTarget.USER); + } +} + +const registry = Registry.as(ActionExtensions.WorkbenchActions); +registry.registerWorkbenchAction(SyncActionDescriptor.create(ToggleColumnSelectionAction, ToggleColumnSelectionAction.ID, ToggleColumnSelectionAction.LABEL), 'View: Toggle Column Selection Mode', nls.localize('view', "View")); + +MenuRegistry.appendMenuItem(MenuId.MenubarSelectionMenu, { + group: '3_multi', + command: { + id: ToggleColumnSelectionAction.ID, + title: nls.localize({ key: 'miColumnSelection', comment: ['&& denotes a mnemonic'] }, "Column &&Selection Mode"), + toggled: ContextKeyExpr.equals('config.editor.columnSelection', true) + }, + order: 1.5 +});