Skip to content

Preserve existing comments when toggling a code block #571

Description

@twelve-cgn

When commenting out a block of XAML/XML that already contains comments, the existing comments are currently modified and are not correctly restored when the block is uncommented.

I think this could be solved by temporarily escaping existing comments inside the selected block.

Example

Starting with:

<Grid>
    <!-- This is an important comment -->
    <Label Text="Test" />
</Grid>

Commenting the block could temporarily transform the existing comment:

<Grid>
    <!~~ This is an important comment ~~>
    <Label Text="Test" />
</Grid>

and then wrap the entire block:

<!--
<Grid>
    <!~~ This is an important comment ~~>
    <Label Text="Test" />
</Grid>
-->

When uncommenting, the outer comment is removed and the escaped comment is restored:

<Grid>
    <!-- This is an important comment -->
    <Label Text="Test" />
</Grid>

Supporting multiple levels

It would be even better if this mechanism supported multiple consecutive Comment operations.

For example:

Original:
<!-- Comment -->

Comment:
<!~~ Comment ~~>

Comment again:
<!~~~ Comment ~~~>

Comment again:
<!~~~~ Comment ~~~~>

Each Uncomment operation would then remove exactly one level:

<!~~~~ Comment ~~~~>
        ↓ Uncomment
<!~~~ Comment ~~~>
        ↓ Uncomment
<!~~ Comment ~~>
        ↓ Uncomment
<!-- Comment -->

This would make the Comment/Uncomment operation fully reversible, even when the same block is commented out multiple times.

The exact escape characters are just a suggestion. The important part is that existing comments are treated as nested comments and that each Comment/Uncomment operation changes exactly one nesting level.

Expected behavior

The fundamental requirement would be:

Every Comment operation adds one level, and every Uncomment operation removes exactly one level.

Existing comments inside the selected block must not be lost or converted into plain text.

This would be especially useful for XAML/XML, where comments are commonly present inside larger blocks that developers temporarily disable during development.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions