mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-21 02:11:11 +00:00
Fixes #35673: Comment hotkeys throws the cursor before the comment
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user