Skip to content

fix(operators): correctly handle newlines at start of textobject#2248

Merged
echasnovski merged 1 commit intonvim-mini:backlogfrom
TheLeoP:fix_newline
Feb 3, 2026
Merged

fix(operators): correctly handle newlines at start of textobject#2248
echasnovski merged 1 commit intonvim-mini:backlogfrom
TheLeoP:fix_newline

Conversation

@TheLeoP
Copy link
Member

@TheLeoP TheLeoP commented Jan 28, 2026

Partially fixes #2247

@echasnovski
Copy link
Member

If it is a change in do_between_marks, then I think it is reasonable to also add tests for all operators that use it. Namely, "multiply" and "exchange".

Also, I am a bit hesitant to yet merge this as it doesn't address both problems of #2247.

@TheLeoP
Copy link
Member Author

TheLeoP commented Jan 28, 2026

If it is a change in do_between_marks, then I think it is reasonable to also add tests for all operators that use it. Namely, "multiply" and "exchange".

On it.

Also, I am a bit hesitant to yet merge this as it doesn't address both problems of #2247.

Fair. I'll try to take a look at what may be causing the issue with the trailing newline tomorrow

@TheLeoP
Copy link
Member Author

TheLeoP commented Feb 2, 2026

I changed the commit message to include newlines at the end of textobject because I added a test for a different edge case on MiniOperators.replace that happened only on visual mode and only when replacing a region with a trailing newline. But, the operator still duplicates the trailing newline (it can't delete it because, as explained in #2247 (comment) , custom operators can't see trailing newlines).

We would be accepting that this is a current limitation of Neovim and the behavior is expected.

@echasnovski
Copy link
Member

Could you please move cache-set-unset of 'virtualedit' at least inside H.exchange_do or explore if only moving it inside H.replace_do is enough . Preferably closer to commands when they are actually needed (i.e. not at the top and bottom).

Also, please add the same one-line comment above each 'virtualedit' caching describing why this is needed.

For tests, it looks like the behavior is Visual mode specific. So could you please move them after 'works in Visual mode' cases for each operator and be more general like 'works with newline in region'. For trailing newlines in exchange and multiply having a comment about why it doesn't work (like Doesn't work due to Neovim limitations\nSee https://github.com/neovim/neovim/issues/37664).

@echasnovski echasnovski changed the base branch from main to backlog February 3, 2026 16:02
@echasnovski echasnovski merged commit cabec54 into nvim-mini:backlog Feb 3, 2026
12 checks passed
@echasnovski
Copy link
Member

I currently have time to finish nit-picking parts myself. Hope to merge into main soon-ish.

@echasnovski
Copy link
Member

The first version of this (with only do_between_marks) should now be part of latest main.

After looking more closely, having all "cache-set-unset" separate didn't gain much. The only case is for "replace" to act less wrong on trailing newline. The problem is that the resulting behavior is still wrong (replacing a region with itself should have produced the same text, not add another line).

So as the first version is much simpler and to the point, let's go with that one.


Thanks for all the deep research and PR to make 'mini.operators' better in this very narrow use case :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mini.operators] some operators have issues with newlines at start/end of textobject

2 participants