josdejong / josdejong/jsoneditor

How can I prevent existing keyboard events?

Open
#1,542 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
12.3k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.