diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 53b3d85e5dbd6e..ee364e8c3beaeb 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -159,6 +159,8 @@ function RichTextWrapper( // retreived from the store on merge. // To do: fix this somehow. const { selectionStart, selectionEnd, isSelected } = useSelect( selector ); + const { getSelectionStart, getSelectionEnd, getBlockRootClientId } = + useSelect( blockEditorStore ); const { selectionChange } = useDispatch( blockEditorStore ); const multilineTag = getMultilineTag( multiline ); const adjustedAllowedFormats = getAllowedFormats( { @@ -195,6 +197,18 @@ function RichTextWrapper( const unset = start === undefined && end === undefined; if ( typeof start === 'number' || unset ) { + // If we are only setting the start (or the end below), which + // means a partial selection, and we're not updating a selection + // with the same client ID, abort. This means the selected block + // is a parent block. + if ( + end === undefined && + getBlockRootClientId( clientId ) !== + getBlockRootClientId( getSelectionEnd().clientId ) + ) { + return; + } + selection.start = { clientId, attributeKey: identifier, @@ -203,6 +217,14 @@ function RichTextWrapper( } if ( typeof end === 'number' || unset ) { + if ( + start === undefined && + getBlockRootClientId( clientId ) !== + getBlockRootClientId( getSelectionStart().clientId ) + ) { + return; + } + selection.end = { clientId, attributeKey: identifier,