1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-31 20:48:30 +01:00

Fix deleteBackwardAtRange removing extra character when called at start of both block and inline node (#2408)

This commit is contained in:
Malgalad 2018-11-11 20:59:40 +02:00 committed by Ian Storm Taylor
parent a75c06b501
commit da2cf83310
2 changed files with 45 additions and 1 deletions

View File

@ -322,7 +322,16 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => {
const text = document.getDescendant(start.key)
if (start.isAtStartOfNode(text)) {
const prev = document.getPreviousText(text.key)
let prev = document.getPreviousText(text.key)
const inline = document.getClosestInline(text.key)
// If the range is at the start of the inline node, and previous text node
// is empty, take the text node before that, or "prevBlock" would be the
// same node as "block"
if (inline && prev.text === '') {
prev = document.getPreviousText(prev.key)
}
const prevBlock = document.getClosestBlock(prev.key)
const prevVoid = document.getClosestVoid(prev.key, editor)

View File

@ -0,0 +1,35 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function(editor) {
editor.deleteBackward()
}
export const input = (
<value>
<document>
<paragraph>
one<link>two</link>
</paragraph>
<paragraph>
<link>
<cursor />three
</link>four
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
one<link>two</link>
<link>
<cursor />three
</link>four
</paragraph>
</document>
</value>
)