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] Split pasted content between title and body #37169

Merged
merged 4 commits into from
Apr 13, 2023
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
39 changes: 31 additions & 8 deletions packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PostTitle extends Component {
super( props );

this.setRef = this.setRef.bind( this );
this.onPaste = this.onPaste.bind( this );
}
componentDidUpdate( prevProps ) {
// Unselect if any other block is selected and blur the RichText.
Expand Down Expand Up @@ -60,16 +61,31 @@ class PostTitle extends Component {
this.props.onSelect();
}

onPaste( { value, onChange, plainText } ) {
onPaste( { value, onChange, plainText, html } ) {
const { title, onInsertBlockAfter, onUpdate } = this.props;

const content = pasteHandler( {
HTML: html,
plainText,
mode: 'INLINE',
tagName: 'p',
} );

if ( typeof content === 'string' ) {
const valueToInsert = create( { html: content } );
onChange( insert( value, valueToInsert ) );
if ( content.length ) {
if ( typeof content === 'string' ) {
const valueToInsert = create( { html: content } );
onChange( insert( value, valueToInsert ) );
} else {
const [ firstBlock ] = content;
if (
! title &&
( firstBlock.name === 'core/heading' ||
firstBlock.name === 'core/paragraph' )
) {
onUpdate( firstBlock.attributes.content );
onInsertBlockAfter( content.slice( 1 ) );
} else {
onInsertBlockAfter( content );
}
}
}
}

Expand Down Expand Up @@ -181,17 +197,18 @@ export default compose(

return {
postType: getEditedPostAttribute( 'type' ),
title: getEditedPostAttribute( 'title' ),
isAnyBlockSelected: !! selectedId,
isSelected: isPostTitleSelected(),
isDimmed: selectionIsNested,
globalStyles,
};
} ),
withDispatch( ( dispatch ) => {
const { undo, redo, togglePostTitleSelection } =
const { undo, redo, togglePostTitleSelection, editPost } =
dispatch( editorStore );

const { clearSelectedBlock, insertDefaultBlock } =
const { clearSelectedBlock, insertDefaultBlock, insertBlocks } =
dispatch( blockEditorStore );

return {
Expand All @@ -207,6 +224,12 @@ export default compose(
onUnselect() {
togglePostTitleSelection( false );
},
onUpdate( title ) {
editPost( { title } );
},
onInsertBlockAfter( blocks ) {
insertBlocks( blocks, 0 );
},
};
} ),
withInstanceId,
Expand Down