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

[Gutenberg] Account for the end of buffer marker #928

Merged
merged 3 commits into from
Sep 17, 2020
Merged
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
11 changes: 10 additions & 1 deletion aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown

val emptyEditTextBackspaceDetector = InputFilter { source, start, end, dest, dstart, dend ->
if (selectionStart == 0 && selectionEnd == 0
&& end == 0 && start == 0
&& start == 0
&& dstart == 0 && dend == 0
&& isCleanStringEmpty(source)
&& !isHandlingBackspaceEvent) {
isHandlingBackspaceEvent = true

Expand All @@ -654,6 +655,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
}
}

private fun isCleanStringEmpty(text: CharSequence): Boolean {
if ( isInGutenbergMode ) {
return (text.count() == 1 && text[0] == Constants.END_OF_BUFFER_MARKER)
} else {
return text.count() == 0
}
}

private fun handleBackspaceAndEnter(event: KeyEvent): Boolean {
if (event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER) {
// Check if the external listener has consumed the enter pressed event
Expand Down