Slate: Select all + paste results in an error when there is a trailing empty block

Created on 5 Dec 2017  路  8Comments  路  Source: ianstormtaylor/slate

Do you want to request a feature or report a bug?

Bug

What's the current behavior?

If there is a trailing empty block, and we select all with cmd+a and then paste anything, an error occurs:

Uncaught TypeError: Cannot read property 'key' of undefined
    at Changes.insertFragmentAtRange (https://npmcdn.com/[email protected]/dist/slate.js:7158:55)
    at Change.call (https://npmcdn.com/[email protected]/dist/slate.js:10521:10)
    at Change.(anonymous function) [as insertFragmentAtRange] (https://npmcdn.com/[email protected]/dist/slate.js:10580:15)
    at Changes.insertFragment (https://npmcdn.com/[email protected]/dist/slate.js:6193:10)
    at Change.call (https://npmcdn.com/[email protected]/dist/slate.js:10521:10)
    at Change.(anonymous function) [as insertFragment] (https://npmcdn.com/[email protected]/dist/slate.js:10580:15)
    at Object.onPaste (https://npmcdn.com/[email protected]/dist/slate-react.js:11554:14)
    at Stack.run (https://npmcdn.com/[email protected]/dist/slate.js:16879:38)
    at https://npmcdn.com/[email protected]/dist/slate-react.js:9290:20
    at Change.call (https://npmcdn.com/[email protected]/dist/slate.js:10521:10)

Issue can be reproduced on the default fiddle: https://jsfiddle.net/fj9dvhom/1/
Here is a gif: https://imgur.com/a/1KENt

Chrome version 62, Ubuntu 17, Slate version 0.31.5

What's the expected behavior?

After selecting all with cmd+a, paste should work correctly no matter if there is a trailing empty block or not.

bug

Most helpful comment

No, sorry if I confused things here. This was recently fixed for when inserting text (i.e. for insertTextAtRange), but it's still an issue for insertFragmentAtRange.

All 8 comments

I did a PR for this. It did solve it in my case.

It's not only when pasting though. If you select all, with a trailing empty block, and type something you also get an error. I think @zGrav's fix will solve the pasting issue, but not for when inserting text.

I do not suffer from this issue @tobiasandersen

Oh you're right, I hand't pulled latest, so I guess it was fixed recently :)

I did found out another one though, PR'ing :)

So is this fixed on the latest?

No, sorry if I confused things here. This was recently fixed for when inserting text (i.e. for insertTextAtRange), but it's still an issue for insertFragmentAtRange.

I think this is fixed in the latest version of Slate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

varoot picture varoot  路  3Comments

AlexeiAndreev picture AlexeiAndreev  路  3Comments

markolofsen picture markolofsen  路  3Comments

chrpeter picture chrpeter  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments