helix
helix copied to clipboard
textobjects for html/xml tags
I bundled the html and jsx queries with this pr to show how it work in practice
mae - will select the element and all it's child element, this is can also be used to select self closing element like we see in jsx
mie - will select the all the child nodes of an element
Please do not change the behavior of t as it's probably part of muscle memory for multiple people already (myself included).
If e is available, maybe use that instead as element?
Yeah I don't see a compelling reason for a breaking change here: more languages have queryable test conventions than XML tags. We could use T for xml tags?
There are also the navigation commands ]e/[e to add: https://github.com/helix-editor/helix/blob/0c08ff1596b398d53c8c48cc96cfbd24ddec303b/helix-term/src/keymap/default.rs#L100-L121
Thanks so much for this PR!
I tested the changes (rebased the current main) and it works reliably for around-queries.
For inside-queries it works when the cursor is already on the content nested in a tag.
When the cursor is resting on an html attribute such as class="sr-only", mie selects nothing.
When the cursor rests on the tag name of a closing tag, mie selects the tag name itself.
I would expect the element the cursor is in to be the context the selection is applied to:
<section>
<p [CURSOR] class="sr-only"> text </p>
</section>
mie selects text
mae selects <p class="sr-only"> text </p>
Currently only mae works that way
The mei queries still don't work as I want them to.
<section>
<p [CURSOR] class="sr-only"> text </p>
</section>
It would be ideal in the above case for mei to select the text inside the paragraph element. But for now it selects the whole paragraph element.
Hopefully someone who understand treesitter queries can help in that.
Furthermore, i think it would be great if the Text selection is trimmed of whitespace by default but that should be part of another PR
So in the end i had to modify how textobjects are captured from rust to capture the element.inner as intended. This is also how nvim-treesitter-textobjects does the capture for these too. Hopefully some with better knowledge of rust can help me remove the extra QueryCursor allocation.
closing this one out as stale, thank you for contributing!