From 2c8190705b71e89a7234401db6d3a6f2b6c56146 Mon Sep 17 00:00:00 2001 From: Ben Nguyen <87835859+btnguyenPersonal@users.noreply.github.com> Date: Wed, 9 Jul 2025 09:53:57 -0500 Subject: [PATCH] fix: keyboard hiding cursor on startup (#172) * fix: keyboard hiding cursor on startup * update changelog * lint * hacky delayed scroll, has to be a better way * use window inset listener * Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * only run keyboard listener once and check config.placeCursorToEnd * fix: keyboard hiding cursor on startup * update changelog * lint * hacky delayed scroll, has to be a better way * use window inset listener * Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * only run keyboard listener once and check config.placeCursorToEnd * Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> * add fits system windows * remove extra keyboard listener * remove unused imports * style: add empty line --------- Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> Co-authored-by: Naveen Singh --- CHANGELOG.md | 5 +++++ .../fossify/notes/fragments/TextFragment.kt | 18 ++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 1 + 3 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2c2c40..4858c3d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated translations +### Fixed + +- Fixed keyboard hiding cursor on long notes ([#164]) + ## [1.2.0] - 2025-05-07 ### Added @@ -71,3 +75,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#83]: https://github.com/FossifyOrg/Notes/issues/83 [#99]: https://github.com/FossifyOrg/Notes/issues/99 [#110]: https://github.com/FossifyOrg/Notes/issues/110 +[#164]: https://github.com/FossifyOrg/Notes/issues/164 diff --git a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt index 5442651c..dc969ce5 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -17,6 +17,8 @@ import android.view.ViewGroup import android.view.inputmethod.InputMethodManager import android.widget.ImageView import android.widget.TextView +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat import androidx.viewbinding.ViewBinding import org.fossify.commons.extensions.* import org.fossify.commons.views.MyEditText @@ -200,6 +202,22 @@ class TextFragment : NoteFragment() { setTextWatcher() } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupKeyboardListener() + } + + private fun setupKeyboardListener() { + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, insets -> + if (insets.isVisible(WindowInsetsCompat.Type.ime())) { + noteEditText.post { + noteEditText.bringPointIntoView(noteEditText.selectionEnd) + } + } + insets + } + } + fun setTextWatcher() { noteEditText.apply { removeTextChangedListener(textWatcher) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3091fed8..c69607d4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -2,6 +2,7 @@