From 6891688dfcf28d45519bfac271134660b870986d Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 23 Sep 2020 12:38:17 +0200 Subject: [PATCH] Be sure to execute grouped undo / redo elements in order (#101789) --- .../undoRedo/common/undoRedoService.ts | 44 +++++++++++++++++-- .../test/common/undoRedoService.test.ts | 4 +- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/undoRedo/common/undoRedoService.ts b/src/vs/platform/undoRedo/common/undoRedoService.ts index 3e1c5d11198..76ed91065c6 100644 --- a/src/vs/platform/undoRedo/common/undoRedoService.ts +++ b/src/vs/platform/undoRedo/common/undoRedoService.ts @@ -985,9 +985,9 @@ export class UndoRedoService implements IUndoRedoService { }); } - private _continueUndoInGroup(groupId: number): Promise | void { + private _findClosestUndoElementInGroup(groupId: number): [StackElement | null, string | null] { if (!groupId) { - return; + return [null, null]; } // find another element with the same groupId and with the highest groupOrder ready to be undone @@ -1007,6 +1007,15 @@ export class UndoRedoService implements IUndoRedoService { } } + return [matchedElement, matchedStrResource]; + } + + private _continueUndoInGroup(groupId: number): Promise | void { + if (!groupId) { + return; + } + + const [, matchedStrResource] = this._findClosestUndoElementInGroup(groupId); if (matchedStrResource) { return this.undo(matchedStrResource); } @@ -1024,6 +1033,15 @@ export class UndoRedoService implements IUndoRedoService { return; } + if (element.groupId) { + // this element is a part of a group, we need to make sure undoing in a group is in order + const [matchedElement, matchedStrResource] = this._findClosestUndoElementInGroup(element.groupId); + if (element !== matchedElement && matchedStrResource) { + // there is an element in the same group that should be undone before this one + return this.undo(matchedStrResource); + } + } + try { if (element.type === UndoRedoElementType.Workspace) { return this._workspaceUndo(strResource, element); @@ -1190,9 +1208,9 @@ export class UndoRedoService implements IUndoRedoService { }); } - private _continueRedoInGroup(groupId: number): Promise | void { + private _findClosestRedoElementInGroup(groupId: number): [StackElement | null, string | null] { if (!groupId) { - return; + return [null, null]; } // find another element with the same groupId and with the lowest groupOrder ready to be redone @@ -1212,6 +1230,15 @@ export class UndoRedoService implements IUndoRedoService { } } + return [matchedElement, matchedStrResource]; + } + + private _continueRedoInGroup(groupId: number): Promise | void { + if (!groupId) { + return; + } + + const [, matchedStrResource] = this._findClosestRedoElementInGroup(groupId); if (matchedStrResource) { return this.redo(matchedStrResource); } @@ -1229,6 +1256,15 @@ export class UndoRedoService implements IUndoRedoService { return; } + if (element.groupId) { + // this element is a part of a group, we need to make sure redoing in a group is in order + const [matchedElement, matchedStrResource] = this._findClosestRedoElementInGroup(element.groupId); + if (element !== matchedElement && matchedStrResource) { + // there is an element in the same group that should be redone before this one + return this.redo(matchedStrResource); + } + } + try { if (element.type === UndoRedoElementType.Workspace) { return this._workspaceRedo(strResource, element); diff --git a/src/vs/platform/undoRedo/test/common/undoRedoService.test.ts b/src/vs/platform/undoRedo/test/common/undoRedoService.test.ts index 714f689d01d..4c0a48e5875 100644 --- a/src/vs/platform/undoRedo/test/common/undoRedoService.test.ts +++ b/src/vs/platform/undoRedo/test/common/undoRedoService.test.ts @@ -210,7 +210,9 @@ suite('UndoRedoService', () => { }); test('UndoRedoGroup.None uses id 0', () => { - assert.equal(UndoRedoGroup.None, 0); + assert.equal(UndoRedoGroup.None.id, 0); + assert.equal(UndoRedoGroup.None.nextOrder(), 0); + assert.equal(UndoRedoGroup.None.nextOrder(), 0); }); }); -- GitLab