-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 Para/Heading blocks on enter.KEY - step 1 #10553
Changes from 3 commits
cd5c8c9
97b64a3
650ce00
a4203fc
6444a3e
5383932
aa791fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import { View } from 'react-native'; | |
import { __ } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { RichText } from '@wordpress/editor'; | ||
import { parse } from '@wordpress/blocks'; | ||
import { parse, createBlock } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -24,6 +24,25 @@ import './editor.scss'; | |
const minHeight = 50; | ||
|
||
class HeadingEdit extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.splitBlock = this.splitBlock.bind( this ); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
splitBlock( htmlText, start, end ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @daniloercoli , can we perhaps go closer to the interface of the web-side counterpart, wdyt? https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/heading/edit.js#L52. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, we will probably go toward that direction in the short future. For now i'd like to go with the current implementation, and get the ball rolling. |
||
const { | ||
insertBlocksAfter, | ||
} = this.props; | ||
|
||
if ( insertBlocksAfter ) { | ||
const blocks = []; | ||
blocks.push( createBlock( 'core/paragraph', { content: 'Test' } ) ); | ||
insertBlocksAfter( blocks ); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
attributes, | ||
|
@@ -55,6 +74,7 @@ class HeadingEdit extends Component { | |
content: newParaBlock.attributes.content, | ||
} ); | ||
} } | ||
onSplit={ this.splitBlock } | ||
onContentSizeChange={ ( event ) => { | ||
setAttributes( { aztecHeight: event.aztecHeight } ); | ||
} } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,31 @@ import { View } from 'react-native'; | |
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { parse } from '@wordpress/blocks'; | ||
import { parse, createBlock } from '@wordpress/blocks'; | ||
import { RichText } from '@wordpress/editor'; | ||
|
||
const minHeight = 50; | ||
|
||
class ParagraphEdit extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick #3: let's remove the extra line here |
||
this.splitBlock = this.splitBlock.bind( this ); | ||
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
splitBlock( htmlText, start, end ) { | ||
const { | ||
insertBlocksAfter, | ||
} = this.props; | ||
|
||
if ( insertBlocksAfter ) { | ||
const blocks = []; | ||
blocks.push( createBlock( 'core/paragraph', { content: 'Test' } ) ); | ||
insertBlocksAfter( blocks ); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
attributes, | ||
|
@@ -44,6 +63,7 @@ class ParagraphEdit extends Component { | |
} ); | ||
} | ||
} | ||
onSplit={ this.splitBlock } | ||
onContentSizeChange={ ( event ) => { | ||
setAttributes( { | ||
...this.props.attributes, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,22 @@ export class RichText extends Component { | |
} | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
onHTMLContentWithCursor( htmlText, cursorPosition ) { | ||
// Descriptive placeholder: This logic still needs to be implemented. | ||
onHTMLContentWithCursor( htmlText, start, end ) { | ||
if ( ! this.props.onSplit ) { | ||
// insert the \n char instead? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a ToDo comment here to make sure this is something we come back to at a follow up stage |
||
return; | ||
} | ||
this.splitContent( htmlText, start, end ); | ||
} | ||
|
||
splitContent( htmlText, start, end ) { | ||
const { onSplit } = this.props; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick #2: can we remove this extra line here? |
||
if ( ! onSplit ) { | ||
return; | ||
} | ||
|
||
onSplit( htmlText, start, end ); | ||
} | ||
|
||
onActiveFormatsChange( formats ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: can we remove this extra line here?