提交 2b1bbfa6 编写于 作者: B Benjamin Pasero

Hot exit: untitled backup is not made when opening new untitled with initial content (fix #86891)

上级 44cf9c91
...@@ -37,6 +37,7 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu ...@@ -37,6 +37,7 @@ export class BackupModelTracker extends Disposable implements IWorkbenchContribu
this._register(this.textFileService.models.onModelDisposed(e => this.discardBackup(e))); this._register(this.textFileService.models.onModelDisposed(e => this.discardBackup(e)));
// Listen for untitled model changes // Listen for untitled model changes
this._register(this.untitledTextEditorService.onDidCreate(e => this.onUntitledModelChanged(e)));
this._register(this.untitledTextEditorService.onDidChangeContent(e => this.onUntitledModelChanged(e))); this._register(this.untitledTextEditorService.onDidChangeContent(e => this.onUntitledModelChanged(e)));
this._register(this.untitledTextEditorService.onDidDisposeModel(e => this.discardBackup(e))); this._register(this.untitledTextEditorService.onDidDisposeModel(e => this.discardBackup(e)));
......
...@@ -31,6 +31,11 @@ export interface IUntitledTextEditorService { ...@@ -31,6 +31,11 @@ export interface IUntitledTextEditorService {
_serviceBrand: undefined; _serviceBrand: undefined;
/**
* Events for when untitled text editors are created.
*/
readonly onDidCreate: Event<URI>;
/** /**
* Events for when untitled text editors content changes (e.g. any keystroke). * Events for when untitled text editors content changes (e.g. any keystroke).
*/ */
...@@ -117,6 +122,9 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe ...@@ -117,6 +122,9 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
private mapResourceToInput = new ResourceMap<UntitledTextEditorInput>(); private mapResourceToInput = new ResourceMap<UntitledTextEditorInput>();
private mapResourceToAssociatedFilePath = new ResourceMap<boolean>(); private mapResourceToAssociatedFilePath = new ResourceMap<boolean>();
private readonly _onDidCreate = this._register(new Emitter<URI>());
readonly onDidCreate = this._onDidCreate.event;
private readonly _onDidChangeContent = this._register(new Emitter<URI>()); private readonly _onDidChangeContent = this._register(new Emitter<URI>());
readonly onDidChangeContent = this._onDidChangeContent.event; readonly onDidChangeContent = this._onDidChangeContent.event;
...@@ -263,6 +271,9 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe ...@@ -263,6 +271,9 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
// Add to cache // Add to cache
this.mapResourceToInput.set(untitledResource, input); this.mapResourceToInput.set(untitledResource, input);
// Signal new untitled as event
this._onDidCreate.fire(untitledResource);
return input; return input;
} }
......
...@@ -54,11 +54,20 @@ suite('Workbench untitled text editors', () => { ...@@ -54,11 +54,20 @@ suite('Workbench untitled text editors', () => {
assert.equal(service.getAll().length, 0); assert.equal(service.getAll().length, 0);
let createdResources: URI[] = [];
const createListener = service.onDidCreate(resource => {
createdResources.push(resource);
});
const input1 = service.createOrGet(); const input1 = service.createOrGet();
assert.equal(input1, service.createOrGet(input1.getResource())); assert.equal(input1, service.createOrGet(input1.getResource()));
assert.ok(service.exists(input1.getResource())); assert.ok(service.exists(input1.getResource()));
assert.ok(!service.exists(URI.file('testing'))); assert.ok(!service.exists(URI.file('testing')));
assert.equal(createdResources.length, 1);
assert.equal(createdResources[0].toString(), input1.getResource());
createListener.dispose();
const input2 = service.createOrGet(); const input2 = service.createOrGet();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册