提交 32dfe5dd 编写于 作者: B Benjamin Pasero

fix #66338

上级 abd57bb0
......@@ -859,6 +859,10 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
// Updated resolved stat with updated stat since touching it might have changed mtime
this.updateLastResolvedDiskStat(stat);
// Emit File Saved Event
this._onDidStateChange.fire(StateChange.SAVED);
}, error => onUnexpectedError(error) /* just log any error but do not notify the user since the file was not dirty */));
}
......
......@@ -246,37 +246,36 @@ export abstract class TextFileService extends Disposable implements ITextFileSer
.map(async untitled => (await this.untitledEditorService.loadOrCreate({ resource: untitled })).backup()));
}
private confirmBeforeShutdown(): boolean | Promise<boolean> {
return this.confirmSave().then(confirm => {
// Save
if (confirm === ConfirmResult.SAVE) {
return this.saveAll(true /* includeUntitled */, { skipSaveParticipants: true }).then(result => {
if (result.results.some(r => !r.success)) {
return true; // veto if some saves failed
}
private async confirmBeforeShutdown(): Promise<boolean> {
const confirm = await this.confirmSave();
return this.noVeto({ cleanUpBackups: true });
});
// Save
if (confirm === ConfirmResult.SAVE) {
const result = await this.saveAll(true /* includeUntitled */, { skipSaveParticipants: true });
if (result.results.some(r => !r.success)) {
return true; // veto if some saves failed
}
// Don't Save
else if (confirm === ConfirmResult.DONT_SAVE) {
return this.noVeto({ cleanUpBackups: true });
}
// Make sure to revert untitled so that they do not restore
// see https://github.com/Microsoft/vscode/issues/29572
this.untitledEditorService.revertAll();
// Don't Save
else if (confirm === ConfirmResult.DONT_SAVE) {
return this.noVeto({ cleanUpBackups: true });
}
// Make sure to revert untitled so that they do not restore
// see https://github.com/Microsoft/vscode/issues/29572
this.untitledEditorService.revertAll();
// Cancel
else if (confirm === ConfirmResult.CANCEL) {
return true; // veto
}
return this.noVeto({ cleanUpBackups: true });
}
return false;
});
// Cancel
else if (confirm === ConfirmResult.CANCEL) {
return true; // veto
}
return false;
}
private noVeto(options: { cleanUpBackups: boolean }): boolean | Promise<boolean> {
......
......@@ -17,7 +17,7 @@ import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiatio
export class TextResourcePropertiesService implements ITextResourcePropertiesService {
_serviceBrand: ServiceIdentifier<any>;
_serviceBrand: ServiceIdentifier<ITextResourcePropertiesService>;
private remoteEnvironment: IRemoteAgentEnvironment | null = null;
......
......@@ -44,7 +44,7 @@ suite('Files - TextFileEditorModel', () => {
accessor.fileService.setContent(content);
});
test('Save', async function () {
test('save', async function () {
const model: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/index_async.txt'), 'utf8');
await model.load();
......@@ -52,10 +52,38 @@ suite('Files - TextFileEditorModel', () => {
model.textEditorModel!.setValue('bar');
assert.ok(getLastModifiedTime(model) <= Date.now());
let savedEvent = false;
model.onDidStateChange(e => {
if (e === StateChange.SAVED) {
savedEvent = true;
}
});
await model.save();
assert.ok(model.getLastSaveAttemptTime() <= Date.now());
assert.ok(!model.isDirty());
assert.ok(savedEvent);
model.dispose();
assert.ok(!accessor.modelService.getModel(model.getResource()));
});
test('save - touching also emits saved event', async function () {
const model: TextFileEditorModel = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/index_async.txt'), 'utf8');
await model.load();
let savedEvent = false;
model.onDidStateChange(e => {
if (e === StateChange.SAVED) {
savedEvent = true;
}
});
await model.save({ force: true });
assert.ok(savedEvent);
model.dispose();
assert.ok(!accessor.modelService.getModel(model.getResource()));
......
......@@ -65,7 +65,7 @@ suite('Files - TextFileService', () => {
accessor.untitledEditorService.revertAll();
});
test('confirm onWillShutdown - no veto', function () {
test('confirm onWillShutdown - no veto', async function () {
model = instantiationService.createInstance(TextFileEditorModel, toResource.call(this, '/path/file.txt'), 'utf8');
(<TextFileEditorModelManager>accessor.textFileService.models).add(model.getResource(), model);
......@@ -76,9 +76,7 @@ suite('Files - TextFileService', () => {
if (typeof veto === 'boolean') {
assert.ok(!veto);
} else {
veto.then(veto => {
assert.ok(!veto);
});
assert.ok(!(await veto));
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册