-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add textobjects for XML, HTML and jsx #11158
base: master
Are you sure you want to change the base?
Conversation
feb505b
to
a5b50d1
Compare
Awesome work, thanks! Can anything be done about HTML tags that don't have closing tags ("void elements" like <div class="flex flex-col items-center">
<input
placeholder="Enter your email"
type="email"
name="EMAIL"
class="required email mb-4 p-2 border border-gray-300 rounded"
id="mce-EMAIL"
required=""
value=""
/>
<input
type="submit"
name="subscribe"
id="mc-embedded-subscribe"
class="button bg-blue-500 hover:bg-blue-600 text-white rounded py-2 px-4"
value="Subscribe"
/>
</div>
|
runtime/queries/jsx/textobjects.scm
Outdated
|
||
(jsx_element (jsx_opening_element) (_)* @xml_element.inside (jsx_closing_element)) | ||
|
||
(jsx_element) @xml_element.around |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to runtime/queries/_jsx/textobjects.scm
instead so that both jsx
and tsx
can inherit it? The file doesn't exist yet, but I tried it locally and it seems to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I've moved it
@David-Else thanks for the feedback and @david-crespo thanks for your well illustrated point! The current implementation is consistent with other textobjects. See for example the function textobject with nested functions below, where I completely agree that the behaviour of the vim tag-textobject is more intuitive, but changing this is not possible in the textobject definition itself AFAIK. We would have to change the way helix handles the textobjects and this is a change that requires more rust knowledge than I currently have and would change this PR from a pretty minimal enhancement into something that requires a lot more discussion with the core team. This is why I tried to keep the PR simple, because a more wide reaching PR for the same problem went nowhere in the past. Starting Position
|
Wise! Cool with me, it’s a great start. |
@Ansimorph OK, if what I described are not bugs then this is fantastic anyway, and I hope it gets merged ASAP. |
2c82769
to
f317d55
Compare
Building on the work done by @ff2400t this adds text-objects to select xml-like elements in html, jsx and xml files.
Fixes: #6682
The behaviour is consistent with other text-objects in helix. It is however not consistent with vim's tag textobject:
If the cursor is on
<span>
vit
would selectinner_span
in vim.In Helix
mix
will select<span> inner_span </span>
If the cursor is actually inside the tag, both solutions work the same.
I think despite the difference to vim this textobject is very useful and would love to see it in my daily work.