- AuthorPosts
- January 10, 2013 at 5:49 pm #10741ArthurZParticipant
I am thinking why not allowing commenting a line of code where the cursor currently is on?
Right now the Comment/Uncomment functionality becomes enabled only when line(s) are selected and this is small but un-needed limitation IMO.
January 11, 2013 at 3:27 am #10746Yutaka EmuraKeymasterHello,
Since these commands are in the “Convert Selection” sub menu of the Edit menu, I wanted to make them work same as other commands in the same sub menu. If I allowed these commands to work when unselected, I would have to allow all other commands to work when unselected.
Thanks for your inputs!
January 11, 2013 at 3:27 pm #10751ArthurZParticipantI see, but in my case I placed the Comment-Uncomment pair onto the toolbar.
Therefore IMHO, this limitation should not be in this case.
PS: This useful command (I use very often) is buried too deep in the menus, I suggest to elevate it.
January 11, 2013 at 5:47 pm #10753Yutaka EmuraKeymasterHello,
How about a macro like this:
[JavaScript]
if( document.selection.IsEmpty ){
editor.ExecuteCommandByID(4154);
}
editor.ExecuteCommandByID(4371);This macro will comment out the selection if the selections exists, or comment the current line if the selection does not exist.
Thanks!
January 11, 2013 at 6:27 pm #10754ArthurZParticipantProbably you meant it will comment in either case. At least the code does this. And I think it would be nice to enhance the functionality so if the comment is already there – uncomment – thus toggling the comments on/off.
January 13, 2013 at 5:49 pm #10760Yutaka EmuraKeymasterYou are right; the above code was to comment in all cases.
To toggle the comment, it will a little more complicated. To uncomment in all cases, here is the code:
if( document.selection.IsEmpty ){
editor.ExecuteCommandByID(4154);
}
editor.ExecuteCommandByID(4372);Thanks!
January 14, 2013 at 1:59 am #10763ArthurZParticipantNot quite there, but the following variation is almost what I need, how to un-select a line?
if( document.selection.IsEmpty )
{
// highlight select and comment
editor.ExecuteCommandByID(4154); editor.ExecuteCommandByID(4371);
}
else
{
// uncomment
editor.ExecuteCommandByID(4372);
}
January 14, 2013 at 9:27 am #10764MeirParticipantHi!
IMHO this macro just UN-comments an already commented-out text. It didn’t comment out any un-commented one, or am I missing something?
January 14, 2013 at 2:33 pm #10766ArthurZParticipantHello Meir,
It highlights and comments out a line of code (even if it was commented out already). You need to just position the cursor within the line.
While the cursor is still on the same (just commented) line it un-comments it.
January 15, 2013 at 12:35 pm #10767MeirParticipantDear Arthur,
I agree with you, but when one or more lines are SELECTED, nothing happens! No commenting-out!
Is this last behavior planned? If so, what should I add to have it comment out a bunch of selected lines?
January 15, 2013 at 3:42 pm #10768ArthurZParticipantHello Meir,
Yes, the macro is designed to work on a single line of unselected text.
This is because in the rest of the situations we have the right-click -> Convert Selection > Comment/Uncomment functionality or you can pull these two buttons onto the toolbar.
Agin, the latter just does not work for a single un-highlighted line of code – hence the macro.I must add, this creates some uncomfort for me – split, non-unified functionality :hammer: .
Hope Yutaka is listening: I suggest a change to allow commenting code regardless of whether a line is highlighted/selected.
January 15, 2013 at 4:20 pm #10769MeirParticipantThanks Arthur,
OK…
Hmmm! IMHO, the most desirable functionality is a single, toggle command which can be assigned a keyboard shortcut, working on the current line if none is selected or on all selected lines is. If any of these are already commented out, uncomment it!
Toggle, because obviously if it is already commented out, why would you want to comment it out again? Also in the opposite direction.
Yes I am sure Yutaka is listening. He always does, and that is not the least reason that I am using EE :-)
January 15, 2013 at 4:47 pm #10770ArthurZParticipantMy both thumbs are up for the proposed!
By the way your rephrase Meir: “Toggle” is the word and the way to go.
January 17, 2013 at 9:11 pm #10772JohnQSmithParticipantHmmm! IMHO, the most desirable functionality is a single, toggle command which can be assigned a keyboard shortcut, working on the current line if none is selected or on all selected lines is. If any of these are already commented out, uncomment it!
Toggle, because obviously if it is already commented out, why would you want to comment it out again?
Because the code I’m editing already has comments that I want to keep. For example,
...
for(int i=0;i<10;i++) {
// the following line prints incremented variable
printf("\%d",i);
}
...Using your idea, if I wanted to comment out that loop, I’d end up with
...
//for(int i=0;i<10;i++) {
the following line prints incremented variable
// printf("\%d",i);
//}
...which would be wrong. :-(
If I comment out that block, it should add additional comments on previously commented lines like
...
//for(int i=0;i<10;i++) {
//// the following line prints incremented variable
// printf("\%d",i);
//}
...that way when I later uncomment it, it will be back the way it was when I started.
October 8, 2014 at 12:34 pm #19416QiaoJiaoParticipantSweet and simple (actually, totally based on Emura code with my brute force comment check).
I assigned it to ctrl+qif( document.selection.IsEmpty ) { editor.ExecuteCommandByID(4154); // select // if line has comment sign if ( document.selection.Text.substring(0,2) == '//' ) { // change to (0,1) and '#' if you use # editor.ExecuteCommandByID(4372); // uncomment } else { editor.ExecuteCommandByID(4371); // comment } document.selection.Collapse(); // unselect }
November 15, 2014 at 3:35 am #19626QiaoJiaoParticipantShame on me, it was included in on of the new version.
- AuthorPosts
- You must be logged in to reply to this topic.