Skip to content

Commit

Permalink
Allow middle mouse click to open file entry in the background (#42769)
Browse files Browse the repository at this point in the history
* Allow middle mouse click to open file entry in the background

* Remove unnecessary assignment

* Remove unnecessary payload

* Go with preferred way

* 💄
  • Loading branch information
usernamehw authored and bpasero committed Feb 5, 2018
1 parent 10e8ce9 commit 81d6d82
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/vs/base/parts/quickopen/browser/quickOpenWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import { Color } from 'vs/base/common/color';
import { mixin } from 'vs/base/common/objects';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';

export interface IQuickOpenCallbacks {
onOk: () => void;
Expand Down Expand Up @@ -253,7 +254,10 @@ export class QuickOpenWidget implements IModelProvider {

this.toUnbind.push(this.tree.onDidChangeSelection((event: ISelectionEvent) => {
if (event.selection && event.selection.length > 0) {
this.elementSelected(event.selection[0], event);
const mouseEvent: StandardMouseEvent = event.payload && event.payload.originalEvent instanceof StandardMouseEvent ? event.payload.originalEvent : void 0;
const shouldOpenInBackground = mouseEvent ? this.shouldOpenInBackground(mouseEvent) : false;

this.elementSelected(event.selection[0], event, shouldOpenInBackground ? Mode.OPEN_IN_BACKGROUND : Mode.OPEN);
}
}));
}).
Expand Down Expand Up @@ -399,19 +403,26 @@ export class QuickOpenWidget implements IModelProvider {
}
}

private shouldOpenInBackground(e: StandardKeyboardEvent): boolean {
if (e.keyCode !== KeyCode.RightArrow) {
return false; // only for right arrow
}
private shouldOpenInBackground(e: StandardKeyboardEvent | StandardMouseEvent): boolean {

// Keyboard
if (e instanceof StandardKeyboardEvent) {
if (e.keyCode !== KeyCode.RightArrow) {
return false; // only for right arrow
}

if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
return false; // no modifiers allowed
}

if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
return false; // no modifiers allowed
// validate the cursor is at the end of the input and there is no selection,
// and if not prevent opening in the background such as the selection can be changed
const element = this.inputBox.inputElement;
return element.selectionEnd === this.inputBox.value.length && element.selectionStart === element.selectionEnd;
}

// validate the cursor is at the end of the input and there is no selection,
// and if not prevent opening in the background such as the selection can be changed
const element = this.inputBox.inputElement;
return element.selectionEnd === this.inputBox.value.length && element.selectionStart === element.selectionEnd;
// Mouse
return e.middleButton;
}

private onType(): void {
Expand Down

0 comments on commit 81d6d82

Please sign in to comment.