If I create a page with a button and a CodeMirror editor (in Safari 17.3), then
click on the editor
click directly onto the button (without clicking on the body first)
type some text
The focus is transferred back to CodeMirror and the text is added there (even though it should be unfocused). Is there any way to prevent this behaviour, and make it so that the keys are ignored when the CodeMirror element is unfocused?
In the demo below, I tried forcing the focus to change with .blur() on the CodeMirror element and .focus() on the button but these didn’t help.
If you click a button, that button receives focus (you can check with document.activeElement). But Safari seems to have added some weird feature where if you start typing in that situation it magically moves focus back into the editor. That is not CodeMirror’s problem and definitely not something CodeMirror should try to work around.