Skip to content
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

fix diw and ciw #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RoastBeefer00
Copy link

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.

@Diegovsky
Copy link

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

@usagi-flow
Copy link
Owner

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

@RoastBeefer00
Copy link
Author

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

@Diegovsky
Copy link

Diegovsky commented Dec 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants