diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index fd2de5827bf50..fb506dbe38070 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -174,6 +174,12 @@ export interface IEditorOptions { */ pinned?: boolean; + /** + * Editor that is being shown with an `forcePreview` will override the `enablePreview` setting + * of the workspace configuration to allow the editor to be shown as a preview editor. + */ + forcePreview?: boolean; + /** * The index in the document stack where to insert the editor into when opening. */ @@ -197,4 +203,4 @@ export interface ITextEditorOptions extends IEditorOptions { endLineNumber?: number; endColumn?: number; }; -} \ No newline at end of file +} diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 39f47cce016ff..ae9a82cf044b2 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -239,7 +239,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService // while the UI is not yet ready. Clients have to deal with this fact and we have to make sure that the // stacks model gets updated if any of the UI updating fails with an error. const group = this.ensureGroup(position, !options || !options.preserveFocus); - const pinned = !this.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty(); + const pinned = (!this.previewEditors && !(options && options.forcePreview)) || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty(); const active = (group.count === 0) || !options || !options.inactive; group.openEditor(input, { active, pinned, index: options && options.index }); @@ -1380,4 +1380,4 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService private hasGroup(position: Position): boolean { return !!this.stacks.groupAt(position); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/browser/parts/editor/editorPicker.ts b/src/vs/workbench/browser/parts/editor/editorPicker.ts index 4cec36daa7f70..f74843a68750a 100644 --- a/src/vs/workbench/browser/parts/editor/editorPicker.ts +++ b/src/vs/workbench/browser/parts/editor/editorPicker.ts @@ -16,16 +16,18 @@ import { IAutoFocus, Mode, IEntryRunContext, IQuickNavigateConfiguration } from import { QuickOpenModel, QuickOpenEntry, QuickOpenEntryGroup } from 'vs/base/parts/quickopen/browser/quickOpenModel'; import scorer = require('vs/base/common/scorer'); import { IModeService } from 'vs/editor/common/services/modeService'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { getIconClasses } from 'vs/workbench/browser/labels'; import { IModelService } from 'vs/editor/common/services/modelService'; import { QuickOpenHandler } from 'vs/workbench/browser/quickopen'; -import { Position } from 'vs/platform/editor/common/editor'; +import { IEditorOptions, ITextEditorOptions, Position } from 'vs/platform/editor/common/editor'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { EditorInput, asFileEditorInput, IEditorGroup, IEditorStacksModel } from 'vs/workbench/common/editor'; + export class EditorPickerEntry extends QuickOpenEntryGroup { private stacks: IEditorStacksModel; @@ -35,6 +37,7 @@ export class EditorPickerEntry extends QuickOpenEntryGroup { @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IModeService private modeService: IModeService, @IModelService private modelService: IModelService, + @IHistoryService protected historyService: IHistoryService, @IEditorGroupService editorGroupService: IEditorGroupService ) { super(); @@ -77,16 +80,27 @@ export class EditorPickerEntry extends QuickOpenEntryGroup { public run(mode: Mode, context: IEntryRunContext): boolean { if (mode === Mode.OPEN) { - return this.runOpen(context); + this.runOpen(context); + + return true; + } else if (mode === Mode.PREVIEW) { + this.runOpen(context, { forcePreview: true, pinned: false, revealIfVisible: true, preserveFocus: true }); + + return false; } return super.run(mode, context); } - private runOpen(context: IEntryRunContext): boolean { - this.editorService.openEditor(this.editor, null, this.stacks.positionOfGroup(this.group)).done(null, errors.onUnexpectedError); - - return true; + private runOpen(context: IEntryRunContext, options?: IEditorOptions | ITextEditorOptions) { + if (options.forcePreview) { + this.historyService.block(true); + } + this.editorService.openEditor(this.editor, options, this.stacks.positionOfGroup(this.group)) + .done(() => this.historyService.block(false), err => { + this.historyService.block(false); + errors.onUnexpectedError(err); + }); } } @@ -267,4 +281,4 @@ export class AllEditorsPicker extends BaseEditorPicker { return super.getAutoFocus(searchValue); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index b35417330c7f6..c87f35fdd02a8 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -30,11 +30,10 @@ import { IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor'; import { IModeService } from 'vs/editor/common/services/modeService'; import { getIconClasses } from 'vs/workbench/browser/labels'; import { IModelService } from 'vs/editor/common/services/modelService'; -import { EditorInput, getUntitledOrFileResource, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor'; +import { EditorInput, getUntitledOrFileResource } from 'vs/workbench/common/editor'; import { WorkbenchComponent } from 'vs/workbench/common/component'; import Event, { Emitter } from 'vs/base/common/event'; import { IPartService } from 'vs/workbench/services/part/common/partService'; -import { KeyMod } from 'vs/base/common/keyCodes'; import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry } from 'vs/workbench/browser/quickopen'; import errors = require('vs/base/common/errors'); import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -46,6 +45,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; const HELP_PREFIX = '?'; const QUICK_OPEN_MODE = new RawContextKey('inQuickOpen', false); @@ -94,6 +94,8 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe private previousActiveHandlerDescriptor: QuickOpenHandlerDescriptor; private actionProvider = new ContributableActionProvider(); private previousValue = ''; + private previousActiveEditorInput: IEditorInput; + private previousPreviewEditorInput: IEditorInput; private visibilityChangeTimeoutHandle: number; private closeOnFocusLost: boolean; @@ -106,7 +108,8 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe @IConfigurationService private configurationService: IConfigurationService, @IHistoryService private historyService: IHistoryService, @IInstantiationService private instantiationService: IInstantiationService, - @IPartService private partService: IPartService + @IPartService private partService: IPartService, + @IEditorGroupService private editorGroupService: IEditorGroupService ) { super(QuickOpenController.ID); @@ -267,7 +270,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe withElementById(this.partService.getWorkbenchElementId()).getHTMLElement(), { onOk: () => { /* ignore, handle later */ }, - onCancel: () => { /* ignore, handle later */ }, + onCancel: () => this.handleOnCancel(true), onType: (value: string) => { /* ignore, handle later */ }, onShow: () => this.handleOnShow(true), onHide: (reason) => this.handleOnHide(true, reason) @@ -479,6 +482,15 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe this.previousValue = prefix; + // Track active editor before navigation + const activeGroup = this.editorGroupService.getStacksModel().activeGroup; + + // Determine if there was a preview editor already open + if (activeGroup) { + this.previousActiveEditorInput = activeGroup.activeEditor; + this.previousPreviewEditorInput = activeGroup.previewEditor; + } + const promiseCompletedOnHide = new TPromise(c => { this.promisesToCompleteOnHide.push(c); }); @@ -499,7 +511,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe withElementById(this.partService.getWorkbenchElementId()).getHTMLElement(), { onOk: () => { /* ignore */ }, - onCancel: () => { /* ignore */ }, + onCancel: () => this.handleOnCancel(false), onType: (value: string) => this.onType(value || ''), onShow: () => this.handleOnShow(false), onHide: (reason) => this.handleOnHide(false, reason), @@ -549,6 +561,33 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe return promiseCompletedOnHide; } + private handleOnCancel(isPicker: boolean): void { + // restore the editor part state after cancelling + this.historyService.block(true); + + // restore the previous preview editor + if (this.previousPreviewEditorInput) { + this.editorService.openEditor(this.previousPreviewEditorInput, { preserveFocus: true }); + } + // otherwise close the preview editor that was created with eager preview + else { + const activeGroup = this.editorGroupService.getStacksModel().activeGroup; + const groupPosition = this.editorGroupService.getStacksModel().positionOfGroup(activeGroup); + if (activeGroup && activeGroup.previewEditor) { + this.editorService.closeEditor(groupPosition, activeGroup.previewEditor); + } + } + + // restore the prevously active tab + this.editorService.openEditor(this.previousActiveEditorInput).done( + () => this.historyService.block(false), + err => { + this.historyService.block(false); + errors.onUnexpectedError(err); + } + ); + } + private handleOnShow(isPicker: boolean): void { if (isPicker && this.quickOpenWidget) { this.quickOpenWidget.hide(HideReason.FOCUS_LOST); @@ -1048,9 +1087,10 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { @IModelService private modelService: IModelService, @ITextFileService private textFileService: ITextFileService, @IWorkspaceContextService contextService: IWorkspaceContextService, + @IHistoryService private historyService: IHistoryService, @IConfigurationService private configurationService: IConfigurationService ) { - super(editorService); + super(editorService, historyService, configurationService); this.input = input; @@ -1103,19 +1143,6 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { } public run(mode: Mode, context: IEntryRunContext): boolean { - if (mode === Mode.OPEN) { - const sideBySide = !context.quickNavigateConfiguration && context.keymods.indexOf(KeyMod.CtrlCmd) >= 0; - const pinned = !this.configurationService.getConfiguration().workbench.editor.enablePreviewFromQuickOpen; - - if (this.input instanceof EditorInput) { - this.editorService.openEditor(this.input, { pinned }, sideBySide).done(null, errors.onUnexpectedError); - } else { - this.editorService.openEditor({ resource: (this.input as IResourceInput).resource, options: { pinned } }, sideBySide); - } - - return true; - } - return super.run(mode, context); } } @@ -1158,4 +1185,4 @@ export class RemoveFromEditorHistoryAction extends Action { } }); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/browser/quickopen.ts b/src/vs/workbench/browser/quickopen.ts index 9bc3f88cd3ed9..739b21216e316 100644 --- a/src/vs/workbench/browser/quickopen.ts +++ b/src/vs/workbench/browser/quickopen.ts @@ -17,9 +17,11 @@ import { Action } from 'vs/base/common/actions'; 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, IEditorOptions } from 'vs/platform/editor/common/editor'; +import { EditorOptions, EditorInput, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor'; +import { IEditor, IResourceInput, IEditorInput, IEditorOptions } from 'vs/platform/editor/common/editor'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService'; import { AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; @@ -231,7 +233,11 @@ export interface IEditorQuickOpenEntry { */ export class EditorQuickOpenEntry extends QuickOpenEntry implements IEditorQuickOpenEntry { - constructor(private _editorService: IWorkbenchEditorService) { + constructor( + private _editorService: IWorkbenchEditorService, + private _historyService: IHistoryService, + protected _configurationService: IConfigurationService + ) { super(); } @@ -250,35 +256,53 @@ export class EditorQuickOpenEntry extends QuickOpenEntry implements IEditorQuick public run(mode: Mode, context: IEntryRunContext): boolean { const hideWidget = (mode === Mode.OPEN); + let sideBySide; if (mode === Mode.OPEN || mode === Mode.OPEN_IN_BACKGROUND) { - let sideBySide = context.keymods.indexOf(KeyMod.CtrlCmd) >= 0; - - let openInBackgroundOptions: IEditorOptions; - if (mode === Mode.OPEN_IN_BACKGROUND) { - openInBackgroundOptions = { pinned: true, preserveFocus: true }; - } + sideBySide = !context.quickNavigateConfiguration && context.keymods.indexOf(KeyMod.CtrlCmd) >= 0; + } - let input = this.getInput(); - if (input instanceof EditorInput) { - let opts = this.getOptions(); - if (opts) { - opts = objects.mixin(opts, openInBackgroundOptions, true); - } else if (openInBackgroundOptions) { - opts = EditorOptions.create(openInBackgroundOptions); - } + let pinned; + let modeOverrideOptions: IEditorOptions; + if (mode === Mode.OPEN) { + pinned = !this._configurationService.getConfiguration().workbench.editor.enablePreviewFromQuickOpen; + } else if (mode === Mode.PREVIEW) { + pinned = false; + modeOverrideOptions = { forcePreview: true, pinned, revealIfVisible: true, preserveFocus: true }; + + this._historyService.block(true); + } else if (mode === Mode.OPEN_IN_BACKGROUND) { + pinned = true; + modeOverrideOptions = { pinned, preserveFocus: true }; + } - this.editorService.openEditor(input, opts, sideBySide).done(null, errors.onUnexpectedError); - } else { - const resourceInput = input; + let openEditorPromise: TPromise; + let input = this.getInput(); + if (input instanceof EditorInput) { + let opts = this.getOptions(); + if (opts) { + opts = objects.mixin(opts, modeOverrideOptions, true); + } else if (modeOverrideOptions) { + opts = EditorOptions.create(modeOverrideOptions); + } - if (openInBackgroundOptions) { - resourceInput.options = objects.assign(resourceInput.options || Object.create(null), openInBackgroundOptions); - } + openEditorPromise = this.editorService.openEditor(input, opts, sideBySide); + } else { + const resourceInput = input; - this.editorService.openEditor(resourceInput, sideBySide).done(null, errors.onUnexpectedError); + if (modeOverrideOptions) { + resourceInput.options = objects.assign(resourceInput.options || Object.create(null), modeOverrideOptions); } + + openEditorPromise = this.editorService.openEditor(resourceInput, sideBySide); } + openEditorPromise.done( + () => this._historyService.block(false), + err => { + this._historyService.block(false); + errors.onUnexpectedError(err); + }); + return hideWidget; } } @@ -435,4 +459,4 @@ export class QuickOpenAction extends Action { return TPromise.as(null); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 2a45200232c40..bbd22d9f9b0ca 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -440,6 +440,7 @@ export class EditorOptions implements IEditorOptions { options.forceOpen = settings.forceOpen; options.revealIfVisible = settings.revealIfVisible; options.pinned = settings.pinned; + options.forcePreview = settings.forcePreview; options.index = settings.index; options.inactive = settings.inactive; @@ -455,6 +456,7 @@ export class EditorOptions implements IEditorOptions { this.forceOpen = other.forceOpen; this.revealIfVisible = other.revealIfVisible; this.pinned = other.pinned; + this.forcePreview = other.forcePreview; this.index = other.index; this.inactive = other.inactive; } @@ -484,6 +486,13 @@ export class EditorOptions implements IEditorOptions { */ public pinned: boolean; + /** + * Editor that is being shown with an `forcePreview` will override the `enablePreview` setting + * of the workspace configuration to allow the editor to be shown as a preview editor while + * selecting in the quick open widgets. + */ + public forcePreview: boolean; + /** * The index in the document stack where to insert the editor into when opening. */ @@ -511,7 +520,7 @@ export class TextEditorOptions extends EditorOptions { public static from(input: IResourceInput): TextEditorOptions { let options: TextEditorOptions = null; if (input && input.options) { - if (input.options.selection || input.options.forceOpen || input.options.revealIfVisible || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') { + if (input.options.selection || input.options.forceOpen || input.options.revealIfVisible || input.options.preserveFocus || input.options.pinned || input.options.forcePreview || input.options.inactive || typeof input.options.index === 'number') { options = new TextEditorOptions(); } @@ -536,6 +545,10 @@ export class TextEditorOptions extends EditorOptions { options.pinned = true; } + if (input.options.forcePreview) { + options.forcePreview = true; + } + if (input.options.inactive) { options.inactive = true; } @@ -557,6 +570,7 @@ export class TextEditorOptions extends EditorOptions { options.forceOpen = settings.forceOpen; options.revealIfVisible = settings.revealIfVisible; options.pinned = settings.pinned; + options.forcePreview = settings.forcePreview; options.index = settings.index; if (settings.selection) { @@ -888,4 +902,4 @@ export interface ActiveEditorMoveArguments { export var EditorCommands = { MoveActiveEditor: 'moveActiveEditor' -}; \ No newline at end of file +}; diff --git a/src/vs/workbench/parts/quickopen/browser/gotoLineHandler.ts b/src/vs/workbench/parts/quickopen/browser/gotoLineHandler.ts index 816f39c9bfa13..5c03a0f6fc081 100644 --- a/src/vs/workbench/parts/quickopen/browser/gotoLineHandler.ts +++ b/src/vs/workbench/parts/quickopen/browser/gotoLineHandler.ts @@ -17,6 +17,9 @@ import { IEditor, IModelDecorationsChangeAccessor, OverviewRulerLane, IModelDelt import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { Position, IEditorInput, ITextEditorOptions } from 'vs/platform/editor/common/editor'; import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; export const GOTO_LINE_PREFIX = ':'; @@ -35,8 +38,8 @@ class GotoLineEntry extends EditorQuickOpenEntry { private column: number; private handler: GotoLineHandler; - constructor(line: string, editorService: IWorkbenchEditorService, handler: GotoLineHandler) { - super(editorService); + constructor(line: string, editorService: IWorkbenchEditorService, historyService: IHistoryService, configurationService: IConfigurationService, handler: GotoLineHandler) { + super(editorService, historyService, configurationService); this.parseInput(line); this.handler = handler; @@ -167,7 +170,12 @@ export class GotoLineHandler extends QuickOpenHandler { private rangeHighlightDecorationId: IEditorLineDecoration; private lastKnownEditorViewState: IEditorViewState; - constructor( @IWorkbenchEditorService private editorService: IWorkbenchEditorService) { + constructor( + @IWorkbenchEditorService private editorService: IWorkbenchEditorService, + @IInstantiationService private instantiationService: IInstantiationService, + @IHistoryService private historyService: IHistoryService, + @IConfigurationService private configurationService: IConfigurationService + ) { super(); } @@ -184,7 +192,11 @@ export class GotoLineHandler extends QuickOpenHandler { this.lastKnownEditorViewState = (editor.getControl()).saveViewState(); } - return TPromise.as(new QuickOpenModel([new GotoLineEntry(searchValue, this.editorService, this)])); + const entry = this.instantiationService.createInstance( + GotoLineEntry, searchValue, this.editorService, this.historyService, this.configurationService, this + ); + + return TPromise.as(new QuickOpenModel([entry])); } public canRun(): boolean | string { @@ -278,4 +290,4 @@ export class GotoLineHandler extends QuickOpenHandler { autoFocusFirstEntry: searchValue.trim().length > 0 }; } -} \ No newline at end of file +} diff --git a/src/vs/workbench/parts/search/browser/openFileHandler.ts b/src/vs/workbench/parts/search/browser/openFileHandler.ts index 04ca191c83a5e..a271fccce0425 100644 --- a/src/vs/workbench/parts/search/browser/openFileHandler.ts +++ b/src/vs/workbench/parts/search/browser/openFileHandler.ts @@ -30,6 +30,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IQueryOptions, ISearchService, ISearchStats, ISearchQuery } from 'vs/platform/search/common/search'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; export class FileQuickOpenModel extends QuickOpenModel { @@ -50,9 +51,10 @@ export class FileEntry extends EditorQuickOpenEntry { @IModeService private modeService: IModeService, @IModelService private modelService: IModelService, @IConfigurationService private configurationService: IConfigurationService, + @IHistoryService historyService: IHistoryService, @IWorkspaceContextService contextService: IWorkspaceContextService ) { - super(editorService); + super(editorService, historyService, configurationService); } public getLabel(): string { @@ -295,4 +297,4 @@ export class CacheState { this.previous = null; } } -} \ No newline at end of file +} diff --git a/src/vs/workbench/parts/search/browser/openSymbolHandler.ts b/src/vs/workbench/parts/search/browser/openSymbolHandler.ts index a4e009ec3bfb7..2c1a8b2a88556 100644 --- a/src/vs/workbench/parts/search/browser/openSymbolHandler.ts +++ b/src/vs/workbench/parts/search/browser/openSymbolHandler.ts @@ -18,6 +18,7 @@ import { EditorInput, IWorkbenchEditorConfiguration } from 'vs/workbench/common/ import labels = require('vs/base/common/labels'); import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -30,11 +31,12 @@ class SymbolEntry extends EditorQuickOpenEntry { constructor( private _bearing: IWorkspaceSymbol, private _provider: IWorkspaceSymbolProvider, - @IConfigurationService private _configurationService: IConfigurationService, + @IConfigurationService configurationService: IConfigurationService, @IWorkspaceContextService private _contextService: IWorkspaceContextService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService + @IWorkbenchEditorService editorService: IWorkbenchEditorService, + @IHistoryService historyService: IHistoryService ) { - super(editorService); + super(editorService, historyService, configurationService); } public getLabel(): string { @@ -208,4 +210,4 @@ export class OpenSymbolHandler extends QuickOpenHandler { autoFocusPrefixMatch: searchValue.trim() }; } -} \ No newline at end of file +} diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index 10cd09a907895..dc5323061e139 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -272,6 +272,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic private stack: IStackEntry[]; private index: number; private blockStackChanges: boolean; + private blockEditorHistoryChanges: boolean; private currentFileEditorState: EditorState; private history: (IEditorInput | IResourceInput)[]; @@ -374,6 +375,16 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic this.recentlyClosedFiles = []; } + public block(block: boolean) { + if (block) { + this.blockStackChanges = true; + this.blockEditorHistoryChanges = true; + } else { + this.blockStackChanges = false; + this.blockEditorHistoryChanges = false; + } + } + private navigate(): void { const entry = this.stack[this.index]; @@ -414,7 +425,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic const input = editor ? editor.input : void 0; // Ensure we have at least a name to show - if (!input || !input.getName()) { + if (this.blockEditorHistoryChanges || !input || !input.getName()) { return; } @@ -700,4 +711,4 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic return void 0; }).filter(input => !!input); } -} \ No newline at end of file +} diff --git a/src/vs/workbench/services/history/common/history.ts b/src/vs/workbench/services/history/common/history.ts index d76384abd5c99..1f91345845144 100644 --- a/src/vs/workbench/services/history/common/history.ts +++ b/src/vs/workbench/services/history/common/history.ts @@ -47,4 +47,9 @@ export interface IHistoryService { * Get the entire history of opened editors. */ getHistory(): (IEditorInput | IResourceInput)[]; -} \ No newline at end of file + + /** + * Blocks writing to stack and editor history. + */ + block(block: boolean): void; +}