Skip to content

Commit

Permalink
Adding onSelectionChange from store to RichText
Browse files Browse the repository at this point in the history
  • Loading branch information
etoledom authored and Tug committed May 2, 2019
1 parent d88977b commit d05b230
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { View, Platform } from 'react-native';
import { Component, RawHTML } from '@wordpress/element';
import { withInstanceId, compose } from '@wordpress/compose';
import { BlockFormatControls } from '@wordpress/block-editor';
import { withSelect } from '@wordpress/data';
import { withSelect, withDispatch } from '@wordpress/data';
import {
applyFormat,
getActiveFormat,
Expand Down Expand Up @@ -490,6 +490,7 @@ export class RichText extends Component {
this.lastContent = newContent;
this.props.onChange( this.lastContent );
}
this.props.onSelectionChange(realStart, realEnd);
}

isEmpty() {
Expand Down Expand Up @@ -778,6 +779,21 @@ const RichTextContainer = compose( [
onCaretVerticalPositionChange: context.onCaretVerticalPositionChange,
};
} ),
withDispatch( ( dispatch, {
clientId,
instanceId,
identifier = instanceId,
} ) => {
const {
selectionChange,
} = dispatch( 'core/block-editor' );

return {
onSelectionChange( start, end ) {
selectionChange( clientId, identifier, start, end );
},
};
} ),
] )( RichText );

RichTextContainer.Content = ( { value, format, tagName: Tag, multiline, ...props } ) => {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class HeadingEdit extends Component {
<HeadingToolbar minLevel={ 2 } maxLevel={ 5 } selectedLevel={ level } onChange={ ( newLevel ) => setAttributes( { level: newLevel } ) } />
</BlockControls>
<RichText
identifier="content"
tagName={ tagName }
value={ content }
isSelected={ this.props.isSelected }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class ParagraphEdit extends Component {
onAccessibilityTap={ this.props.onFocus }
>
<RichText
identifier="content"
tagName="p"
value={ content }
isSelected={ this.props.isSelected }
Expand Down

0 comments on commit d05b230

Please sign in to comment.