In order to avoid focus on the editor I noticed it to be sufficient to define
mousedown: (_, ev) => {
console.log("Mouse down")
console.log("Prevent default...");
ev.preventDefault();
},
in handleDOMEvents
on the EditorView
. Indeed, whenever I press on some random text in my editor it doesn’t focus, great! However, now I have an element that defines the toDom
function as
[
'button',
{
contenteditable: false,
},
0,
];
I now adapt the mousedown
function to only prevent the default when the target has contenteditable
set to false (just like the button above). Something like:
mousedown: (_, ev) => {
console.log("Mouse down");
const canEdit = ev.target.contentEditable;
if (canEdit === "false") {
console.log("Prevent default...");
ev.preventDefault();
}
}
I now do the following:
- Press somewhere on ‘regular’ text inside the editor - say location
A
-, we get focus (as expected) - Press outside the editor, to remove the focus
- Now I press the button
- It focusses on location
A
. Why?!
Point 4 is what I want to avoid. I tried implementing all reasonable handleDOMEvents
, but none which avoided focus on button press. What am I missing?