kisielk / vigo

Vi in Go
Other
168 stars 17 forks source link

Added Ctrl-A and Ctrl-M commands #32

Closed gchp closed 10 years ago

gchp commented 10 years ago

Updated - removed the un-needed return value

gchp commented 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.

gchp commented 10 years ago

@kisielk I've fixed the single character word case. Let me know if I can improve on this in any way!

kisielk commented 10 years ago

getting there I think

kisielk commented 10 years ago

what happens when the cursor is on whitespace?

gchp commented 10 years ago

Applied the changes you suggested.

Currently, when you are on whitespace it will just return nil. I think that is reasonable?

kisielk commented 10 years ago

I think returning nil is fine for now. Not sure what other vi's do yet.

kisielk commented 10 years ago

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.

gchp commented 10 years ago

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

kisielk commented 10 years ago

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.

gchp commented 10 years ago

Ah, right yeah that makes sense. Just updated.