1
0
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:
Ian Storm Taylor
2016-09-13 11:39:22 -07:00
committed by GitHub
parent bcd85ff1bb
commit 7b55316c18
5 changed files with 77 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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

View File

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