codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 377 forks source link

Selecting backwards throws errors with EditContext (6.28.0). #1392

Closed jclem closed 5 months ago

jclem commented 5 months ago

Describe the issue

This is reproducible with the basic setup when using the EditContext API. CodeMirror will call editContext.updateSelection() with a start > end value, which is a DOMException.

Browser and platform

Chrome

Reproduction link

No response

marijnh commented 5 months ago

Oh, that's disappointing — they didn't implement their own spec, which explicitly says inverted selections are supported, properly.

I guess I'll push an emergency patch to turn EditContext integration off for the time being until we sort this out. Thanks for reporting these.

jclem commented 5 months ago

Thanks! Note that the MDN docs do mention that this is an exception: https://developer.mozilla.org/en-US/docs/Web/API/EditContext/updateSelection#exceptions

If start is greater than end, a DOMException is thrown.

(Although the MDN docs != the spec of course)

marijnh commented 5 months ago

This is fixed in Chrome 126. I've pushed a patch that disables EditContext use for older browser versions.

jclem commented 5 months ago

@marijnh Thank you! This was in Electron, which I guess is why I ran into it. Also explains why I couldn't reproduce it with plain old Vite in Chrome.