Home Download Buy Blog Forum Support

"Toggle comment" doesn't work correctly in HTML

"Toggle comment" doesn't work correctly in HTML

Postby callum on Mon Feb 11, 2013 1:24 pm

Take the following HTML:

Code: Select all
    <script src="console.js"></script>
    <script src="lodash.js"></script>
    <script src="application.js"></script>

Let's say you want to disable one of the scripts temporarily. So you click your cursor on (or next to) the relevant script tag, and press CMD+/ or CTRL+/.

Expected result:

Code: Select all
    <script src="console.js"></script>
    <script src="lodash.js"></script>
    <!-- <script src="application.js"></script> -->

Actual result:

Code: Select all
    <script src="scripts/safe-console.js"></script>
    <script src="scripts/lodash.js"></script>
    // <script src="scripts/application.js"></script>

(This happens no matter where on the line you put your cursor – even if you put it right at the beginning of the line, before the indentation.)

The same bug happens with <style> tags, except it uses CSS comment syntax instead, e.g. <style>body{color:blue}</style> becomes /*<style>body{color:blue}</style>*/.

This bug has existed for as long as I have been using Sublime Text, and it still exists in ST3 (build 3012).

This bug is really annoying, because toggling individual script tags on and off is probably the most common use case for HTML comments when working on large JavaScript codebases (for me, anyway), and HTML's comment syntax is particularly fiddly to type manually.
callum
 
Posts: 2
Joined: Fri Dec 09, 2011 6:24 pm

Re: "Toggle comment" doesn't work correctly in HTML

Postby FragOnly on Mon Feb 11, 2013 2:09 pm

This isn't a fix for commenting but it might help in the short term to quickly disable a script. If you double tap CTRL + / it should do the following:

Original:
Code: Select all
<script type="text/javascript"></script>


After the first CTRL + /
Code: Select all
// <script type="text/javascript"></script>


After the second CTRL + /
Code: Select all
<!-- // <script type="text/javascript"></script> -->


From this point on it seems like it just toggles the HTML comment.
FragOnly
 
Posts: 19
Joined: Sat Feb 09, 2013 12:50 pm

Re: "Toggle comment" doesn't work correctly in HTML

Postby ajjusto on Thu Jul 11, 2013 1:52 pm

Another work around is to select the line, CTR/CMD + X to cut it, CTR/CMD + / to insert comment tags, and CTR/CMD + V to paste it.
ajjusto
 
Posts: 1
Joined: Thu Jul 11, 2013 1:48 pm

Re: "Toggle comment" doesn't work correctly in HTML

Postby johnmorales on Mon Jul 22, 2013 9:19 pm

cut and paste works as a workaround but this should truly be fixed. It's annoying.
johnmorales
 
Posts: 1
Joined: Mon Jul 22, 2013 9:17 pm

Re: "Toggle comment" doesn't work correctly in HTML

Postby skuroda on Tue Jul 23, 2013 3:49 am

ST has trouble with nested languages. The comment applied to a particular line is based on the scopes at the cursor.

For example, given the following (with no leading spaces)

Code: Select all
<script src="scripts/application.js"></script>


Placing the cursor at the beginning of the string has the following scope.

Code: Select all
text.html.basic meta.tag.any.html punctuation.definition.tag.begin.html


Now, insert a leading space then again place the cursor at the beginning of the line. It now has the following scope

Code: Select all
text.html.basic source.js.embedded.html


I'm not saying it's not bothersome, but I think it's worthwhile to understand why it "doesn't work correctly". You could try playing with the tmLanguage files to get things to work a little better, but that's a pretty significant undertaking I think.
skuroda
 
Posts: 690
Joined: Fri Oct 05, 2012 8:11 am

Re: "Toggle comment" doesn't work correctly in HTML

Postby cotne.nazarashvili on Sat Dec 14, 2013 10:27 am

i modified portable version and fixed bug
in HTML.tmLanguage on line 286 i replaced this
<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string>
with this
<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)(?!.*&lt;/script&gt;)</string>

this version also have bugs on commenting but its much better then original

link on modified portable version (win32) https://docs.google.com/file/d/0B1gBa3_5Y2mBa2tDX0g4N25IdkE
cotne.nazarashvili
 
Posts: 1
Joined: Sat Dec 14, 2013 10:15 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 28 guests