提交 de8f1b80 编写于 作者: J Johannes Rieken

reset editor selection when explicitly cancelling snippet mode, #68512

上级 1eb6de1d
......@@ -193,7 +193,7 @@ export class SnippetController2 implements IEditorContribution {
}
}
cancel(): void {
cancel(resetSelection: boolean = false): void {
this._inSnippet.reset();
this._hasPrevTabstop.reset();
this._hasNextTabstop.reset();
......@@ -201,6 +201,12 @@ export class SnippetController2 implements IEditorContribution {
dispose(this._session);
this._session = undefined;
this._modelVersionId = -1;
if (resetSelection) {
// reset selection to the primary cursor when being asked
// for. this happens when explicitly cancelling snippet mode,
// e.g. when pressing ESC
this._editor.setSelections([this._editor.getSelection()]);
}
}
prev(): void {
......@@ -257,7 +263,7 @@ registerEditorCommand(new CommandCtor({
registerEditorCommand(new CommandCtor({
id: 'leaveSnippet',
precondition: SnippetController2.InSnippetMode,
handler: ctrl => ctrl.cancel(),
handler: ctrl => ctrl.cancel(true),
kbOpts: {
weight: KeybindingWeight.EditorContrib + 30,
kbExpr: EditorContextKeys.editorTextFocus,
......
......@@ -361,4 +361,44 @@ suite('SnippetController2', function () {
assertSelections(editor, new Selection(1, 7, 1, 7));
assertContextKeys(contextKeys, false, false, false);
});
test('Cancelling snippet mode should discard added cursors #68512 (soft cancel)', function () {
const ctrl = new SnippetController2(editor, logService, contextKeys);
model.setValue('');
editor.setSelection(new Selection(1, 1, 1, 1));
ctrl.insert('.REGION ${2:FUNCTION_NAME}\nCREATE.FUNCTION ${1:VOID} ${2:FUNCTION_NAME}(${3:})\n\t${4:}\nEND\n.ENDREGION$0');
assertSelections(editor, new Selection(2, 17, 2, 21));
ctrl.next();
assertSelections(editor, new Selection(1, 9, 1, 22), new Selection(2, 22, 2, 35));
assertContextKeys(contextKeys, true, true, true);
editor.setSelections([new Selection(1, 22, 1, 22), new Selection(2, 35, 2, 35)]);
assertContextKeys(contextKeys, true, true, true);
editor.setSelections([new Selection(2, 1, 2, 1), new Selection(2, 36, 2, 36)]);
assertContextKeys(contextKeys, false, false, false);
assertSelections(editor, new Selection(2, 1, 2, 1), new Selection(2, 36, 2, 36));
});
test('Cancelling snippet mode should discard added cursors #68512 (hard cancel)', function () {
const ctrl = new SnippetController2(editor, logService, contextKeys);
model.setValue('');
editor.setSelection(new Selection(1, 1, 1, 1));
ctrl.insert('.REGION ${2:FUNCTION_NAME}\nCREATE.FUNCTION ${1:VOID} ${2:FUNCTION_NAME}(${3:})\n\t${4:}\nEND\n.ENDREGION$0');
assertSelections(editor, new Selection(2, 17, 2, 21));
ctrl.next();
assertSelections(editor, new Selection(1, 9, 1, 22), new Selection(2, 22, 2, 35));
assertContextKeys(contextKeys, true, true, true);
editor.setSelections([new Selection(1, 22, 1, 22), new Selection(2, 35, 2, 35)]);
assertContextKeys(contextKeys, true, true, true);
ctrl.cancel(true);
assertContextKeys(contextKeys, false, false, false);
assertSelections(editor, new Selection(1, 22, 1, 22));
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册