PrismJS / live

Prism Live: Lightweight, extensible editable code editors. A work in progress, try it out at your own risk (and report bugs!) :)
https://live.prismjs.com
MIT License
105 stars 28 forks source link

Multiline uncommenting acts weird, causes errors #31

Open dragoncoder047 opened 2 years ago

dragoncoder047 commented 2 years ago

Go to the Prism Live web site, scroll down to the JS, and select something more than one line. For example, select setCaret() here

setCaret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}

moveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}

(Not that this is where the problem may be; it's just what I happened to be staring at when I noticed this bug.)

Press Ctrl+/, and it comments out like it should:

/*setCaret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}*/

moveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}

Notice the selection includes the /* */ markers. With those still selected press Ctrl+/ again and it just adds more comments (and creating a syntax error with the second end comment):

/*/*setCaret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}*/*/

moveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}

It only un-comments if the /* */ are not selected. I change selection to this (| are the selection boundaries):

/*/*|setCaret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}|*/*/

moveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}

Press Ctrl+/ and I get this:

/*se|tCaret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}*/|

moveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}

Then without changing the selection hit Ctrl+/ again, and the selection range is messed up even more:

setC|aret(pos) {
    this.selectionStart = this.selectionEnd = pos;
}

m|oveCaret(chars) {
    if (chars) {
        this.setCaret(this.selectionEnd + chars);
    }
}