codex-team / editor.js

A block-style editor with clean JSON output
https://editorjs.io
Apache License 2.0
28.86k stars 2.09k forks source link

When I tried to delete the first <span contenteditable='false'> tag of a block, it raised an error #2852

Open amoydavid opened 1 month ago

amoydavid commented 1 month ago

I'm using a editorjs-mention-tool plugin.

It will insert a <span contenteditable='false'>@user</span> tag into a block inner html.

But if this span tag located at the first element of the block, when I tried to press the backspace keyboard button to delete the whole span, I got this error.

Failed to execute 'setEnd' on 'Range': There is no child at offset 15.
IndexSizeError: Failed to execute 'setEnd' on 'Range': There is no child at offset 15.

situation:

<div class="ce-paragraph cdx-block" contenteditable="true" data-placeholder-active="Let's write an awesome story!" data-empty="false"><span href="kyleockford" contenteditable="false" class="mention_tool_at">[[kyleockford]]</span>|</div>

My caret is at the place of | , then I press backspace and I got the error.

related to this function? https://github.com/codex-team/editor.js/blob/631340912e7a1b3db1e114e930ddf1e97ec4ea61/src/components/utils/caret.ts#L10

neSpecc commented 1 month ago

Yes, that is probably because browser returns incorrect selection focusOffset. We need to find a solution.

amoydavid commented 1 month ago

@neSpecc I've tried to make a pr #2853 for this. It seems fixed my bug.