diff --git a/src/vs/editor/common/controller/cursorTypeOperations.ts b/src/vs/editor/common/controller/cursorTypeOperations.ts index cad7da5a71cc65e09a2919825081c8534fcba4b7..0ffb52bd5afb900297d77e4cdd88efa4b0c159f9 100644 --- a/src/vs/editor/common/controller/cursorTypeOperations.ts +++ b/src/vs/editor/common/controller/cursorTypeOperations.ts @@ -739,7 +739,19 @@ export class TypeOperations { } } - return this.typeWithoutInterceptors(prevEditOperationType, config, model, selections, ch); + // A simple character type + let commands: ICommand[] = []; + for (let i = 0, len = selections.length; i < len; i++) { + commands[i] = new ReplaceCommand(selections[i], ch); + } + let shouldPushStackElementBefore = (prevEditOperationType !== EditOperationType.Typing); + if (ch === ' ') { + shouldPushStackElementBefore = true; + } + return new EditOperationResult(EditOperationType.Typing, commands, { + shouldPushStackElementBefore: shouldPushStackElementBefore, + shouldPushStackElementAfter: false + }); } public static typeWithoutInterceptors(prevEditOperationType: EditOperationType, config: CursorConfiguration, model: ITokenizedModel, selections: Selection[], str: string): EditOperationResult { diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index c891a78db07ffbcc79339a7e9598f5f59f155ec2..98b3810dec495357b909695387a6a944cea294b1 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -4040,4 +4040,32 @@ suite('Undo stops', () => { }); }); + test('inserts undo stop when typing space', () => { + let model = Model.createFromString( + [ + 'A line', + 'Another line', + ].join('\n') + ); + + withMockCodeEditor(null, { model: model }, (editor, cursor) => { + cursor.setSelections('test', [new Selection(1, 3, 1, 3)]); + cursorCommand(cursor, H.Type, { text: 'first and interesting' }, 'keyboard'); + assert.equal(model.getLineContent(1), 'A first and interesting line'); + assertCursor(cursor, new Selection(1, 24, 1, 24)); + + cursorCommand(cursor, H.Undo, {}); + assert.equal(model.getLineContent(1), 'A first and line'); + assertCursor(cursor, new Selection(1, 12, 1, 12)); + + cursorCommand(cursor, H.Undo, {}); + assert.equal(model.getLineContent(1), 'A first line'); + assertCursor(cursor, new Selection(1, 8, 1, 8)); + + cursorCommand(cursor, H.Undo, {}); + assert.equal(model.getLineContent(1), 'A line'); + assertCursor(cursor, new Selection(1, 3, 1, 3)); + }); + }); + });