Skip to content
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

[JSX] Improve commenting behavior. #2787

Merged
merged 2 commits into from Apr 29, 2021

Conversation

Thom1729
Copy link
Collaborator

@Thom1729 Thom1729 commented Apr 12, 2021

Should fix #2461.

Given the following:

<foo>
    bar!
</foo>;

The toggle_comment command will comment the second line as follows:

<foo>
    {/*bar!*/}
</foo>;

But when you call it again to uncomment, you get:

<foo>
    {bar!}
</foo>;

…instead of the original, which we want. This is due to internal implementation details of toggle_comment — it won't remove {/*/*/}, even though they're specified in JSX Comments.tmPreferences, because the comment scope doesn't extend to the braces.

This PR adds a special case to JSX interpolations so that when an interpolation contains only a single block comment, the entire interpolation including the braces will get the comment scope, so that the toggle_comment command will do what we want. This is not really the correct scoping, but the previous behavior is really annoying and we can't really change toggle_comment.

In addition, this PR improves the behavior of commenting attributes. E.g.:

<Foo
  bar={42}
/>

…will become:

<Foo
  // bar={42}
/>

@Thom1729
Copy link
Collaborator Author

I've simplified the comments file substantially, but they should behave the same.

Note that there are still some broken corner cases due to sublimehq/sublime_text#2152.

@wbond wbond merged commit 271f6cf into sublimehq:master Apr 29, 2021
@Thom1729 Thom1729 deleted the jsx-better-comments branch May 4, 2021 16:22
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
* [JSX] Improve commenting behavior.

* [JSX] Simplify comments files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JSX] Comment not working in HTML content
2 participants