-
Notifications
You must be signed in to change notification settings - Fork 26
[Android] Apply a better solution for #878 #881
[Android] Apply a better solution for #878 #881
Conversation
- 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.
There was a problem hiding this 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!
...d/library/src/main/java/io/element/android/wysiwyg/inputhandlers/InterceptInputConnection.kt
Show resolved
Hide resolved
...d/library/src/main/java/io/element/android/wysiwyg/inputhandlers/InterceptInputConnection.kt
Show resolved
Hide resolved
replaceAll(result.text) | ||
val editorSelectionIndex = editorIndex(result.selection.first, editable) | ||
setSelection(editorSelectionIndex, editorSelectionIndex) | ||
setComposingRegion(editorSelectionIndex, editorSelectionIndex) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…Digits`, since it's way less flaky this way
Kudos, SonarCloud Quality Gate passed! |
ComposerModel
into an editor one.replaceAll
.isDigitOnly
check at theonHardwareCharacterKey
method, since it's where the logic differs from the IME and setting it insetComposingText
instead causes issues with Gboard: if you type a word, add a space and start typing a number, bothsetComposignText
andcommitText
will be called for it and it'll be added twice.