sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
804 stars 39 forks source link

XML nested comment handling #2454

Open stdedos opened 5 years ago

stdedos commented 5 years ago

Summary

<div>
  <test></test><!-- Comment -->
  <test>foobar</test><!-- Comment -->
  <test>foobar</test><!-- Comment -->
</div>

Expected behavior

  1. Press Comment (Ctrl+/):
    • Expected: (Un)comment whole line
      1. With caret to L2, C# (no selection):
        • Actual: Comment disappears
      2. With caret to L3, C# (no selection):
        • Actual: Invalid XML
          <!-- <test>foobar</test><!-- Comment --> -->
  2. Press Comment (Ctrl+/) to "revert" L2:
    • Expected: Revert line
    • Actual: Line is fully commented
      <!-- <test></test>Comment -->
    • (actual behavior works on L3, even though intermediate text is invalid xml)
  3. Select L4's <test>foobar</test>, Press Comment (Ctrl+/) twice:
    • Expected: No difference
    • Actual: Invalid XML
      <test>foobar</test> --><!-- Comment

Actual behavior

I understand that the nature of XML comments makes this process tricky; so fix it however it feels better

Environment

            .-/+oossssoo+/-.               sntentos@sntentos-precision-t3620 
        `:+ssssssssssssssssss+:`           --------------------------------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 16.04.5 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: Precision Tower 3620 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 4.15.0-36-generic 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 7 days, 5 hours, 31 mins 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 2611 (dpkg), 3 (snap) 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.3.48 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: 1680x1050, 1920x1080, 1920x1080 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: Unity 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Compiz 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: Ambiance 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: Ambiance [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: ubuntu-mono-dark [GTK2/3] 
  +sssssssssdmydMMMMMMMMddddyssssssss+     Terminal: gnome-terminal 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      CPU: Intel i7-7700 (8) @ 4.200GHz 
    .ossssssssssssssssssdMMMNysssso.       GPU: Intel Device 5912 
      -+sssssssssssssssssyyyssss+-         GPU: NVIDIA GeForce GT 640 OEM 
        `:+ssssssssssssssssss+:`           Memory: 18054MiB / 64183MiB 
            .-/+oossssoo+/-.
keith-hall commented 5 years ago

related: https://github.com/SublimeTextIssues/Core/issues/446

justingolden21 commented 3 years ago

Uncommenting in HTML still doesn't work. Example:

<!-- <a class="active tab" data-tab="inventory">
                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
                Inventory
            </a> -->

Uncommenting on the bottom line produces: <!-- </a> --> --> and leaves the rest unchanged.

Uncommenting on the second to bottom line produces:

<!-- <a class="active tab" data-tab="inventory">
                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
                <!-- Inventory -->
            </a> -->

Uncommenting on the second line produces:

<!-- <a class="active tab" data-tab="inventory">
                <!-- <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg> -->
                Inventory
            </a> -->

Uncommenting the top line produces:

<!-- <!-- <a class="active tab" data-tab="inventory"> -->
                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
                Inventory
            </a> -->

All four of these results are invalid...

stdedos commented 3 years ago

A lot of fixing internet knowledge here: https://stackoverflow.com/questions/1324821/nested-comments-in-xml

deathaxe commented 3 years ago

This is what it looks like in ST 4098.

Animation

I need to select the whole <a> tag to comment it, but uncommenting works correctly wherever the caret is located.

stdedos commented 3 years ago

@deathaxe your test is missing the pre-existing comment on said line

(I amended the issue title to reflect that)

justingolden21 commented 3 years ago

Thank you @deathaxe for making the gif, and thanks both for looking into this.

It's probably something about handling inline SVGs in HTML would be my guess.

deathaxe commented 3 years ago

Which pre-existing comment is missing on which said line? The comment starts with the whole <a ... </a> commented out, which is what I did, too. Than commenting it in with the caret located at different lines, which is said to not work, but actually does with ST 4098. What do I miss?

Once the whole block is commented in, triggereing "comment line" comments out the current line (only), if nothing is selected. How should it know how many lines to comment out otherwise?

Anyway, the issue described by @justingolden21 is different from the inititial issue comment, which is about commenting out lines which contain comments.

The only solution I'd see is to comment out text before the first punctuation.comment.begin only.

  <test>foobar</test><!-- Comment -->

becomes

  <!--<test>foobar</test>--><!-- Comment -->