Skip to content

Commit

Permalink
clean up from #13925
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Oct 21, 2016
1 parent 1d59084 commit 89fbdde
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
17 changes: 4 additions & 13 deletions src/vs/base/parts/quickopen/browser/quickOpenWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class QuickOpenWidget implements IModelProvider {

const focus = this.tree.getFocus();
if (focus) {
this.elementSelected(focus, keyboardEvent);
this.elementSelected(focus, keyboardEvent, keyboardEvent.keyCode === KeyCode.RightArrow ? Mode.OPEN_IN_BACKGROUND : Mode.OPEN);
}
}

Expand Down Expand Up @@ -401,23 +401,14 @@ export class QuickOpenWidget implements IModelProvider {
this.model.runner.run(value, Mode.PREVIEW, context);
}

private elementSelected(value: any, event?: any): void {
private elementSelected(value: any, event?: any, preferredMode?: Mode): void {
let hide = true;

// Trigger open of element on selection
if (this.isVisible()) {
let eventForContext = event;
let mode = Mode.OPEN;
let mode = preferredMode || Mode.OPEN;

if (event instanceof StandardKeyboardEvent) {
eventForContext = event.browserEvent;

if (event.keyCode === KeyCode.RightArrow) {
mode = Mode.OPEN_IN_BACKGROUND;
}
}

const context: IEntryRunContext = { event: eventForContext, keymods: this.extractKeyMods(eventForContext), quickNavigateConfiguration: this.quickNavigateConfiguration };
const context: IEntryRunContext = { event, keymods: this.extractKeyMods(event), quickNavigateConfiguration: this.quickNavigateConfiguration };

hide = this.model.runner.run(value, mode, context);
}
Expand Down
36 changes: 20 additions & 16 deletions src/vs/workbench/browser/quickopen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { KeyMod } from 'vs/base/common/keyCodes';
import { Mode, IEntryRunContext, IAutoFocus, IModel, IQuickNavigateConfiguration } from 'vs/base/parts/quickopen/common/quickOpen';
import { QuickOpenEntry, IHighlight, QuickOpenEntryGroup, QuickOpenModel } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { EditorOptions, EditorInput } from 'vs/workbench/common/editor';
import { IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
import { IResourceInput, IEditorInput, IEditorOptions } from 'vs/platform/editor/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
import { AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
Expand Down Expand Up @@ -244,34 +244,38 @@ export class EditorQuickOpenEntry extends QuickOpenEntry implements IEditorQuick
}

public getOptions(): EditorOptions {
return EditorOptions.create({});
return null;
}

public run(mode: Mode, context: IEntryRunContext): boolean {
const hideWidget = mode === Mode.OPEN;
const hideWidget = (mode === Mode.OPEN);

if (mode === Mode.OPEN || mode === Mode.OPEN_IN_BACKGROUND) {
let sideBySide = context.keymods.indexOf(KeyMod.CtrlCmd) >= 0;
let opts = this.getOptions();

let backgroundOpts;
let openInBackgroundOptions: IEditorOptions;
if (mode === Mode.OPEN_IN_BACKGROUND) {
backgroundOpts = { pinned: true, preserveFocus: true };
opts.mixin(backgroundOpts);
openInBackgroundOptions = { pinned: true, preserveFocus: true };
}

let input = this.getInput();
if (input instanceof EditorInput) {
let opts = this.getOptions();
if (opts) {
opts.mixin(openInBackgroundOptions);
} else if (openInBackgroundOptions) {
opts = EditorOptions.create(openInBackgroundOptions);
}

this.editorService.openEditor(input, opts, sideBySide).done(null, errors.onUnexpectedError);
}
else {
if (backgroundOpts) {
(<IResourceInput>input).options = objects.assign(
(<IResourceInput>input).options || {},
backgroundOpts
);
} else {
const resourceInput = <IResourceInput>input;

if (openInBackgroundOptions) {
resourceInput.options = objects.assign(resourceInput.options || Object.create(null), openInBackgroundOptions);
}
this.editorService.openEditor(<IResourceInput>input, sideBySide).done(null, errors.onUnexpectedError);

this.editorService.openEditor(resourceInput, sideBySide).done(null, errors.onUnexpectedError);
}
}

Expand Down Expand Up @@ -431,4 +435,4 @@ export class QuickOpenAction extends Action {

return TPromise.as(null);
}
}
}
15 changes: 9 additions & 6 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,15 @@ export class EditorOptions implements IEditorOptions {
/**
* Inherit all options from other EditorOptions instance.
*/
public mixin(other: EditorOptions): void {
this.preserveFocus = other.preserveFocus;
this.forceOpen = other.forceOpen;
this.revealIfVisible = other.revealIfVisible;
this.pinned = other.pinned;
this.index = other.index;
public mixin(other: IEditorOptions): void {
if (other) {
this.preserveFocus = other.preserveFocus;
this.forceOpen = other.forceOpen;
this.revealIfVisible = other.revealIfVisible;
this.pinned = other.pinned;
this.index = other.index;
this.inactive = other.inactive;
}
}

/**
Expand Down

2 comments on commit 89fbdde

@wprater
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bpasero since you're setting the mode in the elementSelected method, should you pass the original event as it were before?

@bpasero
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh yes, thanks!

Please sign in to comment.