From bed52805bfb07d125b03c85df472cb518344e5a2 Mon Sep 17 00:00:00 2001 From: Stefanos Togkoulidis Date: Thu, 10 Mar 2022 17:09:42 +0200 Subject: [PATCH 1/2] Pass the ol start and reversed to native RichText too --- .../block-editor/src/components/rich-text/index.native.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index f20e387819621..19286a4d537ff 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -66,6 +66,8 @@ function RichTextWrapper( { children, tagName, + start, + reversed, value: originalValue, onChange: originalOnChange, isSelected: originalIsSelected, @@ -575,6 +577,8 @@ function RichTextWrapper( selectionEnd={ selectionEnd } onSelectionChange={ onSelectionChange } tagName={ tagName } + start={ start } + reversed={ reversed } placeholder={ placeholder } allowedFormats={ adjustedAllowedFormats } withoutInteractiveFormatting={ withoutInteractiveFormatting } From 7ce18a8217e52fcf8bf8e122f3fdcc93a88c124d Mon Sep 17 00:00:00 2001 From: Stefanos Togkoulidis Date: Thu, 10 Mar 2022 18:06:32 +0200 Subject: [PATCH 2/2] Rename local vars to avoid shadowing 'start' --- .../src/components/rich-text/index.native.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index 19286a4d537ff..8fc0829b1b17c 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -216,8 +216,13 @@ function RichTextWrapper( } const onSelectionChange = useCallback( - ( start, end ) => { - selectionChange( clientId, identifier, start, end ); + ( selectionChangeStart, selectionChangeEnd ) => { + selectionChange( + clientId, + identifier, + selectionChangeStart, + selectionChangeEnd + ); }, [ clientId, identifier ] ); @@ -351,9 +356,11 @@ function RichTextWrapper( onChange( insertLineSeparator( value ) ); } } else { - const { text, start, end } = value; + const { text, start: splitStart, end: splitEnd } = value; const canSplitAtEnd = - onSplitAtEnd && start === end && end === text.length; + onSplitAtEnd && + splitStart === splitEnd && + splitEnd === text.length; if ( shiftKey || ( ! canSplit && ! canSplitAtEnd ) ) { if ( ! disableLineBreaks ) { @@ -532,15 +539,18 @@ function RichTextWrapper( return; } - const { start, text } = value; - const characterBefore = text.slice( start - 1, start ); + const { start: startPosition, text } = value; + const characterBefore = text.slice( + startPosition - 1, + startPosition + ); // The character right before the caret must be a plain space. if ( characterBefore !== ' ' ) { return; } - const trimmedTextBefore = text.slice( 0, start ).trim(); + const trimmedTextBefore = text.slice( 0, startPosition ).trim(); const prefixTransforms = getBlockTransforms( 'from' ).filter( ( { type } ) => type === 'prefix' ); @@ -555,7 +565,9 @@ function RichTextWrapper( return; } - const content = valueToFormat( slice( value, start, text.length ) ); + const content = valueToFormat( + slice( value, startPosition, text.length ) + ); const block = transformation.transform( content ); onReplace( [ block ] );