fix off by one issue, #16277

This commit is contained in:
Johannes Rieken 2016-12-01 09:23:29 +01:00
parent ff1991b789
commit de15217aee
2 changed files with 17 additions and 2 deletions

View file

@ -377,12 +377,12 @@ class BeforeAfterData {
let contentBefore = '';
if (overwriteBefore > 0) {
contentBefore = model.getLineContent(selection.startLineNumber).substring(selection.startColumn - 1 - overwriteBefore, selection.startColumn);
contentBefore = model.getLineContent(selection.startLineNumber).substring(selection.startColumn - 1 - overwriteBefore, selection.startColumn - 1);
}
let contentAfter = '';
if (overwriteAfter > 0) {
contentAfter = model.getLineContent(selection.endLineNumber).substring(selection.endColumn - 1, selection.endColumn + overwriteAfter);
contentAfter = model.getLineContent(selection.endLineNumber).substring(selection.endColumn - 1, selection.endColumn - 1 + overwriteAfter);
}
return new BeforeAfterData(model, contentBefore, contentAfter, overwriteBefore, overwriteAfter);

View file

@ -506,4 +506,19 @@ suite('SnippetController', () => {
}, ['this._', 'abc', 'def._']);
});
test('Multiple cursor and overwriteBefore/After, #16277', () => {
snippetTest((editor, cursor, codeSnippet, controller) => {
editor.setSelections([
new Selection(1, 5, 1, 5),
new Selection(2, 5, 2, 5),
]);
codeSnippet = CodeSnippet.fromTextmate('document');
controller.run(codeSnippet, 3, 0);
assert.equal(editor.getModel().getValue(), '{document}\n{document && true}');
}, ['{foo}', '{foo && true}']);
});
});