Skip to content

Commit 186354f

Browse files
committed
Fixes microsoft#51275: push stack element before move word commands
1 parent 7169e43 commit 186354f

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/vs/editor/contrib/wordOperations/test/wordOperations.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Selection } from 'vs/editor/common/core/selection';
1111
import { deserializePipePositions, serializePipePositions, testRepeatedActionAndExtractPositions } from 'vs/editor/contrib/wordOperations/test/wordTestUtils';
1212
import { CursorWordEndLeft, CursorWordEndLeftSelect, CursorWordEndRight, CursorWordEndRightSelect, CursorWordLeft, CursorWordLeftSelect, CursorWordRight, CursorWordRightSelect, CursorWordStartLeft, CursorWordStartLeftSelect, CursorWordStartRight, CursorWordStartRightSelect, DeleteWordEndLeft, DeleteWordEndRight, DeleteWordLeft, DeleteWordRight, DeleteWordStartLeft, DeleteWordStartRight, CursorWordAccessibilityLeft, CursorWordAccessibilityLeftSelect, CursorWordAccessibilityRight, CursorWordAccessibilityRightSelect } from 'vs/editor/contrib/wordOperations/wordOperations';
1313
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
14+
import { Handler } from 'vs/editor/common/editorCommon';
15+
import { Cursor } from 'vs/editor/common/controller/cursor';
1416

1517
suite('WordOperations', () => {
1618

@@ -193,6 +195,32 @@ suite('WordOperations', () => {
193195
assert.deepEqual(actual, EXPECTED);
194196
});
195197

198+
test('issue #51275 - cursorWordStartLeft does not push undo/redo stack element', () => {
199+
function cursorCommand(cursor: Cursor, command: string, extraData?: any, overwriteSource?: string) {
200+
cursor.trigger(overwriteSource || 'tests', command, extraData);
201+
}
202+
203+
function type(cursor: Cursor, text: string) {
204+
for (let i = 0; i < text.length; i++) {
205+
cursorCommand(cursor, Handler.Type, { text: text.charAt(i) }, 'keyboard');
206+
}
207+
}
208+
209+
withTestCodeEditor('', {}, (editor, cursor) => {
210+
type(cursor, 'foo bar baz');
211+
assert.equal(editor.getValue(), 'foo bar baz');
212+
213+
cursorWordStartLeft(editor);
214+
cursorWordStartLeft(editor);
215+
type(cursor, 'q');
216+
217+
assert.equal(editor.getValue(), 'foo qbar baz');
218+
219+
cursorCommand(cursor, Handler.Undo, {});
220+
assert.equal(editor.getValue(), 'foo bar baz');
221+
});
222+
});
223+
196224
test('cursorWordEndLeft', () => {
197225
const EXPECTED = ['| /*| Just| some| more| text| a|+=| 3| +|5|-|3| +| 7| */| '].join('\n');
198226
const [text,] = deserializePipePositions(EXPECTED);

src/vs/editor/contrib/wordOperations/wordOperations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export abstract class MoveWordCommand extends EditorCommand {
5252
return this._moveTo(sel, outPosition, this._inSelectionMode);
5353
});
5454

55+
model.pushStackElement();
5556
editor._getCursors().setStates('moveWordCommand', CursorChangeReason.NotSet, result.map(r => CursorState.fromModelSelection(r)));
5657
if (result.length === 1) {
5758
const pos = new Position(result[0].positionLineNumber, result[0].positionColumn);

0 commit comments

Comments
 (0)