codemirror / dev

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

Selection breaks if you drag outside of an iframe #1386

Closed rickyvetter closed 5 months ago

rickyvetter commented 6 months ago

Describe the issue

If you select code and drag your mouse outside of the containing iframe, then the codemirror state is broken.

It seems to set the entire state to the last character pressed. If, instead of immediately typing, you delete the selection, then your text gets input backwards.

https://github.com/codemirror/dev/assets/4370652/8b0f45bf-887d-4173-83b0-a44647c4188c

Browser and platform

Chrome, Linux

Reproduction link

https://codemirror.net/try/?example=Minimal%20editor

marijnh commented 5 months ago

This seems to require a sandbox attribute on the iframe. That forbids the frame from receiving any information about mouse events outside of its content, so that it isn't told that the mouse has been released until you move the pointer back into the frame.

Since aborting mouse selection when the pointer moves out of the document would break drag-selecting out of the window in cases where that does give us events, I've solved this in attached patch by cutting off mouse selection when the user types.