Change how selection/caret location is determined after applying togg…#51411
Change how selection/caret location is determined after applying togg…#51411dibarbet wants to merge 3 commits intodotnet:mainfrom
Conversation
594f9b3 to
51b2239
Compare
I use the Insert Comment and Remove Comment commands, not the Toggle Comment command
| var caretColumn = caretLine.GetColumnFromLineOffset(caretOffset, editorOptions); | ||
|
|
||
| var nextLine = selectedSpan.Snapshot.GetLineFromLineNumber(nextLineNumber); | ||
| // Compute the correct offset location from the column in the previous line. |
There was a problem hiding this comment.
a super nit (you don't have to take this lol, I personally just think it looks a little cleaner with the newline):
| // Compute the correct offset location from the column in the previous line. | |
| // Compute the correct offset location from the column in the previous line. |
| } | ||
|
|
||
| // In selection or any multi-caret scenarios, leave the selection unchanged. | ||
| return new CommentTrackingSpan(selectedSpan.Span.ToTextSpan()); |
There was a problem hiding this comment.
can we invert the check so the simple case comes first :)
|
How confident are we that this won't piss people off? :) the 'keep selection the same' part seems fine to me. The 'move to next line' seems odd. Is this parity with another editor? |
It's a fair question. The original design review outcome is here - #36351 (comment) We decided to take this specifically without an option. I don't recall the exact discussion since it's been a while, but the points in favor of this are
As such I would rather introduce this change and revisit with an option if we do get feedback later on. |
|
Not sure how I feel about this:
|
|
I think we could separate this into two prs. Take the selection part immediately. Discuss the newline decision with vscode. I'd rather us be consistent on this. |
|
@CyrusNajmabadi sure- I created #51493 for leaving the selection unchanged. I will rebase this PR on it once it merges. Could you take a look at that one? |
|
Thanks for fixing the selection issue. Regarding the move-line-down, an option would be cool, but if you had to make a choice, moving down a line is the more logical choice as moving to the next line is the more common next-action. VSCode should probably consider updating to the move-line-down behaviour. |
This was reviewed and decided upon back in 2019. Here is the relevant post. "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." "We do not want to add a new options for this." |
To be clear, this should apply to all lines included in the selection (except where caret posn = 0). So if it's a MULTI-LINE selection and the user applies ToogleLineComment, every line should have line comment applied or removed, but the selection will be unchanged - spanning multiple lines.
Edit: |
|
In the case where the selection starts at the first char on a line, the selection changes to include the comment markers at the start. This is not expected behaviour and is inconsistent with the idea of not changing the selection. As an example, if the start of the selection was one more char to the right, it would not include the comment makers. The problem stems from adding comment markers mid-line. If comment markers always go at the beginning of the line, which they might as well, then it's easy to achieve consistency with comment behavior. Will consider raising new issue to apply comment markers to the start of each line. |
|
I personally like the move down a line behavior now that I've tried as well. I'm also not sure that unifying behavior here is 100% necessary - I don't know if users moving from VSCode have a strong expectation that VS functions exactly the same. In so many other ways they already differ. I would lean towards just doing what we decided previously in design review, though I can bring it up again if others are strongly against this. |
|
Agreed. VSCode already has a very different set of features and shortcuts. And definitely go with default move-line-down behaviour in the case of zero-length selection. :-D |
…le line comment
Two main changes in this PR:
Resolves #36349
Resolves #36351