mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Ensure previously active file is opened when restoring
This commit is contained in:
parent
3b7e8e63b3
commit
f415979153
|
@ -18,7 +18,7 @@ import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/unti
|
|||
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
|
||||
import {IPartService} from 'vs/workbench/services/part/common/partService';
|
||||
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
|
||||
import {asFileEditorInput} from 'vs/workbench/common/editor';
|
||||
import {asFileEditorInput, getUntitledOrFileResource} from 'vs/workbench/common/editor';
|
||||
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
|
||||
import {IEventService} from 'vs/platform/event/common/event';
|
||||
|
||||
|
@ -279,7 +279,7 @@ export class WorkingFilesModel implements IWorkingFilesModel {
|
|||
let index = this.indexOf(resource);
|
||||
if (index >= 0) {
|
||||
if (resource.scheme === 'file') {
|
||||
this.recentlyClosedEntries.push([this.mapEntryToResource[resource.toString()]]);
|
||||
this.recordRecentlyClosedEntries([this.mapEntryToResource[resource.toString()]]);
|
||||
}
|
||||
|
||||
// Remove entry
|
||||
|
@ -331,7 +331,7 @@ export class WorkingFilesModel implements IWorkingFilesModel {
|
|||
}
|
||||
|
||||
public clear(): void {
|
||||
this.recentlyClosedEntries.push(this.entries);
|
||||
this.recordRecentlyClosedEntries(this.entries);
|
||||
let deleted = this.entries;
|
||||
this.entries = [];
|
||||
this.mapEntryToResource = Object.create(null);
|
||||
|
@ -346,6 +346,27 @@ export class WorkingFilesModel implements IWorkingFilesModel {
|
|||
return this.mapEntryToResource[resource.toString()];
|
||||
}
|
||||
|
||||
private recordRecentlyClosedEntries(resources: WorkingFileEntry[]): void {
|
||||
if (resources.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the active entry the first entry
|
||||
let recentlyClosedEntry: WorkingFileEntry[] = [];
|
||||
let input = this.editorService.getActiveEditorInput();
|
||||
let resource: uri = getUntitledOrFileResource(input);
|
||||
let activeEntry: WorkingFileEntry;
|
||||
if (resource) {
|
||||
activeEntry = this.findEntry(resource);
|
||||
if (activeEntry) {
|
||||
recentlyClosedEntry.push(activeEntry);
|
||||
}
|
||||
}
|
||||
this.recentlyClosedEntries.push(recentlyClosedEntry.concat(resources.filter(e => {
|
||||
return !activeEntry || e.resource.path !== activeEntry.resource.path;
|
||||
})));
|
||||
}
|
||||
|
||||
private indexOf(resource: uri): number {
|
||||
let entry = this.findEntry(resource);
|
||||
if (entry) {
|
||||
|
|
|
@ -7,20 +7,29 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import paths = require('vs/base/common/paths');
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService';
|
||||
import {TestFileService, TestLifecycleService, TestPartService, TestEditorService, TestConfigurationService, TestUntitledEditorService, TestStorageService, TestTelemetryService, TestContextService, TestMessageService, TestEventService} from 'vs/workbench/test/browser/servicesTestUtils';
|
||||
import {WorkingFileEntry, WorkingFilesModel} from 'vs/workbench/parts/files/common/workingFilesModel';
|
||||
import {TextFileService} from 'vs/workbench/parts/files/browser/textFileServices';
|
||||
import {createMockModelService, createMockModeService} from 'vs/editor/test/common/servicesTestUtils';
|
||||
import {EditorInput} from 'vs/workbench/common/editor';
|
||||
import {FileEditorInput} from 'vs/workbench/parts/files/browser/editors/fileEditorInput';
|
||||
|
||||
function toResource(path) {
|
||||
return URI.file(paths.join('C:\\', path));
|
||||
}
|
||||
|
||||
let baseInstantiationService: IInstantiationService;
|
||||
let editorService: TestEditorService;
|
||||
let eventService: TestEventService;
|
||||
let textFileService: TextFileService;
|
||||
|
||||
suite('Files - WorkingFilesModel', () => {
|
||||
|
||||
setup(() => {
|
||||
editorService = new TestEditorService();
|
||||
eventService = new TestEventService();
|
||||
|
||||
baseInstantiationService = createInstantiationService({
|
||||
|
@ -31,7 +40,7 @@ suite('Files - WorkingFilesModel', () => {
|
|||
telemetryService: new TestTelemetryService(),
|
||||
storageService: new TestStorageService(),
|
||||
untitledEditorService: new TestUntitledEditorService(),
|
||||
editorService: new TestEditorService(),
|
||||
editorService: editorService,
|
||||
partService: new TestPartService(),
|
||||
modeService: createMockModeService(),
|
||||
modelService: createMockModelService(),
|
||||
|
@ -103,4 +112,30 @@ suite('Files - WorkingFilesModel', () => {
|
|||
|
||||
assert.equal(model.popLastClosedEntry(), null);
|
||||
});
|
||||
|
||||
test("Reopening multiple files will open the editor in the previously opened file", function() {
|
||||
let model = baseInstantiationService.createInstance(WorkingFilesModel);
|
||||
|
||||
// Open /foo then /bar, set /foo as active input
|
||||
let fooEntry = model.addEntry(URI.create('file', null, '/foo'));
|
||||
editorService.getActiveEditorInput = () => {
|
||||
return baseInstantiationService.createInstance(FileEditorInput, fooEntry.resource, 'text/javascript', void 0);
|
||||
};
|
||||
model.addEntry(URI.create('file', null, '/bar'));
|
||||
model.clear();
|
||||
|
||||
let lastClosedEntry: WorkingFileEntry[] = model.popLastClosedEntry();
|
||||
assert.equal(lastClosedEntry[0].resource.path, '/foo');
|
||||
|
||||
// Open /bar then /foo, set /foo as active input
|
||||
model.addEntry(URI.create('file', null, '/bar'));
|
||||
fooEntry = model.addEntry(URI.create('file', null, '/foo'));
|
||||
editorService.getActiveEditorInput = () => {
|
||||
return baseInstantiationService.createInstance(FileEditorInput, fooEntry.resource, 'text/javascript', void 0);
|
||||
};
|
||||
model.clear();
|
||||
|
||||
lastClosedEntry = model.popLastClosedEntry();
|
||||
assert.equal(lastClosedEntry[0].resource.path, '/foo');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue