Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow middle mouse click to open file entry in the background #42769

Merged
merged 5 commits into from
Feb 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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