mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +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:
committed by
Ian Storm Taylor
parent
2e197662ae
commit
5bef253855
@@ -278,7 +278,19 @@ Commands.insertFragment = (editor, fragment) => {
|
|||||||
if (newText && (lastInline || isInserting)) {
|
if (newText && (lastInline || isInserting)) {
|
||||||
editor.moveToEndOfNode(newText)
|
editor.moveToEndOfNode(newText)
|
||||||
} else if (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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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>
|
||||||
|
)
|
Reference in New Issue
Block a user