Skip to content

Commit

Permalink
[Mobile] Treat a string that only contains the formatting marker as e…
Browse files Browse the repository at this point in the history
…mpty for block formatting (#27583)

* Treat a string that only contains the formatting marker as empty

* Update changelog
  • Loading branch information
chipsnyder authored and jd-alexander committed Dec 8, 2020
1 parent de0dec6 commit 4c34cf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 4c34cf4

Please sign in to comment.