Skip to content

Commit 942e9be

Browse files
committed
Fixes for PR microsoft#961
1 parent cab3627 commit 942e9be

3 files changed

Lines changed: 58 additions & 10 deletions

File tree

src/vs/editor/common/config/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ registerCoreCommand(H.CursorEndSelect, {
198198
mac: { primary: KeyMod.Shift | KeyCode.End, secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow] }
199199
});
200200
registerCoreCommand(H.ExpandLineSelection, {
201-
primary: KeyMod.CtrlCmd | KeyCode.KEY_I,
202-
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_I}
201+
primary: KeyMod.CtrlCmd | KeyCode.KEY_I
203202
});
204203

205204
registerCoreCommand(H.Tab, {

src/vs/editor/common/controller/oneCursor.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,16 +739,26 @@ export class OneCursorOp {
739739

740740
public static expandLineSelection(cursor:OneCursor, ctx: IOneCursorOperationContext): boolean {
741741
ctx.cursorPositionChangeReason = 'explicit';
742-
var currentSelection = cursor.getSelection();
743-
var lastColumn = cursor.getColumnAtEndOfViewLine(currentSelection.endLineNumber, currentSelection.endColumn);
744-
var expandedSelection = new Selection(currentSelection.startLineNumber,1,currentSelection.endLineNumber,lastColumn);
745-
if (currentSelection.equalsSelection(expandedSelection)){
746-
lastColumn = cursor.getColumnAtEndOfViewLine(currentSelection.endLineNumber+1, currentSelection.endColumn+1);
747-
expandedSelection = new Selection(currentSelection.startLineNumber,1,currentSelection.endLineNumber+1,lastColumn);
748-
cursor.setSelection(expandedSelection);
742+
let viewSel = cursor.getViewSelection();
743+
744+
let viewStartLineNumber = viewSel.startLineNumber;
745+
let viewStartColumn = viewSel.startColumn;
746+
let viewEndLineNumber = viewSel.endLineNumber;
747+
let viewEndColumn = viewSel.endColumn;
748+
749+
let viewEndMaxColumn = cursor.getViewLineMaxColumn(viewEndLineNumber);
750+
if (viewStartColumn !== 1 || viewEndColumn !== viewEndMaxColumn) {
751+
viewStartColumn = 1;
752+
viewEndColumn = viewEndMaxColumn;
749753
} else {
750-
cursor.setSelection(expandedSelection);
754+
// Expand selection with one more line down
755+
let moveResult = cursor.getViewPositionDown(viewEndLineNumber, viewEndColumn, 0, 1);
756+
viewEndLineNumber = moveResult.lineNumber;
757+
viewEndColumn = cursor.getViewLineMaxColumn(viewEndLineNumber);
751758
}
759+
760+
cursor.moveViewPosition(false, viewStartLineNumber, viewStartColumn, 0, true);
761+
cursor.moveViewPosition(true, viewEndLineNumber, viewEndColumn, 0, true);
752762
return true;
753763
}
754764

src/vs/editor/test/common/controller/cursor.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,45 @@ suite('Editor Controller - Cursor', () => {
649649
cursorEqual(thisCursor, 5, LINE5.length + 1, 1, 1);
650650
});
651651

652+
test('expandLineSelection', () => {
653+
// 0 1 2
654+
// 01234 56789012345678 0
655+
// var LINE1 = ' \tMy First Line\t ';
656+
moveTo(thisCursor, 1, 1);
657+
cursorCommand(thisCursor, H.ExpandLineSelection);
658+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
659+
660+
moveTo(thisCursor, 1, 2);
661+
cursorCommand(thisCursor, H.ExpandLineSelection);
662+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
663+
664+
moveTo(thisCursor, 1, 5);
665+
cursorCommand(thisCursor, H.ExpandLineSelection);
666+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
667+
668+
moveTo(thisCursor, 1, 19);
669+
cursorCommand(thisCursor, H.ExpandLineSelection);
670+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
671+
672+
moveTo(thisCursor, 1, 20);
673+
cursorCommand(thisCursor, H.ExpandLineSelection);
674+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
675+
676+
moveTo(thisCursor, 1, 21);
677+
cursorCommand(thisCursor, H.ExpandLineSelection);
678+
cursorEqual(thisCursor, 1, LINE1.length + 1, 1, 1);
679+
cursorCommand(thisCursor, H.ExpandLineSelection);
680+
cursorEqual(thisCursor, 2, LINE2.length + 1, 1, 1);
681+
cursorCommand(thisCursor, H.ExpandLineSelection);
682+
cursorEqual(thisCursor, 3, LINE3.length + 1, 1, 1);
683+
cursorCommand(thisCursor, H.ExpandLineSelection);
684+
cursorEqual(thisCursor, 4, LINE4.length + 1, 1, 1);
685+
cursorCommand(thisCursor, H.ExpandLineSelection);
686+
cursorEqual(thisCursor, 5, LINE5.length + 1, 1, 1);
687+
cursorCommand(thisCursor, H.ExpandLineSelection);
688+
cursorEqual(thisCursor, 5, LINE5.length + 1, 1, 1);
689+
});
690+
652691
// --------- eventing
653692

654693
test('no move doesn\'t trigger event', () => {

0 commit comments

Comments
 (0)