未验证 提交 d87e3c37 编写于 作者: A Alex Dima

Save text buffers before renaming to avoid unexpected undo/redo stack elements (#107739)

Co-authored-by: NJohannes Rieken <johannes.rieken@gmail.com>
上级 091c17a0
......@@ -277,13 +277,6 @@ class ResourceEditStack {
}
}
this._future = [];
if (this._past.length > 0) {
const lastElement = this._past[this._past.length - 1];
if (lastElement.type === UndoRedoElementType.Resource && !lastElement.isValid) {
// clear undo stack
this._past = [];
}
}
this._past.push(element);
this.versionId++;
}
......
......@@ -16,6 +16,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { VSBuffer } from 'vs/base/common/buffer';
import { ResourceFileEdit } from 'vs/editor/browser/services/bulkEditService';
import * as resources from 'vs/base/common/resources';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
interface IFileOperation {
uris: URI[];
......@@ -38,6 +39,7 @@ class RenameOperation implements IFileOperation {
readonly options: WorkspaceFileEditOptions,
@IWorkingCopyFileService private readonly _workingCopyFileService: IWorkingCopyFileService,
@IFileService private readonly _fileService: IFileService,
@ITextFileService private readonly _textFileService: ITextFileService,
) { }
get uris() {
......@@ -49,8 +51,18 @@ class RenameOperation implements IFileOperation {
if (this.options.overwrite === undefined && this.options.ignoreIfExists && await this._fileService.exists(this.newUri)) {
return new Noop(); // not overwriting, but ignoring, and the target file exists
}
// See https://github.com/microsoft/vscode/issues/107739
// `IWorkingCopyFileService.move` ends up pushing to the undo/redo service
// if we attempt to move a dirty file.
try {
await this._textFileService.save(this.oldUri, {
skipSaveParticipants: true
});
} catch (err) { }
await this._workingCopyFileService.move([{ source: this.oldUri, target: this.newUri }], { overwrite: this.options.overwrite });
return new RenameOperation(this.oldUri, this.newUri, this.options, this._workingCopyFileService, this._fileService);
return new RenameOperation(this.oldUri, this.newUri, this.options, this._workingCopyFileService, this._fileService, this._textFileService);
}
toString(): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册