When user applies ToggleLineComment with no selection, it is very useful to have the caret move down one line, so the user can apply the command repeatedly.
If needed, this could be a setting in Tools->Options (on by default).
(See #27198)
Want to make sure the request is clear.
The current behavior looks like this.
Note - caret position indicated by $$
class Program
{
void M()
{
string so$$meVar = "hello";
}
}
Toggle line comment is invoked, resulting in this with the entire line selected (indicated by [| |]).
class Program
{
void M()
{
[| //string someVar = "hello";|]
}
}
Is the request to instead remove the selection, and place the caret at the beginning of the next line (in this case, the closing bracket }
)?
Yes, exactly.
The principle being: There was no selection before triggering it. There should be no selection afterwards.
All that happens is that the current line gets "//" added or removed at the beginning, and the caret position moves down one line.
I think this one also breaks the 'toggle' behavior. This is on purpose though as the idea is that one can just keep commenting out (or uncommenting out) lines going down the document.
I personally definitely wouldn't want this, but I can understand the utility. Marking for design review to answer
I overlooked a comment you made about the caret moving to the beginning of the line. The caret should not move to the beginning; it should stay at the same column and simply move down one line.
Yes, it breaks the "toggle" feature - deliberately.
The ability to comment/uncomment as you go is a real winner of a feature - even if it's not one you might use. I've used it for over ten years and it improves productivity.
When making decisions, please consider which is the more common scenario.
A. User wants to comment, then immediately uncomment a single line.
B. User wants to comment/uncomment a line then immediately do the same to the next line?
Case A is usually just an accident.
Case B is incredibly common. Without the "move down" feature, users either do twice the keystrokes, or they must first pre-select the rows then apply the command. Pre-selecting is at least one keystroke longer, but worse, it forces additional cognitive load, and also, it's a real pain when you need to skip one line in a block.
Just to add my two cents to this: I've been using Justin's HotCommands extension (which implements a toggle comment command the way he's described) for several months and I was surprised by how much of a productivity boost it turned out to be. This is definitely my preferred way to comment and uncomment code. The only time I select several lines to toggle the comment is when I am working with more than 8-10 lines. Otherwise it's faster to have the carat at the top line then press Ctrl+/ repeatedly until all lines are toggled.
I forgot to update this!
We took this one for design review on Monday. We agree that this functionality would be good, and we would accept a PR that would move the caret down to the next line when the toggle line comment command is invoked on a caret location. The caret location on the next line would either be the same column, or the end of the line if the column is past the last character on that line. (same as using the down arrow)
e.g, if the caret is at $$
, the caret would move to down to immediately follow the closing }
int M()
{
retur$$n 1;
}
We do not want to add a new options for this.
That's fantastic. 鈽猴笍
Thank you. I'm sure users will find the experience to be an excellent productivity boost.
Now... What do we need to do to get this onto the Ctrl+/ shortcut?
Is there already a bug for that?
Now... What do we need to do to get this onto the Ctrl+/ shortcut?
Is there already a bug for that?
I don't believe there is currently an open bug for that. Ctrl + / was the initial goal, but I believe that shortcut was already in-use for something in some language. I don't quite recall what.
@mikadumont do you happen to recall?
For now it could be valuable to open a new bug for that to help us gauge the priority to see if it is worth re-shuffling commands.
It's bound to Tools.GoToCommandLine at the global scope. But that command does nothing in VS2919, so it doesn't need the shortcut.
Is there some other command using the Ctrl+/ binding? (On the Global or Text Editor scope)
New issue opened: #37358
Most helpful comment
I forgot to update this!
We took this one for design review on Monday. We agree that this functionality would be good, and we would accept a PR that would move the caret down to the next line when the toggle line comment command is invoked on a caret location. The caret location on the next line would either be the same column, or the end of the line if the column is past the last character on that line. (same as using the down arrow)
e.g, if the caret is at
$$
, the caret would move to down to immediately follow the closing}
We do not want to add a new options for this.