diff --git a/src/models/block.js b/src/models/block.js index 5cbb914bf..0a75134c3 100644 --- a/src/models/block.js +++ b/src/models/block.js @@ -53,9 +53,9 @@ class Block extends new Record(DEFAULTS) { properties.isVoid = !!properties.isVoid properties.nodes = Block.createList(properties.nodes) - // if (properties.nodes.size == 0) { - // properties.nodes = properties.nodes.push(Text.create()) - // } + if (properties.nodes.size == 0) { + properties.nodes = properties.nodes.push(Text.create()) + } return new Block(properties).normalize() } diff --git a/src/transforms/by-key.js b/src/transforms/by-key.js index 90e346ad9..32f6e6122 100644 --- a/src/transforms/by-key.js +++ b/src/transforms/by-key.js @@ -37,7 +37,25 @@ export function insertNodeByKey(transform, key, index, node) { const { document } = state const path = document.getPath(key) const newPath = path.slice().push(index) - return transform.insertNodeOperation(path, index, node) + transform.insertNodeOperation(path, index, node) + + // If the node is an inline void, the parent is a block, and the node will be + // inserted at the block's edge, we need to add surrounding text nodes. + if (node.kind == 'inline' && node.isVoid) { + const parent = document.assertDescendant(key) + + if (index == 0) { + const text = Text.create() + transform.insertNodeByKey(key, index, text) + } + + if (index == parent.nodes.size) { + const text = Text.create() + transform.insertNodeByKey(key, index + 1, text) + } + } + + return transform } /** diff --git a/test/transforms/index.js b/test/transforms/index.js index a6dfcbc80..3a65e4092 100644 --- a/test/transforms/index.js +++ b/test/transforms/index.js @@ -18,7 +18,6 @@ describe('transforms', () => { for (const transform of transforms) { if (transform[0] == '.') continue - if (transform == 'insert-node-by-key') continue describe(`${toCamel(transform)}()`, () => { const transformDir = resolve(__dirname, './fixtures/by-key', transform)