-
-
Notifications
You must be signed in to change notification settings - Fork 22
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: use abs()
so distance is always non-negative
#70
Conversation
That's an approach I initially tried out, but it does not work. There is the case where you want to compare two text objects:
Comparing just the absolute value of the distance will in this case result in textobj 2 being selected as the closest one, even though the cursor is standing on a text object. (And the idiomatic behavior of vim is to only do forward seeking of text objects when not already standing on one.) That one was a bit tricky to correctly figure out myself. I guess it does not hurt to add this as a comment, since it's not obvious on first look. |
I think As opposed to brackets, |
Hm what about this method?
That will fix it in my case, when Lua patterns aren't expressive enough. Using Tree-sitter AST would be ideal. I haven't looked into that and am not sure how I'd get that working. |
That is pretty much what the current code is doing 😉 |
Not quite, as both of these are text objects that match:
The second one is closer to the cursor, but the first one gets matched instead. |
you haven't indicated a cursor position, so it's not possible to follow your example |
I've updated my comment. |
I just gave it a try with the local a = "1 + 2222" .. "|1111 + 2"
local b = (1 + 2222) .. (|1111 + 2) In both these cases, it matches correctly the second object. So I assume it's some issue with the patterns of |
I don't know of a way to avoid matching
But Lua doesn't offer this. The current patterns of The only solution I can think of is to match the one closest to the cursor. Or of course there's also Tree-sitter which is the most ideal. |
yeah, lua patterns are somewhat limited. You could maybe have try whether maybe something with frontier patterns work, since they are lua's simplified version of lookbehinds.
As I said, this is pretty much what the current code is doing, considering various cases for comparing textobj standing on or not standing on an obj. And it works for me on other text objects. I want to avoid modifying the core logic if it does not solve a problem multiple textobjects have.
yeah, this plugin isn't really intended for treesitter textobjects, since nvim-treesitter-textobj has all the logic for that. So I guess I'd also consider making a FR/PR over there. |
Well I did ask in nvim-treesitter/nvim-treesitter-textobjects#547 with no reply yet.
It does seem like a bug to me though, if the patterns of |
yes, and if the bug only occurs with |
The bug only occurring in |
Sounds to me like an issue with the patterns. The code of |
You're right, but I don't think Lua has regex groups, that's required in this case.
You're right as well, however given two textobjects, it's not choosing the closer one here. I believe that's what it's designed to do. If it does that, then the patterns should work out. |
yeah,
So yes, strictly speaking, In theory, it is possible to modify |
That makes sense, however in the current case I can't see another easy solution. The only other solutions I can think of is to use tree-sitter, or use a proper regex engine. I don't think handling this case would really add much code. |
So one option would be to utilize If you can find a fix for Thinking about it, and considering all the edge cases that exist for mdEmphasis (having the highest number of patterns already), using Treesitter would probably be a simpler solution. You can take a look at how the |
Thanks for the comments. I thought about the other options:
|
Checklist
I'm not entirely sure what the existing code's condition is doing. For the following example, where I press
yie
, it givesa* *b
, instead ofb
. If it just matches the pattern closest to the cursor, it works.(
|
shows the cursor position.)Using
vim.fn.abs()
appears to fix this. Does this make sense?Of course, ideally
a* *b
would never be matched as the contents of an emphasis anyway, but I don't think Lua patterns are powerful enough for this.