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

cancel snippet mode when undo'ing to the 'before' state, fixes #27612

上级 c212aeb7
......@@ -82,9 +82,9 @@ export class SnippetController2 {
private readonly _hasNextTabstop: IContextKey<boolean>;
private readonly _hasPrevTabstop: IContextKey<boolean>;
// private _snippet: SnippetSession;
private _sessions = new SnippetSessions();
private _snippetListener: IDisposable[] = [];
private _modelVersionId: number;
constructor(
private readonly _editor: ICommonCodeEditor,
......@@ -122,7 +122,13 @@ export class SnippetController2 {
const snippet = new SnippetSession(this._editor, template, overwriteBefore, overwriteAfter);
const newLen = this._sessions.add(snippet);
snippet.insert(newLen > 1);
if (newLen === 1) {
this._modelVersionId = this._editor.getModel().getAlternativeVersionId();
snippet.insert(false);
} else {
snippet.insert(true);
}
if (undoStopAfter) {
this._editor.getModel().pushStackElement();
......@@ -141,6 +147,12 @@ export class SnippetController2 {
return;
}
if (this._modelVersionId === this._editor.getModel().getAlternativeVersionId()) {
// undo until the 'before' state happened
// and makes use cancel snippet mode
return this.cancel();
}
if (!this._sessions.hasPlaceholder) {
// don't listen for selection changes and don't
// update context keys when the snippet is plain text
......
......@@ -189,16 +189,16 @@ suite('SnippetController', () => {
});
});
// test('Stops when undoing', () => {
// snippetTest((editor, cursor, codeSnippet, snippetController) => {
// editor.setPosition({ lineNumber: 4, column: 2 });
// snippetController.run(codeSnippet, 0, 0);
test('Stops when undoing', () => {
snippetTest((editor, cursor, codeSnippet, snippetController) => {
editor.setPosition({ lineNumber: 4, column: 2 });
snippetController.insert(codeSnippet, 0, 0);
// editor.getModel().undo();
editor.getModel().undo();
// assert.equal(snippetController.isInSnippetMode(), false);
// });
// });
assert.equal(snippetController.isInSnippetMode(), false);
});
});
test('Stops when moving cursor outside', () => {
snippetTest((editor, cursor, codeSnippet, snippetController) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册