Repository navigation
feat: Toggle comments on the selected lines with Ctrl+/ - #2882
Merged
Merged
Conversation
scottanderson
force-pushed
the
editor-toggle-comment
branch
2 times, most recently
from
September 8, 2026 06:59
af567cc to
cb2f707
Compare
Owner
|
This one is for you @paxcut |
scottanderson
force-pushed
the
editor-toggle-comment
branch
3 times, most recently
from
September 23, 2026 08:04
8dae879 to
7a2ac7c
Compare
Ctrl+/ comments or uncomments the selected lines, or the line of the cursor. It uncomments only if all lines with text have a comment. It skips blank lines. It gets the token from the language definition and puts it at the smallest indent. One undo reverts all lines.
scottanderson
force-pushed
the
editor-toggle-comment
branch
from
September 24, 2026 03:56
7a2ac7c to
9e9c06b
Compare
paxcut
reviewed
Sep 28, 2026
paxcut
reviewed
Sep 28, 2026
The comment toggle belongs with the other text editor code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem description
Comments or uncomments every line the selection touches, or the cursor's own line when nothing is selected.
Implementation description
Uncomments only when every line with text on it is already commented. A partly commented run becomes wholly commented, which one more press then clears. A blank line takes no token and does not decide the direction. The token goes at the shallowest indent in the run, so the block keeps its shape.
Additional things
The token comes from the language definition, not from a hard coded "//", so the shortcut does nothing in a language that declares none.
Put the text rule in a new header, ui/line_comment.hpp, so it can be tested on its own. TextEditor::toggleLineComment() only reads the lines, calls it, and writes the result back as one undo record, the same shape doPaste() builds. A single Ctrl+Z therefore takes the comment back off every line at once.