From 4c34cf4b726bf2deabbe2d17e192f31473214c69 Mon Sep 17 00:00:00 2001 From: Chip Date: Tue, 8 Dec 2020 15:17:58 -0500 Subject: [PATCH] [Mobile] Treat a string that only contains the formatting marker as empty for block formatting (#27583) * Treat a string that only contains the formatting marker as empty * Update changelog --- .../mobile/ReactNativeAztec/ReactAztecManager.java | 10 ++++++++-- packages/react-native-editor/CHANGELOG.md | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) 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 7d39098ae8c809..edf30a01154e86 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 @@ -41,11 +41,11 @@ import com.facebook.react.views.text.ReactFontManager; import com.facebook.react.views.text.ReactTextUpdate; import com.facebook.react.views.textinput.ReactContentSizeChangedEvent; -import com.facebook.react.views.textinput.ReactTextChangedEvent; import com.facebook.react.views.textinput.ReactTextInputEvent; import com.facebook.react.views.textinput.ReactTextInputManager; import com.facebook.react.views.textinput.ScrollWatcher; +import org.wordpress.aztec.Constants; import org.wordpress.aztec.formatting.LinkFormatter; import org.wordpress.aztec.glideloader.GlideImageLoader; import org.wordpress.aztec.glideloader.GlideVideoThumbnailLoader; @@ -677,7 +677,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { if (mPreviousText.length() == 0 - && !TextUtils.isEmpty(newText) + && !isTextEmpty(newText) && !TextUtils.isEmpty(mEditText.getTagName()) && mEditText.getSelectedStyles().isEmpty()) { @@ -691,6 +691,12 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } } + // This accounts for the END_OF_BUFFER_MARKER that is added to blocks to maintain the styling, if the only char + // is the zero width marker then it is considered "empty" + private boolean isTextEmpty(String text) { + return text.length() == 0 || (text.length() == 1 && text.charAt(0) == Constants.INSTANCE.getEND_OF_BUFFER_MARKER()); + } + @Override public void afterTextChanged(Editable s) {} } diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index 24caa6a16beb7c..155780077c51ab 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -15,6 +15,7 @@ For each user feature we should also add a importance categorization label to i * [**] Button block - Add link picker to the block settingsĀ [#26206] * [**] Support to render background/text colors in Group, Paragraph and Quote blocksĀ [#25994] * [*] Fix theme colors syncing with the editor [#26821] +* [**] Fix issue where a blocks would disappear when deleting all of the text inside without requiring the extra backspace to remove the block. [#27583] ## 1.41.0