Fixes #35673: Comment hotkeys throws the cursor before the comment

This commit is contained in:
Alex Dima
2017-10-09 16:50:58 +02:00
parent 6e7a575339
commit 7e5db3ffed
2 changed files with 52 additions and 0 deletions

View File

@@ -200,8 +200,16 @@ export class LineCommentCommand implements editorCommon.ICommand {
ops = LineCommentCommand._createAddLineCommentsOperations(data.lines, s.startLineNumber);
}
const cursorPosition = new Position(s.positionLineNumber, s.positionColumn);
for (var i = 0, len = ops.length; i < len; i++) {
builder.addEditOperation(ops[i].range, ops[i].text);
if (ops[i].range.isEmpty() && ops[i].range.getStartPosition().equals(cursorPosition)) {
const lineContent = model.getLineContent(cursorPosition.lineNumber);
if (lineContent.length + 1 === cursorPosition.column) {
this._deltaColumn = ops[i].text.length;
}
}
}
this._selectionId = builder.trackSelection(s);

View File

@@ -518,6 +518,50 @@ suite('Editor Contrib - Line Comment Command', () => {
);
});
test('issue #35673: Comment hotkeys throws the cursor before the comment', () => {
testLineCommentCommand(
[
'first',
'',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 1, 2, 1),
[
'first',
'!@# ',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 5, 2, 5)
);
testLineCommentCommand(
[
'first',
'\t',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 2, 2, 2),
[
'first',
'\t!@# ',
'\tsecond line',
'third line',
'fourth line',
'fifth'
],
new Selection(2, 6, 2, 6)
);
});
test('issue #2837 "Add Line Comment" fault when blank lines involved', function () {
testAddLineCommentCommand(
[