Skip to content

Commit

Permalink
Fixes Incorrect Cursor Position after Transition into Normal Mode
Browse files Browse the repository at this point in the history
- By having `redraw` enforce cursor position, we were double
  moving becase both `redraw` (via `Motion.changedMode`) and
  `handleActivationKey` were moving the cursor left. This makes
  it so `redraw` is not responsible for enforcing the cursor
  position. Instead, position enforcement is handled only when
  the cursor may have been moved externally (ie via the mouse).
  • Loading branch information
dpbackes committed Apr 10, 2016
1 parent fa75d3e commit 64aa10f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export class NormalMode extends Mode {
"dw" : async (m) => {
m.changeMode(MotionMode.Cursor);
await new DeleteOperator(this._modeHandler).run(m.position, m.position.getWordRight());

if (m.lineEnd().position === m.position) {
m.left().move();
}

return {};
},
"dW" : async (m) => {
Expand Down Expand Up @@ -131,9 +131,9 @@ export class NormalMode extends Mode {
return {};
},
"x" : async (m) => {
m.changeMode(MotionMode.Cursor);
await new DeleteOperator(this._modeHandler).run(m.position, m.position.getRight());
return {};
m.changeMode(MotionMode.Cursor);
await new DeleteOperator(this._modeHandler).run(m.position, m.position.getRight());
return {};
},
"X" : async (m) => { return vscode.commands.executeCommand("deleteLeft"); },
"esc": async () => { return vscode.commands.executeCommand("workbench.action.closeMessages"); }
Expand Down
19 changes: 10 additions & 9 deletions src/motion/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ export class Motion implements vscode.Disposable {
let line = selection.active.line;
let char = selection.active.character;

this.position = new Position(line, char, null);
var newPosition = new Position(line, char, this._position.positionOptions);

if (char > newPosition.getLineEnd().character) {
newPosition = new Position(newPosition.line, newPosition.getLineEnd().character, null);
}

this.position = newPosition;
this._desiredColumn = this.position.character;
this.changeMode(this._motionMode);
}
Expand All @@ -72,7 +78,7 @@ export class Motion implements vscode.Disposable {
this.redraw();
return this;
}

public move(): Motion {
return this.moveTo(null, null);
}
Expand Down Expand Up @@ -102,12 +108,7 @@ export class Motion implements vscode.Disposable {
case MotionMode.Caret:
// Valid Positions for Caret: [0, eol)
this._position.positionOptions = PositionOptions.CharacterWiseExclusive;

if (this.position.character > this._position.getLineEnd().character) {
this._position = this._position.getLineEnd();
this._desiredColumn = this._position.character;
}


this.highlightBlock(this.position);
break;

Expand All @@ -118,7 +119,7 @@ export class Motion implements vscode.Disposable {
break;
}
}

/**
* Allows us to simulate a block cursor by highlighting a 1 character
* space at the provided position in a lighter color.
Expand Down

0 comments on commit 64aa10f

Please sign in to comment.