Here the user can press [[ ]] enter custom text between the atomic range. After entering I want to capture the Enter keypress and do something. However none of the keypress events are firing. The mouse events do fire though. Is this due to any keyBindings (or lack thereof) or do I need to do something special to capture keypresses inside this widget?
FYI, I am using this extenstion - keymap.of(defaultKeymap),
Giving that element its own contenteditable attribute will make it separately focusable. So I expect the problem is that focus isn’t actually on the main editor, so key event don’t go to the element the library expects them to go to, when this happens.
So with this, it does capture the key event, however I found that all the events in the defaultKeymap are not getting passed to the span/eventHandlers as the keymap extension probably stops the propagation.
If I try to capture to capture any other key that is not registered by the standardKeymap like cltr, alt etc, it gets triggered, but Enter, backspace, left/right arrow keys etc which are part of the standardKeymap are not captured by this plugin.
Any workaround to pass those key events to the PlaceholderWidget?
So the eventHandlers in the above example still fire for the entire editor, not just the Widget.
However I can capture and control the key press this way. However I just need to detect if the cursor is inside the widget or not. How can I detect this?
{
eventHandlers: {
keydown: (e, view) => {
// Detect if the cursor is inside the editor??
console.log("Key pressed:", e.key);
if (e.key === "Enter") {
e.preventDefault();
e.stopPropagation();
console.log("Enter key pressed");
}
if (e.key === "ArrowLeft") {
//e.preventDefault();
e.stopPropagation();
console.log("Left arrow key pressed");
}
if (e.key === "ArrowRight") {
//e.preventDefault();
e.stopPropagation();
console.log("Right arrow key pressed");
}
},
},
The focus is always on the editor no matter what and therefore the event.target is always the editor and not the decorator span element. I guess this makes sense as the editor needs to capture all such events in order to function properly.
I found another way to detect if the current cursor position is inside any of the decorator or not -
The way the editor manages the selection, it assumes widgets are atomic things that you cannot move around through. I don’t think what you’re trying to do here is really something that’s possible with CodeMirror.