Thanks Ella @iseulde, but unfortunately I have read through all of that before I posted here, and it was not much help.
Looking at the core/paragraph block code, it seems all the onSplit function is doing is creating a new block and returning it. when I do that nothing is happening, nor am I getting any errors.
I also wanted to point out that in the core/paragraph code, as well as the documentation, the onSplit function is stated to only receive one argument that is meant to be the chunk of content that is being split into the new block. In actuality this function receives two arguments, the first is the content before the cursor, and the second is the content after the cursor. But regardless, I am unable to actually split the content, as when I return the newly created block nothing is happening.
https://github.com/WordPress/gutenberg/blob/00c82b4809e9b8b9d8e90b7220ceb4c6371a0ff1/packages/block-library/src/paragraph/edit.js#L183-L195
In Paragraph block, there is a custom onSplit
method defined for RichText
component. onMerge
props in RichText
defintion uses mergeBlocks
callback passed down from BlockListBlock
component and its internally used action is defined here:
https://github.com/WordPress/gutenberg/blob/00c82b4809e9b8b9d8e90b7220ceb4c6371a0ff1/packages/block-editor/src/store/actions.js#L474-L487
Both onReplace
and onRemove
props in RichText
use onReplace
callback passed down from BlockListBlock
compoentn and its internally used action is defined here:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/store/actions.js#L221-L261
There is also merge
property which you can define for the block and it is used to merge the blocks if blocks are of the same type:
https://github.com/WordPress/gutenberg/blob/00c82b4809e9b8b9d8e90b7220ceb4c6371a0ff1/packages/block-library/src/paragraph/index.js#L30-L34
Are you trying to build it for WordPress 5.2 or the last Gutenberg release? Worth noting that the onSplit
prop has only recently been added. Before that you’d have to use __unstableOnSplit
. See https://github.com/WordPress/gutenberg/blob/wp/5.2/packages/block-library/src/paragraph/edit.js.
-
This reply was modified 4 years, 10 months ago by Ella.