From d6901aa416120dc86b8fa9f6bbfff17f47f70c58 Mon Sep 17 00:00:00 2001 From: Andrew Cobby Date: Mon, 5 Sep 2016 14:19:00 +1000 Subject: [PATCH] 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. --- lib/models/transforms.js | 3 ++- .../fixtures/split-block/with-void/index.js | 24 +++++++++++++++++++ .../fixtures/split-block/with-void/input.yaml | 5 ++++ .../split-block/with-void/output.yaml | 8 +++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/transforms/fixtures/split-block/with-void/index.js create mode 100644 test/transforms/fixtures/split-block/with-void/input.yaml create mode 100644 test/transforms/fixtures/split-block/with-void/output.yaml diff --git a/lib/models/transforms.js b/lib/models/transforms.js index a7c72904f..59c66a7ee 100644 --- a/lib/models/transforms.js +++ b/lib/models/transforms.js @@ -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. diff --git a/test/transforms/fixtures/split-block/with-void/index.js b/test/transforms/fixtures/split-block/with-void/index.js new file mode 100644 index 000000000..ea5a66fc1 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-void/index.js @@ -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 +} diff --git a/test/transforms/fixtures/split-block/with-void/input.yaml b/test/transforms/fixtures/split-block/with-void/input.yaml new file mode 100644 index 000000000..5c4272312 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-void/input.yaml @@ -0,0 +1,5 @@ + +nodes: + - kind: block + type: video + isVoid: true diff --git a/test/transforms/fixtures/split-block/with-void/output.yaml b/test/transforms/fixtures/split-block/with-void/output.yaml new file mode 100644 index 000000000..3cd48848e --- /dev/null +++ b/test/transforms/fixtures/split-block/with-void/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: video + isVoid: true + - kind: block + type: video + isVoid: true