Skip to content

Toggle line comments with Ctrl+/ in the editor - #278

Merged
jserv merged 1 commit into
sysprog21:mainfrom
henrylee1003:toggle-line-comment
Oct 12, 2026
Merged

jserv merged 1 commit into
sysprog21:mainfrom
henrylee1003:toggle-line-comment

Conversation

@henrylee1003

@henrylee1003 henrylee1003 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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+/ and Cmd+/ 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 = 3 becomes # 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 than event.code, because the key in that position types - on a German layout and Ctrl with 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 path Tab uses, so it is one input event, one code_update and one undo step. toggleLineComment is a pure function in web/editor.js and reads its marker from lineCommentFor in web/tokenizer.js, so the two cannot disagree; indentSelection is 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 a c: import path, one on an empty URL in face-detector.test.js), and disabled auto indentation retains parsed bracket highlighting fails intermittently here on a clean main as 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 toggleLineComment and isToggleCommentKeystroke, and four of the keydown branch (never taken, language fixed to Python, preventDefault dropped, value assigned instead of applyEditorEdit).

  • A live interview, served by the latest release binary (codetrial 0.1.0 (6d556b7)) started with --web-dir pointing at this branch's web/: the chord commented and uncommented the selected lines in the editor.

Not run locally: ./scripts/test.sh as a whole, because this machine has no Rust toolchain, so the Rust lanes are left to CI. Running all of tests/browser/*.test.js in 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 clean main for comparison. Nothing under src/ changed.

Before and after in that live session, cropped to the editor:
image
image
image

Closes #273


Summary by cubic

Adds Ctrl+/ and Cmd+/ 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 one input event, one code_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 Ctrl with 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.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv
jserv requested review from ColtenOuO and alanhc October 11, 2026 13:46
Comment thread web/editor.js Outdated
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
@jserv
jserv requested a review from ColtenOuO October 12, 2026 04:56

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ColtenOuO
ColtenOuO requested a review from jserv October 12, 2026 08:55
@jserv
jserv merged commit 0308133 into sysprog21:main Oct 12, 2026
6 checks passed
@jserv

jserv commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Thank @henrylee1003 for contributing!

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.

Toggle line comments in the code editor with Ctrl+/

3 participants