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 - RichText - Set a default value for selection values #40581

Merged
merged 1 commit into from
Apr 26, 2022
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
13 changes: 8 additions & 5 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ export class RichText extends Component {
accessibilityLabel,
disableEditingMenu = false,
baseGlobalStyles,
selectionStart,
selectionEnd,
} = this.props;
const { currentFontSize } = this.state;

Expand All @@ -1065,12 +1067,14 @@ export class RichText extends Component {
defaultTextDecorationColor
);

const currentSelectionStart = selectionStart ?? 0;
const currentSelectionEnd = selectionEnd ?? 0;
let selection = null;
if ( this.needsSelectionUpdate ) {
this.needsSelectionUpdate = false;
selection = {
start: this.props.selectionStart,
end: this.props.selectionEnd,
start: currentSelectionStart,
end: currentSelectionEnd,
};

// On AztecAndroid, setting the caret to an out-of-bounds position will crash the editor so, let's check for some cases.
Expand All @@ -1086,12 +1090,11 @@ export class RichText extends Component {
brBeforeParaMatches[ 0 ].match( /br/g ) || []
).length;
if ( count > 0 ) {
let newSelectionStart =
this.props.selectionStart - count;
let newSelectionStart = currentSelectionStart - count;
if ( newSelectionStart < 0 ) {
newSelectionStart = 0;
}
let newSelectionEnd = this.props.selectionEnd - count;
let newSelectionEnd = currentSelectionEnd - count;
if ( newSelectionEnd < 0 ) {
newSelectionEnd = 0;
}
Expand Down