Skip to content

feat: Toggle comments on the selected lines with Ctrl+/ - #2882

Merged
paxcut merged 2 commits into
WerWolv:masterfrom
scottanderson:editor-toggle-comment
Sep 29, 2026
Merged

paxcut merged 2 commits into
WerWolv:masterfrom
scottanderson:editor-toggle-comment

Conversation

@scottanderson

Copy link
Copy Markdown
Contributor

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.

@scottanderson
scottanderson force-pushed the editor-toggle-comment branch 2 times, most recently from af567cc to cb2f707 Compare September 8, 2026 06:59
@WerWolv

WerWolv commented Sep 9, 2026

Copy link
Copy Markdown
Owner

This one is for you @paxcut

@WerWolv
WerWolv requested a review from paxcut September 9, 2026 19:42
@scottanderson
scottanderson force-pushed the editor-toggle-comment branch 3 times, most recently from 8dae879 to 7a2ac7c Compare September 23, 2026 08:04
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.
Comment thread plugins/ui/source/ui/text_editor/line_comment.cpp
Comment thread plugins/ui/CMakeLists.txt Outdated
The comment toggle belongs with the other text editor code.
@paxcut
paxcut merged commit f2d432d into WerWolv:master Sep 29, 2026
22 checks passed
@scottanderson
scottanderson deleted the editor-toggle-comment branch September 29, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants