evil-helix icon indicating copy to clipboard operation
evil-helix copied to clipboard

fix diw and ciw

Open RoastBeefer00 opened this issue 1 year ago • 4 comments

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.

RoastBeefer00 avatar Nov 13 '24 00:11 RoastBeefer00

While this seems to solve the issue (haven't tested), maybe a solution closer to how miw implements word selection should be the desired?

Diegovsky avatar Nov 23 '24 15:11 Diegovsky

@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:

  1. In normal mode, move the cursor to the character a.
  2. Switch to visual mode with v.
  3. Go left with h or left, and go back to normal mode with esc

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).

usagi-flow avatar Dec 06 '24 17:12 usagi-flow

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 :)

RoastBeefer00 avatar Dec 06 '24 17:12 RoastBeefer00

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 :(

Diegovsky avatar Dec 06 '24 18:12 Diegovsky