diff --git a/src/vs/editor/common/controller/oneCursor.ts b/src/vs/editor/common/controller/oneCursor.ts index 63fd0a1cd5c267ad058b4e6297bd096d9ec69cd5..877dca6350cef1f5e4ab34067332d519a1a8c621 100644 --- a/src/vs/editor/common/controller/oneCursor.ts +++ b/src/vs/editor/common/controller/oneCursor.ts @@ -714,23 +714,22 @@ export class OneCursorOp { let viewSel = cursor.viewState.selection; let viewStartLineNumber = viewSel.startLineNumber; - let viewStartColumn = viewSel.startColumn; let viewEndLineNumber = viewSel.endLineNumber; let viewEndColumn = viewSel.endColumn; - let viewEndMaxColumn = cursor.viewModel.getLineMaxColumn(viewEndLineNumber); - if (viewStartColumn !== 1 || viewEndColumn !== viewEndMaxColumn) { - viewStartColumn = 1; - viewEndColumn = viewEndMaxColumn; - } else { - // Expand selection with one more line down - let moveResult = MoveOperations.down(cursor.config, cursor.viewModel, viewEndLineNumber, viewEndColumn, 0, 1, true); - viewEndLineNumber = moveResult.lineNumber; + let moveResult = MoveOperations.down(cursor.config, cursor.viewModel, viewEndLineNumber, viewEndColumn, 0, 1, true); + viewEndLineNumber = moveResult.lineNumber; + + // If we reach the last line of the document, select until the end of line too + if (cursor.viewModel.getLineCount() === viewSel.endLineNumber) { viewEndColumn = cursor.viewModel.getLineMaxColumn(viewEndLineNumber); + } else { + viewEndColumn = 1; } - cursor.moveViewPosition(false, viewStartLineNumber, viewStartColumn, 0, true); + cursor.moveViewPosition(false, viewStartLineNumber, 1, 0, true); cursor.moveViewPosition(true, viewEndLineNumber, viewEndColumn, 0, true); + return true; } diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index bd6ed7764f76cb3938bf92adf4e13d47e5b3890e..a572aaaeb1d021b2e35ced195a671e11891882e6 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -749,33 +749,33 @@ suite('Editor Controller - Cursor', () => { // let LINE1 = ' \tMy First Line\t '; moveTo(thisCursor, 1, 1); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); moveTo(thisCursor, 1, 2); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); moveTo(thisCursor, 1, 5); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); moveTo(thisCursor, 1, 19); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); moveTo(thisCursor, 1, 20); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); moveTo(thisCursor, 1, 21); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 1, LINE1.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 2, 1)); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 2, LINE2.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 3, 1)); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 3, LINE3.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 4, 1)); cursorCommand(thisCursor, H.ExpandLineSelection); - assertCursor(thisCursor, new Selection(1, 1, 4, LINE4.length + 1)); + assertCursor(thisCursor, new Selection(1, 1, 5, 1)); cursorCommand(thisCursor, H.ExpandLineSelection); assertCursor(thisCursor, new Selection(1, 1, 5, LINE5.length + 1)); cursorCommand(thisCursor, H.ExpandLineSelection);