fix diw and ciw
Fix diw and ciw commands
Example
If you have the following text:
foo bar
and your cursor is on the b of bar and you type diw, it will delete everything BEFORE the b because it's looking for the previous word beginning not realizing it's already at the beginning of a word. In VIM with the same situation it would delete all all bar while leaving foo as is.
While this seems to solve the issue (haven't tested), maybe a solution closer to how miw implements word selection should be the desired?
@RoastBeefer00 thank you very much for the PR, much appreciated! And sorry for my late reply.
There is still a small imperfection: Your correction assumes anchor < head, which is not necessarily true:
- In normal mode, move the cursor to the character
a. - Switch to visual mode with
v. - Go left with
horleft, and go back to normal mode withesc
If you now execute ciw, you'll notice the old behavior.
I'm still a bit unsure as to how to proceed; I don't mind merging your PR, especially if you could take care of the case where anchor > head.
But @Diegovsky makes an important point: This logic is already implemented. Unfortunately, select_textobject(), the function in commands.rs which holds this logic, performs the selection right away, whereas I seeked to separate functions which obtain a selection and functions which perform an action on a selection.
In other words, I don't see a straightforward way to reuse the code without altering it (which I'd rather avoid).
No problem at all, please feel free to change or close the PR. Also, I was inspired to make my own evil Helix, which I started from scratch. Please check that out if you wish :)
Well, I don't think the helix team would deny a PR that separates this selection from the command execution context. It is worth a try, and in the end, it could be very tightly integrated with <cmd>iw motions :)
PS: I would volunteer to do it myself, but unfortunately, I don't have the time :(