-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support exact and inexact current word search #1277
Conversation
b346dba
to
119f6ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the bit of duplication, this looks good to me. Thanks so much for the PR! :)
src/actions/actions.ts
Outdated
@@ -1583,6 +1583,34 @@ class CommandStar extends BaseCommand { | |||
return vimState; | |||
} | |||
|
|||
vimState.globalState.searchState = new SearchState( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we share methods with static methods on one of the relevant classes.
Seems I need to update some tests... I started looking into this and found this test: newTest({
title: "Can handle tricky *",
start: ['|blah blahblah duh blah'],
keysPressed: '*',
end: ['blah blahblah duh |blah']
}); Which superficially implies that the change I've made was already implemented? However, on further investigation this is actually behaving incorrectly. Either VSCodeVim I think I should review these few test cases and make sure they can't trigger false positives (and add more coverage for these commands). I need to fix other broken tests as well so I can look into this at the same time (or open a separate issue). |
Yeah - this behavior actually works correctly on my machine. So I feel like we're dealing with some config oddities rather than actual bugs. (I do remember covering this case many many months ago...) I'm okay with your solution, which feels nice, but I would like to know what exactly went wrong... |
Hm. Yeah, that is weird. You did mention that and I had assumed at the time that you had misunderstood my report (since the code itself didn't seem to handle the correct behaviour). Even if I completely clear my config this still behaves as reported in #1266, so perhaps you have some configuration that is causing it to do the right thing? Could you confirm whether you get the incorrect initial move with |
Oh yeah good point. My Vim related settings are:
|
Using your configuration made no difference. |
Rename `CommandStar` and `CommandHash` to `CommandSearchCurrentWordExactForward` and `CommandSearchCurrentWorldExactBackward`, which describe their effect. Also include regex word bounds in the search so that they act the same as in Vim. Add `CommandSearchCurrentWordForward` and `…Backward` (commands `g*` and `g#` respectively), that match without word bounds. Closes VSCodeVim#1266
119f6ad
to
3643de0
Compare
Add tests for `g*` and `g#` by themselves and in combination with `n` (to step to next command). Previously the `#` and `*` commands (and, by virtue of having been copied, the `g#` and `g*` commands introduced in a previous commit) would immediately search and filter any matches that were not full word matches. ie. they would skip matches "hello" when searching for "he". This would work fine for `*` or `#` directly, but subsequent uses of `n` or `N` would match incorrectly since the word bounds were not included in the search state.
Combine implementation of all four search commands (`*`, `#`, `g*`, `g#`) into a single function taking a `direction` and `isExact` argument.
@johnfn Okay, I've added tests, fixed all the problems I identified, and removed the duplication between commands. There's more information in the commit messages. Locally all tests pass. The failures here seem to also be present in master. |
Great! I have been noticing weirdness with the tests as well - sorry if that was confusing. Thanks again for the PR. |
Rename
CommandStar
andCommandHash
toCommandSearchCurrentWordExactForward
andCommandSearchCurrentWorldExactBackward
, which describe their effect. Also include regex word bounds in the search so that they act the same as in Vim.Add
CommandSearchCurrentWordForward
and…Backward
(commandsg*
andg#
respectively), that match without word bounds.Closes #1266
So this is mainly a copy+paste, I wasn't sure if there was an idiomatic approach to sharing behaviour between these two commands. Also I renamed the classes because it felt more sensible to name them after their effect than their keybindings (also it seemed strange to call the new one something like
CommandGStar
.Let me know if there's anything stylistically or functionally wrong here, I'm happy to iterate on it.