From 3a78c4b66e36d702c9b276d39bb715a6f91b80f4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 10 Mar 2018 22:33:13 -0800 Subject: [PATCH] Only show block insert on empty paragraphs --- app/components/Editor/components/BlockInsert.js | 10 ++++++---- .../Editor/components/Toolbar/BlockToolbar.js | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/components/Editor/components/BlockInsert.js b/app/components/Editor/components/BlockInsert.js index 0f6615bf0..71d2398e8 100644 --- a/app/components/Editor/components/BlockInsert.js +++ b/app/components/Editor/components/BlockInsert.js @@ -71,7 +71,11 @@ export default class BlockInsert extends Component { // do not show block menu on title heading or editor const firstNode = this.props.editor.value.document.nodes.first(); - if (result.node === firstNode || result.node.type === 'block-toolbar') { + if ( + result.node === firstNode || + result.node.type === 'block-toolbar' || + !!result.node.text.trim() + ) { this.left = -1000; } else { this.left = Math.round(result.bounds.left - 20); @@ -107,15 +111,13 @@ export default class BlockInsert extends Component { // if we're on an empty paragraph then just replace it with the block // toolbar. Otherwise insert the toolbar as an extra Node. if ( - !this.closestRootNode.text && + !this.closestRootNode.text.trim() && this.closestRootNode.type === 'paragraph' ) { change.setNodeByKey(this.closestRootNode.key, { type: 'block-toolbar', isVoid: true, }); - } else { - change.insertBlock({ type: 'block-toolbar', isVoid: true }); } }); }; diff --git a/app/components/Editor/components/Toolbar/BlockToolbar.js b/app/components/Editor/components/Toolbar/BlockToolbar.js index c9776860c..6f540e39d 100644 --- a/app/components/Editor/components/Toolbar/BlockToolbar.js +++ b/app/components/Editor/components/Toolbar/BlockToolbar.js @@ -61,7 +61,11 @@ class BlockToolbar extends Component { ev.stopPropagation(); this.props.editor.change(change => - change.removeNodeByKey(this.props.node.key) + change.setNodeByKey(this.props.node.key, { + type: 'paragraph', + text: '', + isVoid: false, + }) ); }