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

[Mobile]Update caret position on insert link #14317

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ export class RichText extends Component {
} );
if ( newContent && newContent !== this.props.value ) {
this.props.onChange( newContent );
if ( record.needsSelectionUpdate && record.start && record.end ) {
this.setState( { start: record.start, end: record.end } );
}
this.setState( {
needsSelectionUpdate: record.needsSelectionUpdate,
} );
} else {
// make sure the component rerenders without refreshing the text on gutenberg
// (this can trigger other events that might update the active formats on aztec)
Expand Down Expand Up @@ -525,6 +531,8 @@ export class RichText extends Component {
minHeight = style.minHeight;
}

const selection = this.state.needsSelectionUpdate ? { start: this.state.start, end: this.state.end } : null;

return (
<View>
{ isSelected && (
Expand All @@ -544,7 +552,7 @@ export class RichText extends Component {
...style,
minHeight: Math.max( minHeight, this.state.height ),
} }
text={ { text: html, eventCount: this.lastEventCount } }
text={ { text: html, eventCount: this.lastEventCount, selection } }
placeholder={ this.props.placeholder }
placeholderTextColor={ this.props.placeholderTextColor || styles[ 'editor-rich-text' ].textDecorationColor }
onChange={ this.onChange }
Expand Down
9 changes: 6 additions & 3 deletions packages/format-library/src/link/modal.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ class ModalLinkUI extends Component {

if ( isCollapsed( value ) && ! isActive ) { // insert link
const toInsert = applyFormat( create( { text: linkText } ), [ ...placeholderFormats, format ], 0, linkText.length );
onChange( insert( value, toInsert ) );
const newAttributes = insert( value, toInsert );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else if ( text !== getTextContent( slice( value ) ) ) { // edit text in selected link
const toInsert = applyFormat( create( { text } ), [ ...placeholderFormats, format ], 0, text.length );
onChange( insert( value, toInsert, value.start, value.end ) );
const newAttributes = insert( value, toInsert, value.start, value.end );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else { // transform selected text into link
onChange( applyFormat( value, [ ...placeholderFormats, format ] ) );
const newAttributes = applyFormat( value, [ ...placeholderFormats, format ] );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
}

if ( ! isValidHref( url ) ) {
Expand Down