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] Treat a string that only contains the formatting marker as empty for block formatting #27583

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {

Expand All @@ -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) {}
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down