From fcffd6c6e7e661aa0cf3efe665f3deab976f68ee Mon Sep 17 00:00:00 2001 From: Gerardo Date: Wed, 13 Mar 2024 15:06:18 +0100 Subject: [PATCH 1/5] ReactNativeAztec - Add selectionStart and selectionEnd params to the onChange callback --- .../mobile/ReactNativeAztec/AztecReactTextChangedEvent.kt | 6 +++++- .../mobile/ReactNativeAztec/ReactAztecManager.java | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 1e3e90c3a48442..e5bb145789144f 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 @@ -743,7 +743,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( From 62574e0981e33a585df316111328ec10e57f99f6 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Wed, 13 Mar 2024 15:07:11 +0100 Subject: [PATCH 2/5] RichText - Add workaround for Android when backspacing at the start 0 position where it would fail to merge with the previous blocks for some keyboards. --- .../components/rich-text/native/index.native.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 7a775cad346488..3c166e0f6e5c18 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 ); From a816edcf5ce8df3b1e3ea2969a76b251d847187e Mon Sep 17 00:00:00 2001 From: Gerardo Date: Wed, 13 Mar 2024 15:17:38 +0100 Subject: [PATCH 3/5] Update Aztec ref --- packages/react-native-aztec/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-aztec/android/build.gradle b/packages/react-native-aztec/android/build.gradle index d1aa9fd77c91f8..517175ce4b2a48 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 = 'v1.9.0' + aztecVersion = 'fix_gutenberg-backspace-styles-d845fbf4989acc4fbfddc877fd67c7671412fbe0' wordpressUtilsVersion = '3.3.0' // main From 6b2208977857fdd5d5eb5063b1971aa240806457 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 27 May 2024 17:01:12 +0200 Subject: [PATCH 4/5] Mobile - ReactAztecText - Call removeEndOffMArkerAdder on initialization --- .../org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java | 2 ++ 1 file changed, 2 insertions(+) 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); From 22ec3123cd143e86cc6ba88a3f505353b6078aa2 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Mon, 27 May 2024 17:19:07 +0200 Subject: [PATCH 5/5] Update Aztec version --- packages/react-native-aztec/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-aztec/android/build.gradle b/packages/react-native-aztec/android/build.gradle index 4cc66d9a0e57da..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 = 'fix_gutenberg-backspace-styles-fac06be6604f8cb24d34878c9961fa8503fd0e33' + aztecVersion = '1077-fac06be6604f8cb24d34878c9961fa8503fd0e33' wordpressUtilsVersion = '3.3.0' // main