1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 12:14:14 +02:00

Add failing test showing splitBlock with isVoid bug (#276)

* Add failing test showing splitBlock with isVoid bug

Not sure what I actually expected calling `splitBlock()` on void block, but I
would expect `splitBlock()` to respect a given block type's isVoid property.
This failing test demonstrates that `splitBlock()` always creates a the new
block with `isVoid: false`.

* Fix isVoid not being copied when using splitBlock()

The bug was actually inside `splitBlockAtRange`, as that's what actual drives
`splitBlock()` (I assume the bug was therefore present in both methods). The
fix is to simply copy across the `isVoid` value from the block being copied.
This commit is contained in:
Andrew Cobby
2016-09-05 14:19:00 +10:00
committed by Ian Storm Taylor
parent 3c46d0544c
commit d6901aa416
4 changed files with 39 additions and 1 deletions

View File

@@ -612,7 +612,8 @@ const Transforms = {
secondChild = Block.create({
nodes: secondChildren,
type: parent.type,
data: parent.data
data: parent.data,
isVoid: parent.isVoid
})
// Add the new children.

View File

@@ -0,0 +1,24 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.splitBlock()
.apply()
console.dir(next.document.getBlocks().toJS());
return next
}

View File

@@ -0,0 +1,5 @@
nodes:
- kind: block
type: video
isVoid: true

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: video
isVoid: true
- kind: block
type: video
isVoid: true