-
-
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
feat: wrap selection in <tag>
, change surrounding <tag>
and delete surrounding <tag>
#12055
base: master
Are you sure you want to change the base?
feat: wrap selection in <tag>
, change surrounding <tag>
and delete surrounding <tag>
#12055
Conversation
<tag>
, change surrounding <tag>
and delete surrounding <tag>
I don't think the maintainers would accept this in core because it's language-specific. Not 100% sure though. They might make an exception since XML (in particular, HTML) is so ubiquitous. On the other hand, I also see them preferring to work on a snippet manager within Helix building upon #9801. |
I think a generalised one will be more practical, asin |
I feel like it's still worth to add because, as you said - HTML is ubiquitous and it's extremely handy to have such useful tools embedded into the editor like surround selection with tag and delete it For example we have text object support for functions, types etc right in the editor. These are also language agnostic, not all languages have types So I think such generic utilities for working in tags in general will be fitting, but of course it's the maintainers' choice |
what do you mean by generalised? This PR doesn't depend on any sort of parser/language. I haven't used Kakoune |
sidenote: The logic to delete surrounding tag and change surrounding tag ended up being significantly harder than I initially anticipated I managed to get it working though! It took me quite a long time. I'll publish my changes tomorrow It's super fun for me to learn Rust by implementing new features for a project which I love. I'll be happy if it gets merged, because I genuinely think this feature is really useful. but if it doesn't I'll also be happy :). I'm just doing this for fun! Also I learned so much from this, I really fell in love with Rust. I started learning it about a week ago specifically because I wanted to add some features to this project which I myself wish it had: https://github.com/helix-editor/helix/pulls/nikitarevenco |
Ok, so I just pushed all the changes and now all 3 functionalities work as expected! |
Good job, thanks! |
Drafted since I realised there are several edge cases that the current implementation won't be able to cover, and there is some additional work that needs to be done |
Asciinema recording showcase of this feature: https://asciinema.org/a/EVuPLsPJnpPVclGH7dJjhvnrq
This PR was inspired by #11158 which adds text objects for XML, HTML and JSX tags allowing us to:
A popular request is to add the ability to rename tags: #966
It would also be useful to delete surrounding tag, and add a tag around a selection
This PR adds those capabilities by adding
x
under thesurround
operations, since #11158 also usesx
.Change surrounding tag
mrx
opens a prompt prefilled with the name tag surrounding the current selection (e.g.span
).div
, it'll replacespan
->div
)Delete surrounding tag
mdx
deletes the closest opening and closest tag to the cursorAdd surrounding tag
msx
opens a promptdiv
, it'll add a<div></div>
around each selection)Related to #966 and #6682