Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move word special case to appropriate place. #239

Merged
merged 1 commit into from
Jun 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 1 addition & 25 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InsertMode } from './modeInsert';
import { VisualMode } from './modeVisual';
import {
BaseMovement, BaseCommand, Actions,
MoveWordBegin, BaseOperator,
BaseOperator,
KeypressState } from './../actions/actions';
import { Configuration } from '../configuration/configuration';
import { Position } from './../motion/position';
Expand Down 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