diff --git a/src/vs/platform/undoRedo/common/undoRedoService.ts b/src/vs/platform/undoRedo/common/undoRedoService.ts index 3e1c5d111980bfc841f6ce7b4d9249c65bcdafb8..76ed91065c6e707450a3d15b8eee13d533db4058 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 714f689d01da6aa74a42ca700a26f845df73dbf5..4c0a48e58759072fad488d862bb436a1c7463948 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); }); });