@codemirror/comment odd toggle behavior

We’re using the commenting commands extension with Next to edit JavaScript, but I find its behavior to be unexpected when toggling. For example given selected lines like:

Line 1: // This is my for loop
Line 2: for (let i = 0; i < 10; i++) {

then toggling line comments produces:

Line 1: This is my for loop
Line 2: for (let i = 0; i < 10; i++) {

in other words, it uncomments the comment. What for us is the desired output would be:

Line 1: // // This is my for loop
Line 2: // for (let i = 0; i < 10; i++) {

this makes it so a re-toggle with the same selection produces the original value.

Is the current behavior intended? It is easy for us to just write our own implementation create a private copy of the @codemirror/comment code, but I wasn’t sure if this was a bug or a feature?

That’s a good point, and one that I hadn’t really thought about when defining the current behavior. VS Code seems to do what you expect, so this patch aligns CodeMirror with that behavior.