Repository navigation
Toggle line comments with Ctrl+/ in the editor - #278
Merged
Merged
Conversation
henrylee1003
force-pushed
the
toggle-line-comment
branch
from
October 11, 2026 12:06
463db08 to
a5b32ec
Compare
ColtenOuO
reviewed
Oct 11, 2026
henrylee1003
force-pushed
the
toggle-line-comment
branch
from
October 12, 2026 04:02
a5b32ec to
a656b36
Compare
A candidate debugging during the Test step disables a few lines, runs the tests and brings them back, and the editor made that a marker typed and deleted by hand on every line while the clock ran. Ctrl+/ and Cmd+/ now do it in one edit that one undo takes back. The chord is matched on the typed character rather than the key position, which costs nothing on a US layout and leaves Ctrl with that key alone where it types a hyphen and means zoom. The shortcut is always on rather than an editor option, since it does nothing until it is pressed. Closes sysprog21#273
henrylee1003
force-pushed
the
toggle-line-comment
branch
from
October 12, 2026 04:24
a656b36 to
47e3458
Compare
Contributor
|
Thank @henrylee1003 for contributing! |
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.
The code editor had no way to comment lines out except typing
#or//on each one by hand, which is what a candidate ends up doing while debugging in the Test step with the clock running.Ctrl+/andCmd+/now toggle a line comment on the current line or on every line the selection touches.Before, with three lines selected, the chord did nothing. After,
a = 1/b = 2/c = 3becomes# a = 1/# b = 2/# c = 3, and pressing it again restores the text and the selection. The marker is#in the Python tab and//in the others, goes in at the block's shallowest indentation, and skips blank lines. A block is uncommented only when every non-blank line in it is already a comment, so a block holding one commented line gains a level instead of losing that line's.Two choices a reviewer may want to weigh. The chord is matched on
event.key === "/"rather thanevent.code, because the key in that position types-on a German layout andCtrlwith it is the browser's zoom. And the shortcut is always on rather than a sixth editor option beside the ones from #252, since it changes nothing until it is pressed; I am glad to gate it if that is preferred.The edit goes through
applyEditorEdit, the same pathTabuses, so it is oneinputevent, onecode_updateand one undo step.toggleLineCommentis a pure function inweb/editor.jsand reads its marker fromlineCommentForinweb/tokenizer.js, so the two cannot disagree;indentSelectionis not touched.Validation, on Windows 11 with Node 24:
node --test tests/browser/editor.test.js: 57 pass, 0 fail (11 new cases).node --test tests/browser/comment-shortcut.test.js: 5 pass, in Chromium through Playwright.All of
tests/browser/*.test.js, two files at a time: 1049 pass, 10 skipped, 6 fail. The six are outside this change: five fail only on Windows (four on ac:import path, one on an empty URL inface-detector.test.js), anddisabled auto indentation retains parsed bracket highlightingfails intermittently here on a cleanmainas well.ESLint and Prettier clean on the changed files; the pre-commit and commit-msg hooks passed.
Each new behavior was broken on purpose and the tests watched to fail: five mutations of
toggleLineCommentandisToggleCommentKeystroke, and four of thekeydownbranch (never taken, language fixed to Python,preventDefaultdropped, value assigned instead ofapplyEditorEdit).A live interview, served by the
latestrelease binary (codetrial 0.1.0 (6d556b7)) started with--web-dirpointing at this branch'sweb/: the chord commented and uncommented the selected lines in the editor.Not run locally:
./scripts/test.shas a whole, because this machine has no Rust toolchain, so the Rust lanes are left to CI. Running all oftests/browser/*.test.jsin parallel here timed out in many files, mine included, and passed when the same files ran one at a time; I did not run a cleanmainfor comparison. Nothing undersrc/changed.Before and after in that live session, cropped to the editor:



Closes #273
Summary by cubic
Adds
Ctrl+/andCmd+/to toggle a line comment on the current line or on every line the selection touches, so candidates debugging during the Test step no longer have to type#or//by hand. The marker is#in the Python tab and//in the others, goes in at the block's shallowest indentation, skips blank lines, and a block is uncommented only when every non-blank line in it is already a comment. Each toggle is oneinputevent, onecode_update, and one undo step; a held chord toggles once instead of flipping with each repeat.The shortcut is always on rather than an editor option, and it matches on the typed character rather than key position, so
Ctrlwith a key that types-on a German layout still works as the browser's zoom. Closes #273.Written for commit 47e3458. Summary will update on new commits.