From b29bf621e936774bcbca97a049fbf4c601109620 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Sun, 24 Jul 2016 20:55:42 -0700 Subject: [PATCH 1/2] Omit first word in hash backwards search --- src/actions/actions.ts | 2 +- test/mode/normalModeTests/motions.test.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index f1b9c7a298a..758ed76c298 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -519,7 +519,7 @@ class CommandHash extends BaseCommand { vimState.searchState = new SearchState(-1, vimState.cursorPosition, currentWord); do { - vimState.cursorPosition = vimState.searchState.getNextSearchMatchPosition(vimState.cursorPosition).pos; + vimState.cursorPosition = vimState.searchState.getNextSearchMatchPosition(vimState.cursorPosition.getWordLeft()).pos; } while (CommandStar.GetWordAtPosition(vimState.cursorPosition) !== currentWord); return vimState; diff --git a/test/mode/normalModeTests/motions.test.ts b/test/mode/normalModeTests/motions.test.ts index c663836cf4a..f30e1d30958 100644 --- a/test/mode/normalModeTests/motions.test.ts +++ b/test/mode/normalModeTests/motions.test.ts @@ -395,6 +395,13 @@ suite("Motions in Normal Mode", () => { end: ['|blah duh blah duh blah'] }); + newTest({ + title: "Can handle # already on the word", + start: ['one o|ne'], + keysPressed: '#', + end: ['|one one'] + }); + newTest({ title: "Can handle ##", start: ['blah duh blah duh |blah'], From 2ae3f8813f397c9b7c839906bc0d9753ebeb2907 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Sun, 24 Jul 2016 23:39:14 -0700 Subject: [PATCH 2/2] Add comments --- src/actions/actions.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 758ed76c298..09eaf2c5271 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -519,6 +519,9 @@ class CommandHash extends BaseCommand { vimState.searchState = new SearchState(-1, vimState.cursorPosition, currentWord); do { + // use getWordLeft() on position to start at the beginning of the word. + // this ensures that any matches happen ounside of the word currently selected, + // which are the desired semantics for this motion. vimState.cursorPosition = vimState.searchState.getNextSearchMatchPosition(vimState.cursorPosition.getWordLeft()).pos; } while (CommandStar.GetWordAtPosition(vimState.cursorPosition) !== currentWord);