From e5dacfea3886dd8d06c23140301b9ebf143a0b0b Mon Sep 17 00:00:00 2001 From: khaykov Date: Tue, 26 Nov 2024 19:53:51 -0600 Subject: [PATCH 1/6] Improve handling of selection of empty editor with only END_OF_BUFFER_MARKER. --- .../src/main/kotlin/org/wordpress/aztec/AztecText.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index a326e684a..867e19420 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1238,6 +1238,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown } if (length() != 0) { + if((length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)){ + return + } + // if the text end has the marker, let's make sure the cursor never includes it or surpasses it if ((selStart == length() || selEnd == length()) && text[length() - 1] == Constants.END_OF_BUFFER_MARKER) { var start = selStart @@ -1972,14 +1976,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown return super.onTextContextMenuItem(id) } } - android.R.id.selectAll -> { - return if (text.toString() == Constants.END_OF_BUFFER_MARKER.toString()) { - deleteInlineStyleFromTheBeginning() - return true - } else { - super.onTextContextMenuItem(id) - } - } else -> return super.onTextContextMenuItem(id) } From 7a365a5c67a6b232b1ee742e7227d6d332666bac Mon Sep 17 00:00:00 2001 From: khaykov Date: Tue, 26 Nov 2024 20:09:01 -0600 Subject: [PATCH 2/6] Revert fix for select all. --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index 867e19420..618c5f37f 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1976,6 +1976,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown return super.onTextContextMenuItem(id) } } + android.R.id.selectAll -> { + return if (text.toString() == Constants.END_OF_BUFFER_MARKER.toString()) { + deleteInlineStyleFromTheBeginning() + return true + } else { + super.onTextContextMenuItem(id) + } + } else -> return super.onTextContextMenuItem(id) } From 1e415bd320262a3a03259bdaecdc41b70d6e39fa Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 27 Nov 2024 12:59:46 -0600 Subject: [PATCH 3/6] Fixed lint issues. --- 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 618c5f37f..9d4d3fcb9 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1238,7 +1238,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown } if (length() != 0) { - if((length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)){ + if ((length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) { return } From cae619ec17ed62def5b38f7abb10a8ad6ff313d4 Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 27 Nov 2024 13:04:29 -0600 Subject: [PATCH 4/6] added comment --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index 9d4d3fcb9..9bc3f4238 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1238,6 +1238,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown } if (length() != 0) { + // do not set selection when we try to select end of buffer marker in empty editor if ((length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) { return } From 3c5f72f2af49d7ff40783d34c44ef04aca092cff Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 27 Nov 2024 15:03:54 -0600 Subject: [PATCH 5/6] Refined fix to only apply to exact 0 to 1 selection. --- 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 9bc3f4238..bb3726c67 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1239,7 +1239,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown if (length() != 0) { // do not set selection when we try to select end of buffer marker in empty editor - if ((length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) { + if (selStart == 0 && selEnd == 1 && (length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) { return } From 121a1b6bb89019bdee0378cd376a70c808462f57 Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 27 Nov 2024 15:10:18 -0600 Subject: [PATCH 6/6] Prevent selection of EOB marker. --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index bb3726c67..c84284aad 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -1240,6 +1240,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown if (length() != 0) { // do not set selection when we try to select end of buffer marker in empty editor if (selStart == 0 && selEnd == 1 && (length() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)) { + deleteInlineStyleFromTheBeginning() return }