Skip to content

Add toggle line comment command (issue #27) - #28

Merged
magnesj merged 1 commit into
mainfrom
feature/27-toggle-line-comment
Jun 4, 2026
Merged

Add toggle line comment command (issue #27)#28
magnesj merged 1 commit into
mainfrom
feature/27-toggle-line-comment

Conversation

@magnesj

@magnesj magnesj commented Jun 4, 2026

Copy link
Copy Markdown
Member

Closes #27.

Adds an OPM Flow: Toggle Line Comment command that comments or uncomments the selected line(s) by toggling a -- marker at the absolute beginning of each line.

Behaviour

  • If every non-blank line in the selection already starts with --, the marker (plus one optional following space) is removed.
  • Otherwise -- is prefixed at column 0 of each non-blank line.
  • Blank lines are left untouched and ignored when deciding comment vs. uncomment.
  • Multi-cursor / multi-selection aware; a decision is made per selection.

Unlike VS Code's built-in toggle (which inserts at the indentation level), this places the marker at column 0, as requested in the issue.

Surface

  • Command opm-flow.toggleLineComment, available from the Command Palette and the editor right-click menu.
  • Bound to Ctrl+/ (Cmd+/ on macOS); VS Code resolves this through the active keyboard layout, so it lands on the same physical key as the built-in comment toggle.

Implementation

  • Core toggle logic is a pure toggleLineComments() helper in formatting.ts, with unit tests in formatting.test.ts.
  • README documents the new command.

Add an OPM Flow: Toggle Line Comment command that inserts or removes a
'--' marker at the absolute beginning of each selected line. If every
non-blank selected line is already commented the marker is removed;
otherwise '-- ' is prefixed at column 0. Blank lines are left untouched.

The toggle logic lives in a pure toggleLineComments() helper with unit
tests. The command is exposed via the editor context menu and bound to
Ctrl+/ (Cmd+/ on macOS), which VS Code resolves through the active
keyboard layout.
@magnesj
magnesj merged commit 1bc2dad into main Jun 4, 2026
4 checks passed
@magnesj
magnesj deleted the feature/27-toggle-line-comment branch June 4, 2026 12:10
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.

option to comment out single of multiple lines

1 participant