Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Fix disappearing numbers with some keyboards #878

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.element.android.wysiwyg.display.TextDisplay
import io.element.android.wysiwyg.test.R
import io.element.android.wysiwyg.test.rules.createFlakyEmulatorRule
import io.element.android.wysiwyg.test.utils.*
import io.element.android.wysiwyg.utils.NBSP
import io.element.android.wysiwyg.utils.RustErrorCollector
import io.element.android.wysiwyg.view.models.InlineFormat
import io.element.android.wysiwyg.view.spans.LinkSpan
Expand Down Expand Up @@ -512,6 +513,16 @@ class EditorEditTextInputTests {
confirmVerified(textWatcher)
}

@Test
fun testWritingOnlyDigits() {
onView(withId(R.id.rich_text_edit_text))
.perform(ImeActions.setComposingText("1"))
.perform(ImeActions.setComposingText("2"))
.perform(ImeActions.setComposingText("3"))
.perform(ImeActions.commitText(" "))
.check(matches(withText("123$NBSP")))
}

@Test
fun testPasteImage() {
val imageUri = Uri.parse("content://fakeImage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.inputmethod.*
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.annotation.VisibleForTesting
import androidx.core.text.isDigitsOnly
import io.element.android.wysiwyg.internal.utils.TextRangeHelper
import io.element.android.wysiwyg.internal.viewmodel.EditorInputAction
import io.element.android.wysiwyg.internal.viewmodel.ReplaceTextResult
Expand Down Expand Up @@ -322,7 +323,12 @@ internal class InterceptInputConnection(
beginBatchEdit()
editable.removeFormattingSpans()
editable.replace(0, editable.length, charSequence)
setComposingRegion(compositionStart, compositionEnd)
val start = compositionStart.coerceIn(0, editable.length)
val end = compositionEnd.coerceIn(0, editable.length)
val newComposition = editable.substring(start, end)
if (newComposition.isEmpty() || !newComposition.isDigitsOnly()) {
jonnyandrew marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems a bit odd that replaceAll will not honour the given compositionStart and compositionEnd. Maybe the caller could be responsible for passing the right arguments? Or we can move the responsibility of setting the new composition out of replaceAll?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this on 88c81f9

setComposingRegion(start, end)
}
endBatchEdit()
}

Expand Down
Loading