mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-01 05:16:10 +01:00
fix insert fragment selection with non-normalized fragment
This commit is contained in:
parent
46df9f6c52
commit
c874637451
@ -135,6 +135,7 @@ Commands.insertFragment = (editor, fragment) => {
|
||||
const { startText, endText, startInline } = value
|
||||
const lastText = fragment.getLastText()
|
||||
const lastInline = fragment.getClosestInline(lastText.key)
|
||||
const lastBlock = fragment.getClosestBlock(lastText.key)
|
||||
const firstChild = fragment.nodes.first()
|
||||
const lastChild = fragment.nodes.last()
|
||||
const keys = document.getTexts().map(text => text.key)
|
||||
@ -154,13 +155,11 @@ Commands.insertFragment = (editor, fragment) => {
|
||||
const newText = isAppending ? newTexts.last() : newTexts.takeLast(2).first()
|
||||
|
||||
if (newText && (lastInline || isInserting)) {
|
||||
editor.select(selection.moveToEndOfNode(newText))
|
||||
editor.moveToEndOfNode(newText)
|
||||
} else if (newText) {
|
||||
editor.select(
|
||||
selection.moveToStartOfNode(newText).moveForward(lastText.text.length)
|
||||
)
|
||||
editor.moveToStartOfNode(newText).moveForward(lastBlock.text.length)
|
||||
} else {
|
||||
editor.select(selection.moveToStart().moveForward(lastText.text.length))
|
||||
editor.moveToStart().moveForward(lastBlock.text.length)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(editor) {
|
||||
editor.insertFragment(
|
||||
<document>
|
||||
<paragraph>
|
||||
<text>one</text>
|
||||
<text>two</text>
|
||||
</paragraph>
|
||||
</document>
|
||||
)
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
onetwo<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user