diff --git a/packages/block-editor/src/components/rich-text/native/index.native.js b/packages/block-editor/src/components/rich-text/native/index.native.js index 26d39a0c6058b4..f9175d64a21904 100644 --- a/packages/block-editor/src/components/rich-text/native/index.native.js +++ b/packages/block-editor/src/components/rich-text/native/index.native.js @@ -312,15 +312,24 @@ export class RichText extends Component { if ( this.shouldDropEventFromAztec( event, 'onChange' ) ) { return; } + const { eventCount, text, selectionStart, selectionEnd } = + event.nativeEvent; + + // On Android backspacing after selection doesn't work as expected in some keyboards + // this makes sure to update the current selection the native AztecView has before merging. + if ( ! this.isIOS && selectionStart === 0 && selectionEnd === 0 ) { + this.selectionStart = selectionStart; + this.selectionEnd = selectionEnd; + this.props.onSelectionChange( selectionStart, selectionEnd ); + } - const contentWithoutRootTag = this.removeRootTagsProducedByAztec( - event.nativeEvent.text - ); + const contentWithoutRootTag = + this.removeRootTagsProducedByAztec( text ); // On iOS, onChange can be triggered after selection changes, even though there are no content changes. if ( contentWithoutRootTag === this.value?.toString() ) { return; } - this.lastEventCount = event.nativeEvent.eventCount; + this.lastEventCount = eventCount; this.comesFromAztec = true; this.firedAfterTextChanged = true; // The onChange event always fires after the fact. this.onTextUpdate( event ); diff --git a/packages/react-native-aztec/android/build.gradle b/packages/react-native-aztec/android/build.gradle index 45312e89f0b9d9..9b1c886b3388fb 100644 --- a/packages/react-native-aztec/android/build.gradle +++ b/packages/react-native-aztec/android/build.gradle @@ -11,7 +11,7 @@ buildscript { espressoVersion = '3.0.1' // libs - aztecVersion = 'v2.1.2' + aztecVersion = '1077-fac06be6604f8cb24d34878c9961fa8503fd0e33' wordpressUtilsVersion = '3.3.0' // main diff --git a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/AztecReactTextChangedEvent.kt b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/AztecReactTextChangedEvent.kt index 1cf6afdf7b1f3b..9e7c7c87d535db 100644 --- a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/AztecReactTextChangedEvent.kt +++ b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/AztecReactTextChangedEvent.kt @@ -13,7 +13,9 @@ class AztecReactTextChangedEvent( viewId: Int, private val mText: String, private val mEventCount: Int, - private val mMostRecentChar: Char? + private val mMostRecentChar: Char?, + private val mSelectionStart: Int, + private val mSelectionEnd: Int ) : Event(viewId) { override fun getEventName(): String = "topAztecChange" @@ -30,5 +32,7 @@ class AztecReactTextChangedEvent( if (mMostRecentChar != null) { putInt("keyCode", mMostRecentChar.toInt()) } + putInt("selectionStart", mSelectionStart) + putInt("selectionEnd", mSelectionEnd) } } diff --git a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java index ed2a0284c17822..62750c00517cf9 100644 --- a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java +++ b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java @@ -760,7 +760,9 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { mEditText.getId(), mEditText.toHtml(mEditText.getText(), false), currentEventCount, - singleCharacterHasBeenAdded ? s.charAt(start + before) : null)); + singleCharacterHasBeenAdded ? s.charAt(start + before) : null, + mEditText.getSelectionStart(), + mEditText.getSelectionStart())); mEventDispatcher.dispatchEvent( new ReactTextInputEvent( diff --git a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java index e55f27d63b529f..1fd54cc35e3002 100644 --- a/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java +++ b/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java @@ -105,6 +105,8 @@ public ReactAztecText(ThemedReactContext reactContext) { setGutenbergMode(true); + removeEndOfBufferMarkerAdder(); + // don't auto-focus when Aztec becomes visible. // Needed on rotation and multiple Aztec instances to avoid losing the exact care position. setFocusOnVisible(false);