From 89f94f0407dffba19227cdfeba8a5981b1570344 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 15 Apr 2019 23:40:10 -0300 Subject: [PATCH 1/2] prevent execution of filter for programmatically added new lines --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index 2b657a45f..cbf69bb77 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -462,8 +462,11 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown // https://android-review.googlesource.com/c/platform/frameworks/base/+/634929 val dynamicLayoutCrashPreventer = InputFilter { source, start, end, dest, dstart, dend -> var temp : CharSequence? = null - if (!bypassCrashPreventerInputFilter && dstart == dend && dest.length > dend+1) { + if (!bypassCrashPreventerInputFilter + && dstart == dend && dest.length > dend+1 + && source != Constants.NEWLINE_STRING) { // dstart == dend means this is an insertion + // but avoid handling anything if it's a // if there are any images right after the destination position, hack the text val spans = dest.getSpans(dstart, dend+1, AztecImageSpan::class.java) if (spans.isNotEmpty()) { From 37b282a2f08d604d6e2ef3f826a9e9bdf52ab49b Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 15 Apr 2019 23:53:01 -0300 Subject: [PATCH 2/2] ammended comment --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index cbf69bb77..eb2fd0c3a 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -466,7 +466,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown && dstart == dend && dest.length > dend+1 && source != Constants.NEWLINE_STRING) { // dstart == dend means this is an insertion - // but avoid handling anything if it's a + // avoid handling anything if it's a newline // if there are any images right after the destination position, hack the text val spans = dest.getSpans(dstart, dend+1, AztecImageSpan::class.java) if (spans.isNotEmpty()) {