提交 9418ba5f 编写于 作者: A Alex Dima

Don't forget to push undo stops when executing edits (#36234)

上级 573586d8
......@@ -323,7 +323,9 @@ export class ReindentLinesAction extends EditorAction {
}
let edits = getReindentEditOperations(model, 1, model.getLineCount());
if (edits) {
editor.pushUndoStop();
editor.executeEdits(this.id, edits);
editor.pushUndoStop();
}
}
}
......
......@@ -407,7 +407,9 @@ export abstract class AbstractDeleteAllToBoundaryAction extends EditorAction {
return EditOperation.replace(range, '');
});
editor.pushUndoStop();
editor.executeEdits(this.id, edits, endCursorState);
editor.pushUndoStop();
}
/**
......@@ -673,8 +675,9 @@ export class JoinLinesAction extends EditorAction {
}
endCursorState.unshift(endPrimaryCursor);
editor.pushUndoStop();
editor.executeEdits(this.id, edits, endCursorState);
editor.pushUndoStop();
}
}
......
......@@ -73,6 +73,32 @@ suite('Editor Contrib - Line Operations', () => {
assert.equal(model.getLineContent(5), 'horlworld', '005');
});
});
test('issue #36234: should push undo stop', () => {
withMockCodeEditor(
[
'one',
'two',
'three'
], {}, (editor, cursor) => {
let model = editor.getModel();
let deleteAllLeftAction = new DeleteAllLeftAction();
editor.setSelection(new Selection(1, 1, 1, 1));
editor.trigger('keyboard', Handler.Type, { text: 'Typing some text here on line ' });
assert.equal(model.getLineContent(1), 'Typing some text here on line one');
assert.deepEqual(editor.getSelection(), new Selection(1, 31, 1, 31));
deleteAllLeftAction.run(null, editor);
assert.equal(model.getLineContent(1), 'one');
assert.deepEqual(editor.getSelection(), new Selection(1, 1, 1, 1));
editor.trigger('keyboard', Handler.Undo, {});
assert.equal(model.getLineContent(1), 'Typing some text here on line one');
assert.deepEqual(editor.getSelection(), new Selection(1, 31, 1, 31));
});
});
});
suite('JoinLinesAction', () => {
......@@ -164,6 +190,31 @@ suite('Editor Contrib - Line Operations', () => {
assert.deepEqual(editor.getSelection().toString(), new Selection(3, 4, 3, 8).toString(), '003');
});
});
test('should push undo stop', function () {
withMockCodeEditor(
[
'hello',
'world'
], {}, (editor, cursor) => {
let model = editor.getModel();
let joinLinesAction = new JoinLinesAction();
editor.setSelection(new Selection(1, 6, 1, 6));
editor.trigger('keyboard', Handler.Type, { text: ' my dear' });
assert.equal(model.getLineContent(1), 'hello my dear');
assert.deepEqual(editor.getSelection(), new Selection(1, 14, 1, 14));
joinLinesAction.run(null, editor);
assert.equal(model.getLineContent(1), 'hello my dear world');
assert.deepEqual(editor.getSelection(), new Selection(1, 14, 1, 14));
editor.trigger('keyboard', Handler.Undo, {});
assert.equal(model.getLineContent(1), 'hello my dear');
assert.deepEqual(editor.getSelection(), new Selection(1, 14, 1, 14));
});
});
});
test('transpose', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册