From 449f03a626aa05f4595bbb1840e97667dcbb9fcf Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 20 Oct 2017 16:08:09 +0200 Subject: [PATCH] Saving file after it has been deleted from disk saves empty file. (fixes #36573) --- .../services/textfile/common/textFileEditorModel.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 6c3cd249763..35e832cb076 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -690,10 +690,15 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil // mark the save participant as current pending save operation return this.saveSequentializer.setPending(versionId, saveParticipantPromise.then(newVersionId => { - // the model was not dirty and no save participant changed the contents, so we do not have - // to write the contents to disk, as they are already on disk. we still want to trigger - // a change on the file though so that external file watchers can be notified - if (options.force && !this.dirty && options.reason === SaveReason.EXPLICIT && versionId === newVersionId) { + // Under certain conditions a save to the model will not cause the contents to the flushed on + // disk because we can assume that the contents are already on disk. Instead, we just touch the + // file to still trigger external file watchers for example. + // The conditions are all of: + // - a forced, explicit save (Ctrl+S) + // - the model is not dirty (otherwise we know there are changed which needs to go to the file) + // - the model is not in orphan mode (because in that case we know the file does not exist on disk) + // - the model version did not change due to save participants running + if (options.force && !this.dirty && !this.inOrphanMode && options.reason === SaveReason.EXPLICIT && versionId === newVersionId) { return this.doTouch(); } -- GitLab