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

Fix removeSpan crash on Android #469

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

public class MarkdownTextWatcher implements TextWatcher {
private final MarkdownUtils mMarkdownUtils;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

private boolean mShouldSkip = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also remove this field as it's no longer used.

private String mPreviousText;

public MarkdownTextWatcher(@NonNull MarkdownUtils markdownUtils) {
mMarkdownUtils = markdownUtils;
Expand All @@ -22,17 +23,18 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mShouldSkip) {
return;
}
if (s instanceof SpannableStringBuilder) {
mMarkdownUtils.applyMarkdownFormatting((SpannableStringBuilder) s);
mShouldSkip = true;
}

}

@Override
public void afterTextChanged(Editable editable) {
mShouldSkip = false;
if (editable instanceof SpannableStringBuilder) {
String currentText = editable.toString();
if (currentText.equals(mPreviousText)) {
return;
wildan-m marked this conversation as resolved.
Show resolved Hide resolved
}
mMarkdownUtils.applyMarkdownFormatting((SpannableStringBuilder) editable);
mPreviousText = currentText;
}
}
}
Loading