`toggleComment` after triple-click line selection

When you triple-click a line of code, you get the whole line selected plus the new-line character. If you then trigger toggleComment, the behavior is inconsistent depending on the language.

JavaScript works as I’d expect: the line you triple clicked gets commented.

triple-click-js

HTML and CSS comment both the line you triple clicked and the next line. This is not how I’d expect it to behave.
triple-click-html

triple-click-css

I tested this in my full CodeMirror setup and in stripped down CodeMirror Try examples and got the same behavior.

Am I missing some kind of configuration or is there another reason they’re handled differently in these languages?

I suspect it comes down to if the language offers line comments or Block Comments. If so, any workaround to have Block Comments not comment out both lines?

I did find this thread about modifying triple click, but I don’t necessarily want to change the triple click selection behavior; simply the toggleComment behavior.

Indeed, that happened because when there are no line comment markers, the code goes through toggleBlockCommentByLine, which included any lines touched by the selection. Attached patch makes it exclude lines where the selection ends right at the start.

That’s great! Thank you for patching. Mind giving @codemirror/commands a small version bump so I can test it out in my repo?

Sure. I’ve tagged 6.7.1

Working great. Thanks, @marijn!