Skip to content

Commit

Permalink
Improve the discoverability of column selection
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 21, 2020
1 parent 0c369e2 commit 1a6b2ea
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 203 deletions.
22 changes: 21 additions & 1 deletion src/vs/editor/browser/controller/coreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/browser/controller/mouseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/vs/editor/browser/view/viewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ class EditorContextKeysManager extends Disposable {
private readonly _editorTextFocus: IContextKey<boolean>;
private readonly _editorTabMovesFocus: IContextKey<boolean>;
private readonly _editorReadonly: IContextKey<boolean>;
private readonly _editorColumnSelection: IContextKey<boolean>;
private readonly _hasMultipleSelections: IContextKey<boolean>;
private readonly _hasNonEmptySelection: IContextKey<boolean>;
private readonly _canUndo: IContextKey<boolean>;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -3294,6 +3299,7 @@ export const enum EditorOption {
autoSurround,
codeLens,
colorDecorators,
columnSelection,
comments,
contextmenu,
copyWithSyntaxHighlighting,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/editorContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export namespace EditorContextKeys {
export const textInputFocus = new RawContextKey<boolean>('textInputFocus', false);

export const readOnly = new RawContextKey<boolean>('editorReadonly', false);
export const columnSelection = new RawContextKey<boolean>('editorColumnSelection', false);
export const writable: ContextKeyExpr = readOnly.toNegated();
export const hasNonEmptySelection = new RawContextKey<boolean>('editorHasSelection', false);
export const hasOnlyEmptySelection: ContextKeyExpr = hasNonEmptySelection.toNegated();
Expand Down
199 changes: 100 additions & 99 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/dnd/dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit 1a6b2ea

Please sign in to comment.