From e3ad2b7511978102705bd1fbabb267bb0f348a05 Mon Sep 17 00:00:00 2001 From: johnfn Date: Sun, 5 Jun 2016 15:18:00 -0700 Subject: [PATCH] Move word special case to appropriate place. Why does w have so many special cases? --- src/actions/actions.ts | 26 ++++++++++++++++++++++++++ src/mode/modeHandler.ts | 26 +------------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 58d13f2f7f0..60d07950257 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -664,6 +664,32 @@ export class MoveWordBegin extends BaseMovement { return vimState; } + + public async execActionForOperator(position: Position, vimState: VimState): Promise { + 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 diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 53e8ab2b822..76e41123711 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -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'; @@ -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();