editor-js / editor-js/raw

Bug in Firefox when dynamically populating the field

Open
#16 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
71
Forks
33
PR merge metrics
No merged PRs in 30d

Description

There's a weird bug on Firefox (v81) where movement keys jump to next/previous block and not next/previous character. This happens only if you dynamically load content to Editorjs and one of the blocks is a raw block.

**Steps to reproduce:**

1. Load the Editorjs with this code:
```

const editor = new EditorJS({
tools: {
raw: RawTool
},
data: {
blocks : [
{
type : "paragraph",
data : {
text : "Lorem ipsum"
}
},
{
type : "raw",
data : {
html : "Whatevs"
}
}
]
}
})

```
2. Click the end of the `Whatevs` text with latest Firefox and press arrow left on keyboard. The cursor moves to previous block instead of moving to between letters v and s.

If I create a new Editorjs without prepopulating data and recreate those fields, this does not happen and moving the cursor using arrow keys in raw textarea works as it should.

This bug is more than mere annoyance, because it happens also when using backspace to delete characters. The cursor jumps to previous block and consecutive key presses remove characters from there instead of the ones the user intended to remove.

I'm not sure if this is a bug in Editorjs or this plugin, but you can prevent this behaviour by adding the following to this plugin's `drawView()` function:

```
textarea.addEventListener('keydown', function (event) {
const blockKeys = ['ArrowRight', 'ArrowLeft', 'Backspace'];

if (blockKeys.includes(event.key)) {
event.stopPropagation();
}
});
```

But this might have some unwanted side effects. There are some open bugs in Bugzilla related to Firefox's textarea that do not exist on other browsers, so the easier route might be using `

` instead of ``, like in paragraph plugin.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.