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

[Android] Apply a better solution for #878 #881

Conversation

jmartinesp
Copy link
Contributor

  • Make sure we translate any index that comes from the ComposerModel into an editor one.
  • Move setting the composing region out of replaceAll.
  • Apply the isDigitOnly check at the onHardwareCharacterKey method, since it's where the logic differs from the IME and setting it in setComposingText instead causes issues with Gboard: if you type a word, add a space and start typing a number, both setComposignText and commitText will be called for it and it'll be added twice.

- 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.
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.

This looks like it will be a great improvement, thank you!

Comment on lines +277 to +280
replaceAll(result.text)
val editorSelectionIndex = editorIndex(result.selection.first, editable)
setSelection(editorSelectionIndex, editorSelectionIndex)
setComposingRegion(editorSelectionIndex, editorSelectionIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it's reasonable to assume that selection.first == selection.last but it feels a bit strange not to trust the Rust model. Anyway, it's not a big deal but if we did manage to refactor the result handling into a function (as mentioned in my other comment), that might fix this.

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 mostly did it following what was already there and trying to avoid calculating indexes several times, I see no need to convert twice index x from the composer to get the same y editor index in both cases, doing extra work. Also, the composer doesn't have the concept of 'composition', so we some times may have to get a bit creative with selections.

In the future we could add this concept to the composer, since it seems to be used in both Android an iOS (on iOS I believe it's called 'marked text'), but right now that would be way too much work for the time we have to work on the library.

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 320f5c1 into main Nov 20, 2023
7 checks passed
@jmartinesp jmartinesp deleted the fix/jme/improve-fix-for-digits-and-ensure-indexes-are-converted branch November 20, 2023 15:40
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.

2 participants