Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Narrow down blur on unmount to replaceable only #16151

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import memize from 'memize';
/**
* WordPress dependencies
*/
import {
isUnmodifiedDefaultBlock,
} from '@wordpress/blocks';
import { Component, RawHTML } from '@wordpress/element';
import { withInstanceId, compose } from '@wordpress/compose';
import { BlockFormatControls } from '@wordpress/block-editor';
Expand Down Expand Up @@ -701,8 +704,8 @@ export class RichText extends Component {
}

componentWillUnmount() {
if ( this._editor.isFocused() ) {
// this._editor.blur();
if ( this._editor.isFocused() && this.props.shouldBlurOnUnmount ) {
this._editor.blur();
}
}

Expand Down Expand Up @@ -875,6 +878,7 @@ const RichTextContainer = compose( [
const {
getSelectionStart,
getSelectionEnd,
__unstableGetBlockWithoutInnerBlocks,
} = select( 'core/block-editor' );

const selectionStart = getSelectionStart();
Expand All @@ -887,12 +891,19 @@ const RichTextContainer = compose( [
);
}

// If the block of this RichText is unmodified then it's a candidate for replacing when adding a new block.
// In order to fix https://github.com/wordpress-mobile/gutenberg-mobile/issues/1126, let's blur on unmount in that case.
// This apparently assumes functionality the BlockHlder actually
const block = clientId && __unstableGetBlockWithoutInnerBlocks( clientId );
const shouldBlurOnUnmount = block && isSelected && isUnmodifiedDefaultBlock( block );

return {
formatTypes: getFormatTypes(),
selectionStart: isSelected ? selectionStart.offset : undefined,
selectionEnd: isSelected ? selectionEnd.offset : undefined,
isSelected,
blockIsSelected,
shouldBlurOnUnmount,
};
} ),
withDispatch( ( dispatch, {
Expand Down