Skip to content

Commit

Permalink
Fixed edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kou Tenichi committed Apr 6, 2017
1 parent d392d54 commit 3c563f9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Actions/MoveCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ export class ActionMoveCursor {
if (args.isVisualMode) {
anchor = selection.anchor;

if (active.isAfterOrEqual(anchor)) {
const lineLength = activeTextEditor.document.lineAt(active.line).text.length;
if (active.character < lineLength) {
active = active.translate(0, +1);
}
const anchorLineLength = activeTextEditor.document.lineAt(anchor.line).text.length;
const activeLineLength = activeTextEditor.document.lineAt(active.line).text.length;

if (active.isAfterOrEqual(anchor) && active.character < activeLineLength) {
active = active.translate(0, +1);
}

if (active.isAfter(anchor) && selection.isReversed) {
if (active.isEqual(anchor) && anchor.character > 0) {
anchor = anchor.translate(0, -1);
}
else if (active.isAfter(anchor) && selection.isReversed && anchor.character > 0) {
anchor = anchor.translate(0, -1);
}
else if (active.isBefore(anchor) && !selection.isReversed) {
else if (active.isBefore(anchor) && !selection.isReversed && anchor.character < anchorLineLength) {
anchor = anchor.translate(0, +1);
}
}
Expand Down

0 comments on commit 3c563f9

Please sign in to comment.