Skip to content

Commit 1f64122

Browse files
only run keyboard listener once and check config.placeCursorToEnd
1 parent 5b67a7a commit 1f64122

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,17 @@ class TextFragment : NoteFragment() {
206206
}
207207

208208
private fun setupKeyboardListener() {
209-
requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets ->
210-
scrollToEndOfNote()
211-
view.onApplyWindowInsets(insets)
209+
requireActivity().window.decorView.apply {
210+
setOnApplyWindowInsetsListener { view, insets ->
211+
val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets)
212+
if (windowInsets.isVisible(WindowInsetsCompat.Type.ime())) {
213+
if (config!!.placeCursorToEnd) {
214+
scrollToEndOfNote()
215+
}
216+
setOnApplyWindowInsetsListener(null) // clear to avoid scrolling every time
217+
}
218+
view.onApplyWindowInsets(insets)
219+
}
212220
}
213221
}
214222

0 commit comments

Comments
 (0)