Skip to content

editor: Fix toggle comment on HTML closing tags#53153

Closed
rodrigotx21 wants to merge 1 commit into
zed-industries:mainfrom
rodrigotx21:fix-toggle-comment-on-html-closing-tag
Closed

editor: Fix toggle comment on HTML closing tags#53153
rodrigotx21 wants to merge 1 commit into
zed-industries:mainfrom
rodrigotx21:fix-toggle-comment-on-html-closing-tag

Conversation

@rodrigotx21
Copy link
Copy Markdown

@rodrigotx21 rodrigotx21 commented Apr 4, 2026

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:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #52001

Release Notes:

  • N/A

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
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 4, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 4, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, as-cii and dinocosta and removed request for a team April 4, 2026 16:08
@maxdeviant maxdeviant changed the title editor: fix toggle comment on HTML closing tags editor: Fix toggle comment on HTML closing tags Apr 4, 2026
@rodrigotx21
Copy link
Copy Markdown
Author

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!

@dinocosta dinocosta assigned dinocosta and unassigned as-cii Apr 13, 2026
@dinocosta
Copy link
Copy Markdown
Member

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!

Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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, using editor: toggle comments will 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.

  2. The target_column logic 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 in target_column and 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! 🎉

@rodrigotx21
Copy link
Copy Markdown
Author

Hi Dino,

I will look into this as soon as possible!

Thanks for the feedback!

Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! 🙂

@dinocosta dinocosta closed this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toggle comment on </style> in HTML wraps with CSS comment instead of uncommenting

4 participants