提交 83d8cbea 编写于 作者: B Benjamin Pasero

Revisit file filter usage in quick open (fixes #34958)

上级 e34982ae
...@@ -54,7 +54,7 @@ import { attachQuickOpenStyler } from 'vs/platform/theme/common/styler'; ...@@ -54,7 +54,7 @@ import { attachQuickOpenStyler } from 'vs/platform/theme/common/styler';
import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ITree, IActionProvider } from 'vs/base/parts/tree/browser/tree'; import { ITree, IActionProvider } from 'vs/base/parts/tree/browser/tree';
import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { FileKind } from 'vs/platform/files/common/files'; import { FileKind, IFileService } from 'vs/platform/files/common/files';
const HELP_PREFIX = '?'; const HELP_PREFIX = '?';
...@@ -1168,7 +1168,8 @@ class EditorHistoryHandler { ...@@ -1168,7 +1168,8 @@ class EditorHistoryHandler {
constructor( constructor(
@IHistoryService private historyService: IHistoryService, @IHistoryService private historyService: IHistoryService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService @IWorkspaceContextService private contextService: IWorkspaceContextService,
@IFileService private fileService: IFileService
) { ) {
} }
...@@ -1189,7 +1190,7 @@ class EditorHistoryHandler { ...@@ -1189,7 +1190,7 @@ class EditorHistoryHandler {
history.forEach(input => { history.forEach(input => {
let resource: URI; let resource: URI;
if (input instanceof EditorInput) { if (input instanceof EditorInput) {
resource = toResource(input, { filter: ['file', 'untitled'] }); resource = resourceForEditorHistory(input, this.fileService);
} else { } else {
resource = (input as IResourceInput).resource; resource = (input as IResourceInput).resource;
} }
...@@ -1245,14 +1246,15 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { ...@@ -1245,14 +1246,15 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
@ITextFileService private textFileService: ITextFileService, @ITextFileService private textFileService: ITextFileService,
@IWorkspaceContextService contextService: IWorkspaceContextService, @IWorkspaceContextService contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService, @IConfigurationService private configurationService: IConfigurationService,
@IEnvironmentService environmentService: IEnvironmentService @IEnvironmentService environmentService: IEnvironmentService,
@IFileService private fileService: IFileService
) { ) {
super(editorService); super(editorService);
this.input = input; this.input = input;
if (input instanceof EditorInput) { if (input instanceof EditorInput) {
this.resource = toResource(input, { filter: ['file', 'untitled'] }); this.resource = resourceForEditorHistory(input, fileService);
this.label = input.getName(); this.label = input.getName();
this.description = input.getDescription(); this.description = input.getDescription();
this.dirty = input.isDirty(); this.dirty = input.isDirty();
...@@ -1317,6 +1319,18 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { ...@@ -1317,6 +1319,18 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
} }
} }
function resourceForEditorHistory(input: EditorInput, fileService: IFileService): URI {
const resource = toResource(input);
// For the editor history we only prefer resources that are either untitled or
// can be handled by the file service which indicates they are editable resources.
if (resource && (fileService.canHandleResource(resource) || resource.scheme === 'untitled')) {
return resource;
}
return void 0;
}
export class RemoveFromEditorHistoryAction extends Action { export class RemoveFromEditorHistoryAction extends Action {
public static ID = 'workbench.action.removeFromEditorHistory'; public static ID = 'workbench.action.removeFromEditorHistory';
......
...@@ -245,12 +245,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -245,12 +245,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// Track closing of pinned editor to support to reopen closed editors // Track closing of pinned editor to support to reopen closed editors
if (event.pinned) { if (event.pinned) {
const file = toResource(event.editor, { filter: 'file' }); // we only support files to reopen const resource = toResource(event.editor);
if (file) { const supportsReopen = resource && this.fileService.canHandleResource(resource); // we only support file'ish things to reopen
if (supportsReopen) {
// Remove all inputs matching and add as last recently closed // Remove all inputs matching and add as last recently closed
this.removeFromRecentlyClosedFiles(event.editor); this.removeFromRecentlyClosedFiles(event.editor);
this.recentlyClosedFiles.push({ resource: file, index: event.index }); this.recentlyClosedFiles.push({ resource, index: event.index });
// Bounding // Bounding
if (this.recentlyClosedFiles.length > HistoryService.MAX_RECENTLY_CLOSED_EDITORS) { if (this.recentlyClosedFiles.length > HistoryService.MAX_RECENTLY_CLOSED_EDITORS) {
...@@ -591,9 +592,10 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -591,9 +592,10 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
} }
private preferResourceInput(input: IEditorInput): IEditorInput | IResourceInput { private preferResourceInput(input: IEditorInput): IEditorInput | IResourceInput {
const file = toResource(input, { filter: 'file' }); const resource = toResource(input);
if (file) { const preferResourceInput = resource && this.fileService.canHandleResource(resource); // file'ish things prefer resources
return { resource: file }; if (preferResourceInput) {
return { resource };
} }
return input; return input;
...@@ -678,9 +680,9 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -678,9 +680,9 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
} }
if (arg2 instanceof EditorInput) { if (arg2 instanceof EditorInput) {
const file = toResource(arg2, { filter: 'file' }); const resource = toResource(arg2);
return file && file.toString() === resource.toString(); return resource && this.fileService.canHandleResource(resource) && resource.toString() === resource.toString();
} }
const resourceInput = arg2 as IResourceInput; const resourceInput = arg2 as IResourceInput;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册