From 413bcb9fe15a977ad9056af3bb41c1ffd4271268 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 25 Feb 2016 20:17:31 +0100 Subject: [PATCH] Fixes #3071 --- .../editor/common/model/editableTextModel.ts | 4 +- .../test/common/controller/cursor.test.ts | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/common/model/editableTextModel.ts b/src/vs/editor/common/model/editableTextModel.ts index e5a4f7182e9..888d082855d 100644 --- a/src/vs/editor/common/model/editableTextModel.ts +++ b/src/vs/editor/common/model/editableTextModel.ts @@ -85,7 +85,9 @@ export class EditableTextModel extends TextModelWithDecorations implements edito throw new Error('EditableTextModel.pushEditOperations: Model is disposed'); } - return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer); + return this.deferredEmit(() => { + return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer); + }); } /** diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index 6f7ceb7370e..2ed9145ec6a 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -1089,6 +1089,48 @@ suite('Editor Controller - Regression tests', () => { }); }); + test('issue #3071: Investigate why undo stack gets corrupted', () => { + usingCursor({ + text: [ + 'some lines', + 'and more lines', + 'just some text', + ], + mode: null, + config: null + }, (model, cursor) => { + moveTo(cursor, 1, 1, false); + moveTo(cursor, 3, 4, true); + + let isFirst = true; + model.addListener2(EventType.ModelContentChanged, (e) => { + if (isFirst) { + isFirst = false; + cursorCommand(cursor, H.Type, { text: '\t' }, null, 'keyboard'); + } + }); + + cursorCommand(cursor, H.Tab); + assert.equal(model.getValue(), [ + '\t just some text' + ].join('\n'), '001'); + + cursorCommand(cursor, H.Undo); + assert.equal(model.getValue(), [ + 'some lines', + 'and more lines', + 'just some text', + ].join('\n'), '002'); + + cursorCommand(cursor, H.Undo); + assert.equal(model.getValue(), [ + 'some lines', + 'and more lines', + 'just some text', + ].join('\n'), '003'); + }); + }); + test('issue #832: deleteWordLeft', () => { usingCursor({ text: [ -- GitLab