Browse Source

Make sure the selection in the plain text editor is inside the text bounds (#2959)

* Make sure the selection in the plain text editor is inside the text bounds

* Add changelog
pull/2961/head
Jorge Martin Espinosa 4 months ago committed by GitHub
parent
commit
19b6b924d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      changelog.d/2959.bugfix
  2. 6
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/markdown/MarkdownTextInput.kt

1
changelog.d/2959.bugfix

@ -0,0 +1 @@ @@ -0,0 +1 @@
Fix crash when restoring the selection values in the plain text editor.

6
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/components/markdown/MarkdownTextInput.kt

@ -90,13 +90,15 @@ fun MarkdownTextInput( @@ -90,13 +90,15 @@ fun MarkdownTextInput(
tag = TestTags.plainTextEditor.value // Needed for UI tests
setPadding(0)
setBackgroundColor(Color.TRANSPARENT)
setText(state.text.value())
val text = state.text.value()
setText(text)
inputType = InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_MULTI_LINE or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
if (canUpdateState) {
setSelection(state.selection.first, state.selection.last)
val textRange = 0..text.length
setSelection(state.selection.first.coerceIn(textRange), state.selection.last.coerceIn(textRange))
setOnFocusChangeListener { _, hasFocus ->
state.hasFocus = hasFocus
}

Loading…
Cancel
Save