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

[mini.ai] textobject selection places cursor at the beginning instead of the end of the selection #1448

Closed
3 tasks done
linjiX opened this issue Dec 31, 2024 · 4 comments
Closed
3 tasks done
Labels
feature-request Request for a feature to existing module mini.ai

Comments

@linjiX
Copy link

linjiX commented Dec 31, 2024

Contributing guidelines

Module(s)

mini.ai

Description

When using textobjects provided by mini.ai in Visual mode (e.g., vi) or vi"), the cursor is placed at the beginning of the selection. However, Neovim's default behavior places the cursor at the end of the selection.

This creates an inconsistency between mini.ai textobjects and Neovim's default textobjects. For example:

  • Using viw places the cursor at the end of the selected word.
  • Using vi) places the cursor at the beginning of the selected parentheses.

This behavior is unexpected for users accustomed to Neovim's default textobject behavior.

Would it be possible to:

  1. Adjust the default behavior to match Neovim's default, where the cursor is placed at the end of the selection?
  2. Alternatively, provide an option to configure this behavior?

Neovim version

0.10.3

Steps to reproduce

  1. Open any file in Neovim with mini.ai enabled.
  2. Place the cursor inside a pair of parentheses or quotes, e.g., This is (a test) or "some text".
  3. Enter Visual mode and use vi) or vi" to select the textobject.

Expected behavior

The cursor should be placed at the end of the selected textobject, matching Neovim's default behavior.

Actual behavior

The cursor is placed at the beginning of the selected textobject.

@linjiX linjiX added the bug Something isn't working label Dec 31, 2024
@echasnovski echasnovski added feature-request Request for a feature to existing module mini.ai and removed bug Something isn't working labels Dec 31, 2024
@echasnovski
Copy link
Owner

Thanks for the suggestion!

If I remember correctly the main motivation for this behavior is to be consistent with how cursor is placed after operating on textobject. This is explicitly documented while cursor placement after visual selection is more of an implementation detail. At least I am not aware of the explicit documentation on the matter.

This was previously closed as not planned (but I can not find right now), but I'll revisit later (and also take a look at whether there are more important implementation reasons for that in 'mini.ai').

@linjiX
Copy link
Author

linjiX commented Dec 31, 2024

Thank you for your response and for explaining the design decision!

Based on my testing, in Neovim, after selecting a region and pressing y to yank, the cursor always moves back to the start of the selection. y + textobject acts the same. However, when using v + textobject to visually select content, the cursor always moves to the end of the selection.

This leads to a noticeable difference: for example, yiw leaves the cursor at the start of the word, while viw moves the cursor to the end of the word. If you follow viw with y (viw + y), the cursor first moves to the end of the selection (due to viw) and then returns to the start (due to y).

I’m not entirely sure why Vim was designed this way, but this has been the default behavior I’ve grown accustomed to over the years. It feels natural to me.

If it’s possible to add a parameter or configuration option to control this behavior in mini.ai, I would greatly appreciate it. This would allow users to choose between the current behavior and one more aligned with Neovim’s defaults.

@echasnovski
Copy link
Owner

There definitely won't be an option for this. I'll revisit and rethink about all pros and cons of putting cursor at the end vs the start. Right now I am leaning towards keeping current behavior, but we'll see.

echasnovski added a commit that referenced this issue Jan 31, 2025
This better aligns with how it is done for built-in textobjects, which
especially matters with "overlapping" textobjects (like a)/i"/etc.).

Resolve #1448
@echasnovski
Copy link
Owner

This should now be resolved on latest main. After a lot of internal back and forth, it indeed seems to be more reasonable to follow the (undocumented) "put on the right edge in Visual mode" than the (documented) "put on the left edge after operator action". Thanks again for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.ai
Projects
None yet
Development

No branches or pull requests

2 participants