Closed gchp closed 10 years ago
I've fixed the issues I was seeing with WordUnderCursor
and it seems to be working as expected now. I added some tests which cover the issues I was seeing.
The one thing I did not fix was the case where the cursor is over a single character word such as a
or I
. In this case, the small word, and the next whole word will be returned. I'm not sure how vim handles this, which is why I haven't fixed it. Going to have a look now.
@kisielk I've fixed the single character word case. Let me know if I can improve on this in any way!
getting there I think
what happens when the cursor is on whitespace?
Applied the changes you suggested.
Currently, when you are on whitespace it will just return nil
. I think that is reasonable?
I think returning nil is fine for now. Not sure what other vi's do yet.
But you probably need to change the implementation of keybindings to check for nil
so they don't clobber the search term and execute the search command.
Added a test for the byte width. What bytes would be longer than 1? I've not come across any.
I don't think that will be an issue. The expected return type of WordUnderCursor
is []byte
. If you return nil, it essentially returns nothing.
I also then convert this to a string in order to pass it to storeSearchTerm
. As far as I know converting nil
to a string doesn't yield anything.
See here for an example: http://play.golang.org/p/obFGhvqoQn
Any character outside of the latin character set will have a width greater than one, but I don't think we need to explicitly test that, just that we return 0 when we expect it and 1 on a regular character.
As for the nil, I know it works and I'm not concerned with crashes, but more the fact that I think doing a "search for word under cursor" when your cursor is not over a word should not cause the editor to forget the previous search term.
Ah, right yeah that makes sense. Just updated.
Updated - removed the un-needed return value