From 90abc993b99c1f60f7241d7662786603b7d709ab Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 5 Aug 2016 10:25:52 -0700 Subject: [PATCH] fix for insertBlockAtRange in empty blocks, closes #224 --- lib/models/transforms.js | 3 ++- .../fixtures/insert-block-at-range/is-empty/input.yaml | 5 +++++ .../fixtures/insert-block-at-range/is-empty/output.yaml | 5 +++++ test/transforms/fixtures/insert-block/is-empty/input.yaml | 5 +++++ test/transforms/fixtures/insert-block/is-empty/output.yaml | 5 +++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/models/transforms.js b/lib/models/transforms.js index 8984602d3..9548d5c45 100644 --- a/lib/models/transforms.js +++ b/lib/models/transforms.js @@ -255,7 +255,8 @@ const Transforms = { // If the block is empty, replace it. else if (startBlock.isEmpty) { - parent = parent.merge({ nodes }) + parent = parent.insertChildrenAfter(startBlock, nodes) + parent = parent.removeDescendant(startBlock) } // If the range is at the start of the block, insert before. diff --git a/test/transforms/fixtures/insert-block-at-range/is-empty/input.yaml b/test/transforms/fixtures/insert-block-at-range/is-empty/input.yaml index f6de4d08a..fbe1a3f76 100644 --- a/test/transforms/fixtures/insert-block-at-range/is-empty/input.yaml +++ b/test/transforms/fixtures/insert-block-at-range/is-empty/input.yaml @@ -5,3 +5,8 @@ nodes: nodes: - kind: text text: "" + - kind: block + type: paragraph + nodes: + - kind: text + text: not empty diff --git a/test/transforms/fixtures/insert-block-at-range/is-empty/output.yaml b/test/transforms/fixtures/insert-block-at-range/is-empty/output.yaml index 68da1740e..82e79625b 100644 --- a/test/transforms/fixtures/insert-block-at-range/is-empty/output.yaml +++ b/test/transforms/fixtures/insert-block-at-range/is-empty/output.yaml @@ -5,3 +5,8 @@ nodes: nodes: - kind: text text: "" + - kind: block + type: paragraph + nodes: + - kind: text + text: not empty diff --git a/test/transforms/fixtures/insert-block/is-empty/input.yaml b/test/transforms/fixtures/insert-block/is-empty/input.yaml index f6de4d08a..fbe1a3f76 100644 --- a/test/transforms/fixtures/insert-block/is-empty/input.yaml +++ b/test/transforms/fixtures/insert-block/is-empty/input.yaml @@ -5,3 +5,8 @@ nodes: nodes: - kind: text text: "" + - kind: block + type: paragraph + nodes: + - kind: text + text: not empty diff --git a/test/transforms/fixtures/insert-block/is-empty/output.yaml b/test/transforms/fixtures/insert-block/is-empty/output.yaml index 68da1740e..82e79625b 100644 --- a/test/transforms/fixtures/insert-block/is-empty/output.yaml +++ b/test/transforms/fixtures/insert-block/is-empty/output.yaml @@ -5,3 +5,8 @@ nodes: nodes: - kind: text text: "" + - kind: block + type: paragraph + nodes: + - kind: text + text: not empty