Fixes: Allow BlockInsert on final block (previously didnt work in Prod)

This commit is contained in:
Tom Moor
2017-12-05 23:25:09 -08:00
parent e64ca3ca43
commit 5c38ff9e63
7 changed files with 30 additions and 17 deletions

View File

@@ -22,6 +22,8 @@ function findClosestRootNode(value, ev) {
if (bounds.top > ev.clientY) return previous;
previous = { node, element, bounds };
}
return previous;
}
@observer
@@ -100,10 +102,21 @@ export default class BlockInsert extends Component {
}
});
change
.collapseToStartOf(this.closestRootNode)
.collapseToEndOfPreviousBlock()
.insertBlock({ type: 'block-toolbar', isVoid: true });
change.collapseToStartOf(this.closestRootNode);
// 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.type === 'paragraph'
) {
change.setNodeByKey(this.closestRootNode.key, {
type: 'block-toolbar',
isVoid: true,
});
} else {
change.insertBlock({ type: 'block-toolbar', isVoid: true });
}
});
};

View File

@@ -1,3 +0,0 @@
// @flow
import ClickablePadding from './ClickablePadding';
export default ClickablePadding;

View File

@@ -72,7 +72,7 @@ class BlockToolbar extends Component {
editor.value.document.nodes.forEach(node => {
if (node.type === 'block-toolbar') {
change.removeNodeByKey(node.key);
change.removeNodeByKey(node.key, undefined, { normalize: false });
}
});