mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 03:11:44 +02:00
Fix insert fragment multiple nested (#309)
* Add fixture for insertFragmentAtRange with multiple blocks in nested blocks * Small fix for the fixture's `expected` output * Rebase on master (0.14.x) Moved tests to new appropriate location * Output now expects that fragment are merged to adjacent blocks * fix insert fragment for multiple children
This commit is contained in:
@@ -304,7 +304,7 @@ export function insertFragmentAtRange(transform, range, fragment) {
|
||||
fragment = fragment.removeDescendant(lonelyChild)
|
||||
|
||||
fragment.nodes.forEach((node, i) => {
|
||||
const newIndex = startIndex + i + 2
|
||||
const newIndex = startIndex + i + 1
|
||||
transform.insertNodeByKey(parent.key, newIndex, node)
|
||||
})
|
||||
}
|
||||
|
@@ -0,0 +1,14 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: fragment one
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: fragment two
|
@@ -0,0 +1,25 @@
|
||||
|
||||
import path from 'path'
|
||||
import readMetadata from 'read-metadata'
|
||||
import { Raw } from '../../../../../..'
|
||||
|
||||
export default function (state) {
|
||||
const file = path.resolve(__dirname, 'fragment.yaml')
|
||||
const raw = readMetadata.sync(file)
|
||||
const fragment = Raw.deserialize(raw, { terse: true }).document
|
||||
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 2,
|
||||
focusKey: first.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
return state
|
||||
.transform()
|
||||
.insertFragmentAtRange(range, fragment)
|
||||
.apply()
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: list-item
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: first
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: second
|
@@ -0,0 +1,20 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: list-item
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: fifragment one
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: fragment tworst
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: second
|
Reference in New Issue
Block a user