question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

deleteBackwardAtRange with empty initial value

See original GitHub issue

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

Bug

What’s the current behavior?

My editor has a character limit of 1000 characters. When pasting four blocks of 251, the text gets trimmed properly using deleteBackward. However, when pasting 1000+ characters at once, the editor crashes.

(See browser console for the error, codesandbox does not display the error)

  • A GIF showing the issue in action. Pasting more than 1000 chars Screen+Recording+2019-11-04+at+02 16+PM

  • Information about your OS, browser, Slate version, etc. OS X Mojave, Chrome 78, Slate 0.47.8, Slate-React 0.22.9

What’s the expected behavior?

I expect the editor to trim the pasted text to 1000 characters without crashing.

Note that pasting 1000+ characters works after typing a couple of characters or setting the initial value to some text or a space. The crash only happens when the initial value is an empty string.

It seems like there’s a check missing in deleteBackwardAtRange where it attempts to access node.key while node is null.

I’m not completely sure if the way we impose the character limit is the correct way to do so. If possible, any pointers to improve the code (while avoiding the “bug”) are welcome. If not, I am certainly willing to work with you in fixing the issue in the Slate code.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ryanmittscommented, Nov 6, 2019

The default “empty” state for this example is a single paragraph block with an empty text node inside. I think that is a reasonable state to have an editor in and expect this to work.

At the time of the paste in the steps of this bug, the selection anchor and focus are both at path [0,0], offset 0, which is the text node within the paragraph block.

It seems the issue is because this condition is causing the node at the current selection to be removed, which invalidates the selection, and then the pasted text replaces it. Therefore, when the schema normalization happens, it’s deleting backwards from a selection where the path and offset of the anchor and focus are now null.

I’m not quite sure what that condition is preventing.

I don’t know what OPs use case is, but maybe an onPaste listener can be used and if the paste is simply text, handle the insertion oneself?

Does Slate have to insert a fragment when the paste is only text? Or can it be handled as an insertText?

0reactions
ianstormtaylorcommented, Nov 28, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detect backspace in empty UITextField - ios - Stack Overflow
Check out UITextInput , specifically UIKeyInput has a deleteBackward delegate method that always gets called when the delete key is pressed. If you're...
Read more >
deleteBackward() - Documentation - Apple Developer
A Boolean value that indicates whether the text-entry object has any text. Required.
Read more >
Detect when delete is typed into a TextField #14809 - GitHub
In the build function set the initial value every time the widget is ... it will detect the backspace key press if the...
Read more >
Chez Scheme Release Notes
The default initial value of this parameter is #f. ... If the list of strings naming base boot files is empty, the first...
Read more >
tf-help
Adds a new world with the name <name>, or defines the default character and password. Any omitted fields will assume the values of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found