editor: Fix toggle comment on HTML closing tags#53153
Conversation
The toggle_comments function would just consider the language at selection.start. Since the </style> or </script> where commented, the language at selection.start would be either css or js, which would result in wrapping the <!-- </style> --> inside css comments (/* <!-- </style> --> */) instead of removing the HTML comments (</style>). Now it takes into account the comment tokens from both neighbor languages, strips them (if they exist) and uses the language inside. Fixes zed-industries#52001
|
Hi @dinocosta could you check in on this PR when you have a moment? I wanted to see if there’s any additional feedback or changes needed from my side. Happy to make updates as required. Thanks! |
Hey @rodrigotx21 ! 👋 I’ve reassigned this from Antonio to myself, since he’s likely busy with other projects and may not be able to review these changes soon. I’m also trying to go through the PRs assigned to me in the order they were created, so it might take a bit before I get to this one, as I currently have quite a few in my queue (https://github.com/zed-industries/zed/pulls/assigned/dinocosta) 😅 Rest assured we’ll get to these changes. Thanks again for working on this! |
There was a problem hiding this comment.
Hey @rodrigotx21 👋
Thank you so much for trying to tackle this one! I've just tested and reviewed your changes and I believe there's some points we could still improve on:
-
The fix seems a little bit brittle as the bug can still be easily reproducible. For example, if you have and already commented out tag, like
<!--</style>-->and you place the cursor in the!character, usingeditor: toggle commentswill add a CSS comment instead. Here's a quick screen recording:CleanShot.2026-04-23.at.15.30.51.mp4
Notice how any use of
cmd-/(editor: toggle comments) before the tag, but still in the comment, leads to a CSS comment being created. -
The
target_columnlogic is complex enough that, I believe, it benefits from documentation. I'd probably remove the comments in the tests, as it's pretty straightforward to understand what is happening and, instead, add comments explaining what's happening intarget_columnand why.
Once again, thank you for trying to tackle this, and let me know if you need help! 🙂
P.S.: Feel free to also add a release note as we'll need that in order to merge this and be able to credit you in the release notes! 🎉
|
Hi Dino, I will look into this as soon as possible! Thanks for the feedback! |
dinocosta
left a comment
There was a problem hiding this comment.
Hey @rodrigotx21 👋
I'm going to close this Pull Request since it's been more or less a month since our last interaction. Feel free to reach out, and ask any questions, in case you're still interested in seeing this one through. Thanks! 🙂
Summary
The toggle_comments function would just consider the language at
selection.start. Since the</style>or</script>were commented, the language at selection.start would be either css or js, which would result in wrapping the<!-- </style> -->inside css comments (/* <!-- </style> --> */) instead of removing the HTML comments (</style>).Now it takes into account the comment tokens from both neighbor languages, strips them (if they exist) and uses the language inside.
I've added tests to assert this behaviour
Self-Review Checklist:
Closes #52001
Release Notes: