jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

How can I prevent existing keyboard events?

Open n4ks opened this issue 1 year ago • 1 comments

Good day! I am using the editor in Tree mode to view data without the ability to edit. To prevent keyboard input and allow copying I used onEvent:

   const isCopyEvent = evt.code === 'KeyC' && evt.ctrlKey; 
    if (
      evt.type === 'input' ||
      evt.type === 'paste' ||
      evt.type === 'keyup' ||
      evt.type === 'keydown'
    ) {
      if (!isCopyEvent) {
        evt.preventDefault();
      }

This works great for "native" events. But I don't understand how to prevent events that already exist in the library - such as ctrl + M, ctrl + D and so on. Is there any way to "unsubscribe" from them?

The events I'm talking about are in the onKeyDown() method

Thanks!

n4ks avatar Aug 09 '23 13:08 n4ks

I think the only way is to alter the Node.prototype.onEvent method, wrap it with your own variation.

josdejong avatar Aug 16 '23 15:08 josdejong