Deleting Custom Blocks throws errors when cursor position is on empty unstyled block
#154 opened on Mar 4, 2016
Description
I ran into this bug on my own editor while working with custom blocks but it can also be reproduced on the TeX example.
When attempting to delete/backspace a custom block it will fail if your cursor position is on an unstyled empty text block. When adding custom blocks the tex example places unstyled empty text blocks after each media block so that you can continue adding more text content after.
Deleting these custom blocks from an empty block will work if the custom block is the last block but if you place your cursor on the empty unstyled text block between two custom blocks it will fail when backspacing. If the unstyled block contains text it will work correctly.
Steps to Reproduce
- Open TeX example
- Clear the content editable (not required but easier to see whats going on)
- Insert 2 new TeX custom blocks
- Press arrow-up OR click between the two TeX blocks to move your cursor
- Press delete
Expected result: The first TeX block should be removed.
Actual result: Cursor moves to top-right corner of screen and throws the error:
Uncaught Error: Got unexpected null or undefined
Fails in getPointForNonTextNode()
if (!getSelectionOffsetKeyForNode(nodeBeforeCursor)) {
// Our target node may be a leaf or a text node, in which case we're
// already where we want to be and can just use the child's length as
// our offset.
leafKey = nullthrows(offsetKey);
textLength = getTextContentLength(nodeBeforeCursor);
}
Pressly delete again will then trigger another error:
Uncaught Invariant Violation: Unknown DraftEntity key.
Pressing delete a third time will remove the block.
Reproduced in Chrome 48.0.2564.116 and Firefox 44.0.2 on OS X Yosemite 10.10.5