Skip to content

Commit

Permalink
Fixes #28186: Do column selection when using middle mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Apr 17, 2018
1 parent 63d9bf4 commit 5d37bdf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/vs/editor/browser/controller/mouseHandler.ts
Expand Up @@ -220,8 +220,8 @@ export class MouseHandler extends ViewEventHandler {
let targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE);
let targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET);

let shouldHandle = e.leftButton;
if (platform.isMacintosh && e.ctrlKey) {
let shouldHandle = e.leftButton || e.middleButton;
if (platform.isMacintosh && e.leftButton && e.ctrlKey) {
shouldHandle = false;
}

Expand Down Expand Up @@ -334,6 +334,7 @@ class MouseDownOperation extends Disposable {
this._lastMouseEvent = e;

this._mouseState.setStartedOnLineNumbers(targetType === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS);
this._mouseState.setStartButtons(e);
this._mouseState.setModifiers(e);
let position = this._findMousePosition(e, true);
if (!position) {
Expand Down Expand Up @@ -488,6 +489,9 @@ class MouseDownOperation extends Disposable {
ctrlKey: this._mouseState.ctrlKey,
metaKey: this._mouseState.metaKey,
shiftKey: this._mouseState.shiftKey,

leftButton: this._mouseState.leftButton,
middleButton: this._mouseState.middleButton,
});
}
}
Expand All @@ -508,6 +512,12 @@ class MouseDownState {
private _shiftKey: boolean;
public get shiftKey(): boolean { return this._shiftKey; }

private _leftButton: boolean;
public get leftButton(): boolean { return this._leftButton; }

private _middleButton: boolean;
public get middleButton(): boolean { return this._middleButton; }

private _startedOnLineNumbers: boolean;
public get startedOnLineNumbers(): boolean { return this._startedOnLineNumbers; }

Expand All @@ -522,6 +532,8 @@ class MouseDownState {
this._ctrlKey = false;
this._metaKey = false;
this._shiftKey = false;
this._leftButton = false;
this._middleButton = false;
this._startedOnLineNumbers = false;
this._lastMouseDownPosition = null;
this._lastMouseDownPositionEqualCount = 0;
Expand All @@ -541,6 +553,11 @@ class MouseDownState {
this._shiftKey = source.shiftKey;
}

public setStartButtons(source: EditorMouseEvent) {
this._leftButton = source.leftButton;
this._middleButton = source.middleButton;
}

public setStartedOnLineNumbers(startedOnLineNumbers: boolean): void {
this._startedOnLineNumbers = startedOnLineNumbers;
}
Expand Down
11 changes: 10 additions & 1 deletion src/vs/editor/browser/view/viewController.ts
Expand Up @@ -31,6 +31,9 @@ export interface IMouseDispatchData {
ctrlKey: boolean;
metaKey: boolean;
shiftKey: boolean;

leftButton: boolean;
middleButton: boolean;
}

export interface ICommandDelegate {
Expand Down Expand Up @@ -133,7 +136,13 @@ export class ViewController {
}

public dispatchMouse(data: IMouseDispatchData): void {
if (data.startedOnLineNumbers) {
if (data.middleButton) {
if (data.inSelectionMode) {
this.columnSelect(data.position, data.mouseColumn);
} else {
this.moveTo(data.position);
}
} else if (data.startedOnLineNumbers) {
// If the dragging started on the gutter, then have operations work on the entire line
if (this._hasMulticursorModifier(data)) {
if (data.inSelectionMode) {
Expand Down

0 comments on commit 5d37bdf

Please sign in to comment.