Skip to content

Commit

Permalink
Move word special case to appropriate place.
Browse files Browse the repository at this point in the history
Why does w have so many special cases?
  • Loading branch information
johnfn committed Jun 5, 2016
1 parent f394940 commit 510a3c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
26 changes: 26 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,32 @@ export class MoveWordBegin extends BaseMovement {

return vimState;
}

public async execActionForOperator(position: Position, vimState: VimState): Promise<VimState> {
const result = await this.execAction(position, vimState);

/*
From the Vim documentation:
Another special case: When using the "w" motion in combination with an
operator and the last word moved over is at the end of a line, the end of
that word becomes the end of the operated text, not the first word in the
next line.
TODO - move this into actions.ts, add test.
*/

if (result.cursorPosition.isLineBeginning()) {
result.cursorPosition = result.cursorPosition.getLeftThroughLineBreaks();
}

if (result.cursorPosition.isLineEnd()) {
result.cursorPosition = new Position(result.cursorPosition.line, result.cursorPosition.character + 1);
}

return vimState;
}

}

@RegisterAction
Expand Down
24 changes: 0 additions & 24 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,30 +430,6 @@ export class ModeHandler implements vscode.Disposable {
}

if (actionState.operator) {
/*
From the Vim documentation:
Another special case: When using the "w" motion in combination with an
operator and the last word moved over is at the end of a line, the end of
that word becomes the end of the operated text, not the first word in the
next line.
TODO - move this into actions.ts, add test.
*/

if (actionState.movement instanceof MoveWordBegin) {
if (stop.isLineBeginning()) {
stop = stop.getLeftThroughLineBreaks();
}

if (stop.isLineEnd()) {
// Yes... we actually push the position OFF THE EDGE OF THE DOCUMENT.

// Why, Vim? WHY?
stop = new Position(stop.line, stop.character + 1);
}
}

if (actionState.movement) {
if (Position.EarlierOf(start, stop) === start) {
stop = stop.getLeft();
Expand Down

0 comments on commit 510a3c3

Please sign in to comment.