提交 47c89258 编写于 作者: A Alex Dima

Insert an undo stop when typing space (#34073)

上级 8e1402b8
......@@ -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 {
......
......@@ -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));
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册