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

Conversation

jmartinesp
Copy link
Contributor

Don't set composition if the replaced text is all digits. This seems to be the default behaviour in all keyboards I've tested (Gboard, AnySoftKeyboard, Simple Keyboard...), and prevents the composition (the last digit) from being replaced with a whitespace.

Fixes element-hq/element-x-android#1415.

@jmartinesp jmartinesp requested a review from a team November 20, 2023 07:16
@jmartinesp jmartinesp force-pushed the fix/jme/android-writing-numbers branch from daff96f to 1bbf8dc Compare November 20, 2023 07:16
@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c698b1b) 87.43% compared to head (88c81f9) 87.28%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #878      +/-   ##
============================================
- Coverage     87.43%   87.28%   -0.16%     
- Complexity      406      409       +3     
============================================
  Files           165      133      -32     
  Lines         18956    17360    -1596     
  Branches       1045      405     -640     
============================================
- Hits          16575    15152    -1423     
+ Misses         2087     1937     -150     
+ Partials        294      271      -23     
Flag Coverage Δ
uitests 65.56% <100.00%> (-5.53%) ⬇️
uitests-android 65.56% <100.00%> (+0.08%) ⬆️
uitests-ios ?
unittests 86.64% <ø> (+1.11%) ⬆️
unittests-android 45.56% <ø> (ø)
unittests-ios ?
unittests-rust 89.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jonnyandrew jonnyandrew left a comment

Choose a reason for hiding this comment

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

Thanks for finding the cause! It was a bit unexpected that replaceText would also update the composing region. I wonder if there's a way to make this a bit less opaque. But feel free to ignore these suggestions.

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()) {
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

This was actually hiding an issue with how the composition is set in `deleteSurroundingText`.
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@jmartinesp jmartinesp merged commit ecb2bb0 into main Nov 20, 2023
7 checks passed
@jmartinesp jmartinesp deleted the fix/jme/android-writing-numbers branch November 20, 2023 11:35
@@ -280,7 +281,7 @@ internal class InterceptInputConnection(
processInput(EditorInputAction.BackPress)
}
if (result != null) {
replaceAll(result.text, 0, editable.length)
replaceAll(result.text, result.selection.first, result.selection.last)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this fixes a separate bug altogether?

Just to double check, is this new logic safe i.e. are the indices in result.selection guaranteed to be valid within result.text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, maybe they're not. I forgot these were composer indexes that need to be translated to editor ones. Damn, I'll create a new PR with a fix for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #881

jmartinesp added a commit that referenced this pull request Nov 20, 2023
jmartinesp added a commit that referenced this pull request Nov 20, 2023
* Ensure editor indexes are used for selection and composition:

- Removes the responsibility of setting the composition from `replaceAll`.
- Also removes `beginBatchEdit` and `endBatchEdit` so it's the calling functions who should manage that.
- Calculate new indexes for selection and composition using `fun editorIndex(composerIndex, editable)`, do it just once per operation.

* Apply a better solution for #878

* Add better tests

* Simplify code

* Input the while text as key presses in `testHardwareKeyboardInputWithDigits`, since it's way less flaky this way
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RTE stops you from typing 166
3 participants