getPos on Keydown vs MouseClick

Hi! I’m trying to implement a simple function where if a user clicks on or keydowns to a node, they can click on a keyboard shortcut to undo marks.

On mouse click, i’m able to get the node successfully starting with getPos().

However, on key down, getPos() returns the value of all the node on the page vs. just the position of where the caret is. Any thoughts on how to getPos on key down to return just 1 value (i.e. where the caret is)?

Thanks!

This sounds like you’re registering a keydown handler on the entire editor in each of your node views. Keyboard focus is per-editor, not per-node, so you cannot really handle keys that go to the editor in node views. Instead, register a single keydown handler with a plugin, check whether the selection is on the type of node you’re interested in (by inspecting the editor state), and do what you’re trying to do from there.

thanks as always marijn. let me give what you suggest a go - that logic makes sense to me.