1
0
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:
Ian Storm Taylor 2018-10-31 10:05:45 -07:00
parent 46df9f6c52
commit c874637451
2 changed files with 38 additions and 5 deletions

View File

@ -135,6 +135,7 @@ Commands.insertFragment = (editor, fragment) => {
const { startText, endText, startInline } = value const { startText, endText, startInline } = value
const lastText = fragment.getLastText() const lastText = fragment.getLastText()
const lastInline = fragment.getClosestInline(lastText.key) const lastInline = fragment.getClosestInline(lastText.key)
const lastBlock = fragment.getClosestBlock(lastText.key)
const firstChild = fragment.nodes.first() const firstChild = fragment.nodes.first()
const lastChild = fragment.nodes.last() const lastChild = fragment.nodes.last()
const keys = document.getTexts().map(text => text.key) 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() const newText = isAppending ? newTexts.last() : newTexts.takeLast(2).first()
if (newText && (lastInline || isInserting)) { if (newText && (lastInline || isInserting)) {
editor.select(selection.moveToEndOfNode(newText)) editor.moveToEndOfNode(newText)
} else if (newText) { } else if (newText) {
editor.select( editor.moveToStartOfNode(newText).moveForward(lastBlock.text.length)
selection.moveToStartOfNode(newText).moveForward(lastText.text.length)
)
} else { } else {
editor.select(selection.moveToStart().moveForward(lastText.text.length)) editor.moveToStart().moveForward(lastBlock.text.length)
} }
} }

View File

@ -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>
)