Fixes #90135: Consider that undo edits might also contain auto trim whitespace edits

This commit is contained in:
Alex Dima 2020-02-10 15:18:46 +01:00
parent aeafeb8a12
commit 6aefd70de8
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
2 changed files with 21 additions and 2 deletions

View file

@ -468,6 +468,7 @@ export class SnippetSession {
// that ensures the primiary cursor stays primary despite not being
// the one with lowest start position
edits[idx] = EditOperation.replace(snippetSelection, snippet.toString());
edits[idx].identifier = { major: idx, minor: 0 }; // mark the edit so only our undo edits will be used to generate end cursors
snippets[idx] = new OneSnippet(editor, snippet, offset);
}
@ -507,7 +508,11 @@ export class SnippetSession {
if (this._snippets[0].hasPlaceholder) {
return this._move(true);
} else {
return undoEdits.map(edit => Selection.fromPositions(edit.range.getEndPosition()));
return (
undoEdits
.filter(edit => !!edit.identifier) // only use our undo edits
.map(edit => Selection.fromPositions(edit.range.getEndPosition()))
);
}
});
this._editor.revealRange(this._editor.getSelections()[0]);
@ -529,7 +534,11 @@ export class SnippetSession {
if (this._snippets[0].hasPlaceholder) {
return this._move(undefined);
} else {
return undoEdits.map(edit => Selection.fromPositions(edit.range.getEndPosition()));
return (
undoEdits
.filter(edit => !!edit.identifier) // only use our undo edits
.map(edit => Selection.fromPositions(edit.range.getEndPosition()))
);
}
});
}

View file

@ -11,6 +11,7 @@ import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKe
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { NullLogService } from 'vs/platform/log/common/log';
import { Handler } from 'vs/editor/common/editorCommon';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
suite('SnippetController2', function () {
@ -428,4 +429,13 @@ suite('SnippetController2', function () {
assertSelections(editor, new Selection(2, 5, 2, 5));
assertContextKeys(contextKeys, false, false, false);
});
test('issue #90135: confusing trim whitespace edits', function () {
const ctrl = new SnippetController2(editor, logService, contextKeys);
model.setValue('');
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
ctrl.insert('\nfoo');
assertSelections(editor, new Selection(2, 8, 2, 8));
});
});