1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

fix selection after pasting inline nodes (#2738)

* fix selection after pasting inline nodes

* add forgotten line

* added test case
This commit is contained in:
Entkenntnis
2019-05-09 22:50:59 +02:00
committed by Ian Storm Taylor
parent 2e197662ae
commit 5bef253855
2 changed files with 48 additions and 1 deletions

View File

@@ -278,7 +278,19 @@ Commands.insertFragment = (editor, fragment) => {
if (newText && (lastInline || isInserting)) {
editor.moveToEndOfNode(newText)
} else if (newText) {
editor.moveToStartOfNode(newText).moveForward(lastBlock.text.length)
// The position within the last text node needs to be calculated. This is the length
// of all text nodes within the last block, but if the last block contains inline nodes,
// these have to be skipped.
const { nodes } = lastBlock
const lastIndex = nodes.findLastIndex(
node => node && node.object === 'inline'
)
const remainingTexts = nodes.takeLast(nodes.size - lastIndex - 1)
const remainingTextLength = remainingTexts.reduce(
(acc, val) => acc + val.text.length,
0
)
editor.moveToStartOfNode(newText).moveForward(remainingTextLength)
}
}

View File

@@ -0,0 +1,35 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function(editor) {
editor.insertFragment(
<document>
<paragraph>
<text>one</text>
<inline type="link">Some inline stuff</inline>
<text>two</text>
</paragraph>
</document>
)
}
export const input = (
<value>
<document>
<paragraph>
A<cursor />B
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
Aone<inline type="link">Some inline stuff</inline>two<cursor />B
</paragraph>
</document>
</value>
)