diff --git a/src/components/content.js b/src/components/content.js index 43f9939679..99b5b0b057 100644 --- a/src/components/content.js +++ b/src/components/content.js @@ -164,6 +164,9 @@ class Content extends React.Component { return } + // If the selection isn't set, do nothing. + if (selection.isUnset) return + // Otherwise, figure out which DOM nodes should be selected... const { anchorText, focusText } = state const { anchorKey, anchorOffset, focusKey, focusOffset } = selection @@ -785,13 +788,29 @@ class Content extends React.Component { isBackward: null } - // If the selection is at the end of a non-void inline node, and there is - // a node after it, put it in the node after instead. const anchorText = document.getNode(anchor.key) const focusText = document.getNode(focus.key) const anchorInline = document.getClosestInline(anchor.key) const focusInline = document.getClosestInline(focus.key) + const focusBlock = document.getClosestBlock(focus.key) + const anchorBlock = document.getClosestBlock(anchor.key) + + // When going from a non-void block to the start of a void-block + // the focus is most of the time collpased to the end of the void block. + // This is getting the void-block selected as well when it shouldn't. + // Make sure it is collapsed to the start in those cases. + if (anchorBlock && !anchorBlock.isVoid && focusBlock && focusBlock.isVoid && focus.offset == 1) { + properties.focusOffset = 0 + } + // If anchor and focus block is the same void block make sure it is anchored to start + // so we are able to select and delete it + if (anchorBlock && anchorBlock.isVoid && focusBlock && focusBlock.key == anchorBlock.key) { + properties.anchorOffset = 0 + } + + // If the selection is at the end of a non-void inline node, and there is + // a node after it, put it in the node after instead. if (anchorInline && !anchorInline.isVoid && anchor.offset == anchorText.text.length) { const block = document.getClosestBlock(anchor.key) const next = block.getNextText(anchor.key)