Consider this simple plugin, which uses closed values to store a mouse position to access inside the keydown
event.
From the docs it looks like it’s recommended to use StateField
, StateEffect
s and transactions to manage states (plz correct me if I’m wrong), but that looks like a lot of work, curious if this approach below is OK here, and if there’s any caveat?
const myExtension = () => {
let mouseX = 0;
let mouseY = 0;
return EditorView.domEventHandlers({
mousemove: (e, view) => {
mouseX = e.clientX;
mouseY = e.clientY;
},
keydown: (e, view) => {
const pos = view.posAtCoords({ mouseX, mouseY });
// do whatever
},
});
};