Slate: deleting inside an empty non-void inline should remove it

Created on 11 Oct 2018  Â·  3Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Bug.

What's the current behavior?

Consider this document:

      <document>
        <paragraph>
          wo<link><cursor /></link>rd
        </paragraph>
      </document>

If you do deleteBackward() here, it will end up removing the 'o' before the cursor, and not removing the non-void <link> inline node too

What's the expected behavior?

It should remove the <link> and the 'o' I think.

bug ♥ help

Most helpful comment

Hi,

My text is only composed of inline nodes inside paragraphs.

Use case is a collaborative editor where each inline is owned by a user:

...
change.insertInline({ type: 'user', data: Data.create({userId: user}) })
...

>

<p>
<span class='user1'>Hello</span>
<span class='user2'>World</span>
<span class='user3'>!</span>
</p>

Delete / backspace is not removing the current inline node even though it's empty.

Oddly, when adding text on second line / first offset before an already existing inline node, editor stops with this error:

Uncaught TypeError: previous.getMarksAtIndex is not a function
    at Document.getMarksAtPosition (slate.es.js:12699)
    at Document.object.(:3000/anonymous function) (http://localhost:3000/static/js/0.chunk.js:56862:28)
    at Document.getInsertMarksAtRange (slate.es.js:12528)
...

When deleting on first line / first offset, editor stops with this error:

TypeError: Cannot read property 'text' of null
push../node_modules/slate/lib/slate.es.js.Commands$1.deleteBackwardAtRange
node_modules/slate/lib/slate.es.js:6050
  6047 | 
  6048 | while (n > traversed) {
  6049 |   node = document.getPreviousText(node.key);
> 6050 |   var next = traversed + node.text.length;
       | ^  6051 | 
  6052 |   if (n <= next) {
  6053 |     offset = next - n;
...

It's a commission so I have to deliver ! Do you have any advice here ? Thanks !

If I find a workaround, I'll let you know here...

All 3 comments

Hi,

My text is only composed of inline nodes inside paragraphs.

Use case is a collaborative editor where each inline is owned by a user:

...
change.insertInline({ type: 'user', data: Data.create({userId: user}) })
...

>

<p>
<span class='user1'>Hello</span>
<span class='user2'>World</span>
<span class='user3'>!</span>
</p>

Delete / backspace is not removing the current inline node even though it's empty.

Oddly, when adding text on second line / first offset before an already existing inline node, editor stops with this error:

Uncaught TypeError: previous.getMarksAtIndex is not a function
    at Document.getMarksAtPosition (slate.es.js:12699)
    at Document.object.(:3000/anonymous function) (http://localhost:3000/static/js/0.chunk.js:56862:28)
    at Document.getInsertMarksAtRange (slate.es.js:12528)
...

When deleting on first line / first offset, editor stops with this error:

TypeError: Cannot read property 'text' of null
push../node_modules/slate/lib/slate.es.js.Commands$1.deleteBackwardAtRange
node_modules/slate/lib/slate.es.js:6050
  6047 | 
  6048 | while (n > traversed) {
  6049 |   node = document.getPreviousText(node.key);
> 6050 |   var next = traversed + node.text.length;
       | ^  6051 | 
  6052 |   if (n <= next) {
  6053 |     offset = next - n;
...

It's a commission so I have to deliver ! Do you have any advice here ? Thanks !

If I find a workaround, I'll let you know here...

When you backspace and the cursor and empty inline are at the beginning of a block, you get:

slate.es.js?d1a0:5849 Uncaught TypeError: Cannot read property 'text' of null
    at Commands$1.deleteBackwardAtRange (slate.es.js?d1a0:5849)

For the user, this causes the backspace to fail. My workaround is specifying inlines isVoid (per the mentions example)

I believe that this may be fixed by https://github.com/ianstormtaylor/slate/pull/3093, which has changed a lot of the logic in Slate and slate-react especially. I'm going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

Was this page helpful?
0 / 5 - 0 ratings