From df1cd5633d350a696c00769e1e7b52662aff623c Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 13:32:58 -0500 Subject: [PATCH 01/19] fix: keyboard hiding cursor on startup --- .../main/kotlin/org/fossify/notes/activities/MainActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 4b3a8ad8..262e5a91 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,6 +23,7 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem +import android.view.WindowManager import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -549,6 +550,7 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) From 726761491ebb778249931b87cd046b4489cab0e8 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 13:56:36 -0500 Subject: [PATCH 02/19] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 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 From 1f605e243105bfba797193cb8b601cec216d9fe0 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 14:01:06 -0500 Subject: [PATCH 03/19] lint --- .../main/kotlin/org/fossify/notes/activities/MainActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 262e5a91..108df9df 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,7 +23,8 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem -import android.view.WindowManager +import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE +import android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -550,7 +551,7 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + window.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE or SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) From 2c03abce1bebc640f48971fcf45394f9c47d7a96 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sat, 5 Jul 2025 09:40:28 -0500 Subject: [PATCH 04/19] hacky delayed scroll, has to be a better way --- .../kotlin/org/fossify/notes/activities/MainActivity.kt | 3 --- .../kotlin/org/fossify/notes/fragments/TextFragment.kt | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 108df9df..4b3a8ad8 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,8 +23,6 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem -import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE -import android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -551,7 +549,6 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { - window.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE or SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) 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 bf7ebcdd..9bdce4bb 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -2,6 +2,7 @@ package org.fossify.notes.fragments import android.annotation.SuppressLint import android.content.Context +import android.graphics.Rect import android.graphics.Typeface import android.os.Bundle import android.text.Editable @@ -169,6 +170,12 @@ class TextFragment : NoteFragment() { requestFocus() val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) + + val rect = Rect() + noteEditText.getFocusedRect(rect) + binding.notesScrollview.postDelayed({ + binding.notesScrollview.smoothScrollTo(0, rect.bottom) + }, 1000) } } } From aa79e59437cb711ad3fb5360a504780abeffdb1d Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sat, 5 Jul 2025 12:51:54 -0500 Subject: [PATCH 05/19] use window inset listener --- .../fossify/notes/fragments/TextFragment.kt | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) 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 9bdce4bb..f27cf65f 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -19,6 +19,9 @@ import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.ImageView import android.widget.TextView +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsAnimationCompat +import androidx.core.view.WindowInsetsCompat import androidx.viewbinding.ViewBinding import org.fossify.commons.extensions.* import org.fossify.commons.views.MyEditText @@ -167,15 +170,10 @@ class TextFragment : NoteFragment() { if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) { onGlobalLayout { if (activity?.isDestroyed == false) { + setupKeyboardListener() requestFocus() val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) - - val rect = Rect() - noteEditText.getFocusedRect(rect) - binding.notesScrollview.postDelayed({ - binding.notesScrollview.smoothScrollTo(0, rect.bottom) - }, 1000) } } } @@ -209,6 +207,35 @@ class TextFragment : NoteFragment() { setTextWatcher() } + private fun setupKeyboardListener() { + requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets -> + scrollToEndOfNote() + view.onApplyWindowInsets(insets) + } + + val callback = + object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) { + override fun onPrepare(animation: WindowInsetsAnimationCompat) { + super.onPrepare(animation) + scrollToEndOfNote() + } + + override fun onProgress( + insets: WindowInsetsCompat, + runningAnimations: MutableList, + ) = insets + } + ViewCompat.setWindowInsetsAnimationCallback(requireActivity().window.decorView, callback) + } + + private fun scrollToEndOfNote() { + val rect = Rect() + noteEditText.getFocusedRect(rect) + binding.notesScrollview.post { + binding.notesScrollview.scrollTo(0, rect.bottom) + } + } + fun setTextWatcher() { noteEditText.apply { removeTextChangedListener(textWatcher) From b088ea484abd937f9e2cb6ae35cb76650d554631 Mon Sep 17 00:00:00 2001 From: Ben Nguyen <87835859+btnguyenPersonal@users.noreply.github.com> Date: Sun, 6 Jul 2025 07:41:50 -0500 Subject: [PATCH 06/19] Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> --- .../org/fossify/notes/fragments/TextFragment.kt | 14 -------------- 1 file changed, 14 deletions(-) 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 f27cf65f..cf2cd0e1 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -212,20 +212,6 @@ class TextFragment : NoteFragment() { scrollToEndOfNote() view.onApplyWindowInsets(insets) } - - val callback = - object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) { - override fun onPrepare(animation: WindowInsetsAnimationCompat) { - super.onPrepare(animation) - scrollToEndOfNote() - } - - override fun onProgress( - insets: WindowInsetsCompat, - runningAnimations: MutableList, - ) = insets - } - ViewCompat.setWindowInsetsAnimationCallback(requireActivity().window.decorView, callback) } private fun scrollToEndOfNote() { From ae80130aa11dcf5cf11936568ec2f2a12079be8b Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sun, 6 Jul 2025 09:38:49 -0500 Subject: [PATCH 07/19] only run keyboard listener once and check config.placeCursorToEnd --- .../org/fossify/notes/fragments/TextFragment.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 cf2cd0e1..92520157 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -208,9 +208,17 @@ class TextFragment : NoteFragment() { } private fun setupKeyboardListener() { - requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets -> - scrollToEndOfNote() - view.onApplyWindowInsets(insets) + requireActivity().window.decorView.apply { + setOnApplyWindowInsetsListener { view, insets -> + val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets) + if (windowInsets.isVisible(WindowInsetsCompat.Type.ime())) { + if (config!!.placeCursorToEnd) { + scrollToEndOfNote() + } + setOnApplyWindowInsetsListener(null) // clear to avoid scrolling every time + } + view.onApplyWindowInsets(insets) + } } } From 322a717e899e2fb2e7600dd690a0a94026c26611 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 13:32:58 -0500 Subject: [PATCH 08/19] fix: keyboard hiding cursor on startup --- .../main/kotlin/org/fossify/notes/activities/MainActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 4b3a8ad8..262e5a91 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,6 +23,7 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem +import android.view.WindowManager import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -549,6 +550,7 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) From e50e931cb36c31ebd99894997906bbcb8eb297fa Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 13:56:36 -0500 Subject: [PATCH 09/19] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 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 From c2903da64770cbc4218c5339c3d48b6402547bf7 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Fri, 4 Jul 2025 14:01:06 -0500 Subject: [PATCH 10/19] lint --- .../main/kotlin/org/fossify/notes/activities/MainActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 262e5a91..108df9df 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,7 +23,8 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem -import android.view.WindowManager +import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE +import android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -550,7 +551,7 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + window.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE or SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) From adffdb90ce597e542457e89e5b944b883e359be1 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sat, 5 Jul 2025 09:40:28 -0500 Subject: [PATCH 11/19] hacky delayed scroll, has to be a better way --- .../kotlin/org/fossify/notes/activities/MainActivity.kt | 3 --- .../kotlin/org/fossify/notes/fragments/TextFragment.kt | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index 108df9df..4b3a8ad8 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -23,8 +23,6 @@ import android.util.TypedValue import android.view.ActionMode import android.view.Gravity import android.view.MenuItem -import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE -import android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN import android.view.inputmethod.EditorInfo import android.webkit.WebResourceRequest import android.webkit.WebView @@ -551,7 +549,6 @@ class MainActivity : SimpleActivity() { } private fun initViewPager(wantedNoteId: Long? = null) { - window.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE or SOFT_INPUT_ADJUST_PAN) NotesHelper(this).getNotes { notes -> notes.filter { it.shouldBeUnlocked(this) } .forEach(::removeProtection) 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..1cdb8d5c 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -2,6 +2,7 @@ package org.fossify.notes.fragments import android.annotation.SuppressLint import android.content.Context +import android.graphics.Rect import android.graphics.Typeface import android.os.Bundle import android.text.Editable @@ -172,6 +173,12 @@ class TextFragment : NoteFragment() { requestFocus() val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) + + val rect = Rect() + noteEditText.getFocusedRect(rect) + binding.notesScrollview.postDelayed({ + binding.notesScrollview.smoothScrollTo(0, rect.bottom) + }, 1000) } } } From 78bf8e2d84a3bc06015b0fc68719d3b7da47e79d Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sat, 5 Jul 2025 12:51:54 -0500 Subject: [PATCH 12/19] use window inset listener --- .../fossify/notes/fragments/TextFragment.kt | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) 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 1cdb8d5c..b81b88e3 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -18,6 +18,9 @@ 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.WindowInsetsAnimationCompat +import androidx.core.view.WindowInsetsCompat import androidx.viewbinding.ViewBinding import org.fossify.commons.extensions.* import org.fossify.commons.views.MyEditText @@ -170,15 +173,10 @@ class TextFragment : NoteFragment() { if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) { onGlobalLayout { if (activity?.isDestroyed == false) { + setupKeyboardListener() requestFocus() val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) - - val rect = Rect() - noteEditText.getFocusedRect(rect) - binding.notesScrollview.postDelayed({ - binding.notesScrollview.smoothScrollTo(0, rect.bottom) - }, 1000) } } } @@ -207,6 +205,35 @@ class TextFragment : NoteFragment() { setTextWatcher() } + private fun setupKeyboardListener() { + requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets -> + scrollToEndOfNote() + view.onApplyWindowInsets(insets) + } + + val callback = + object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) { + override fun onPrepare(animation: WindowInsetsAnimationCompat) { + super.onPrepare(animation) + scrollToEndOfNote() + } + + override fun onProgress( + insets: WindowInsetsCompat, + runningAnimations: MutableList, + ) = insets + } + ViewCompat.setWindowInsetsAnimationCallback(requireActivity().window.decorView, callback) + } + + private fun scrollToEndOfNote() { + val rect = Rect() + noteEditText.getFocusedRect(rect) + binding.notesScrollview.post { + binding.notesScrollview.scrollTo(0, rect.bottom) + } + } + fun setTextWatcher() { noteEditText.apply { removeTextChangedListener(textWatcher) From 5b67a7aa96ff996cbc0a5673a588fdf01c467088 Mon Sep 17 00:00:00 2001 From: Ben Nguyen <87835859+btnguyenPersonal@users.noreply.github.com> Date: Sun, 6 Jul 2025 07:41:50 -0500 Subject: [PATCH 13/19] Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> --- .../org/fossify/notes/fragments/TextFragment.kt | 14 -------------- 1 file changed, 14 deletions(-) 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 b81b88e3..282d9bf1 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -210,20 +210,6 @@ class TextFragment : NoteFragment() { scrollToEndOfNote() view.onApplyWindowInsets(insets) } - - val callback = - object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) { - override fun onPrepare(animation: WindowInsetsAnimationCompat) { - super.onPrepare(animation) - scrollToEndOfNote() - } - - override fun onProgress( - insets: WindowInsetsCompat, - runningAnimations: MutableList, - ) = insets - } - ViewCompat.setWindowInsetsAnimationCallback(requireActivity().window.decorView, callback) } private fun scrollToEndOfNote() { From 1f64122d494f1de3643784645c523d9f75c326b0 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Sun, 6 Jul 2025 09:38:49 -0500 Subject: [PATCH 14/19] only run keyboard listener once and check config.placeCursorToEnd --- .../org/fossify/notes/fragments/TextFragment.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 282d9bf1..5162e7c0 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -206,9 +206,17 @@ class TextFragment : NoteFragment() { } private fun setupKeyboardListener() { - requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets -> - scrollToEndOfNote() - view.onApplyWindowInsets(insets) + requireActivity().window.decorView.apply { + setOnApplyWindowInsetsListener { view, insets -> + val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets) + if (windowInsets.isVisible(WindowInsetsCompat.Type.ime())) { + if (config!!.placeCursorToEnd) { + scrollToEndOfNote() + } + setOnApplyWindowInsetsListener(null) // clear to avoid scrolling every time + } + view.onApplyWindowInsets(insets) + } } } From 232c6f11125a312f5098b6ce5b62a8e05e3bb159 Mon Sep 17 00:00:00 2001 From: Ben Nguyen <87835859+btnguyenPersonal@users.noreply.github.com> Date: Wed, 9 Jul 2025 07:46:11 -0500 Subject: [PATCH 15/19] Update app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> --- .../fossify/notes/fragments/TextFragment.kt | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) 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 5162e7c0..5ab09e5c 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -205,29 +205,21 @@ class TextFragment : NoteFragment() { setTextWatcher() } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupKeyboardListener() + } + private fun setupKeyboardListener() { - requireActivity().window.decorView.apply { - setOnApplyWindowInsetsListener { view, insets -> - val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets) - if (windowInsets.isVisible(WindowInsetsCompat.Type.ime())) { - if (config!!.placeCursorToEnd) { - scrollToEndOfNote() - } - setOnApplyWindowInsetsListener(null) // clear to avoid scrolling every time + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, insets -> + if (insets.isVisible(WindowInsetsCompat.Type.ime())) { + noteEditText.post { + noteEditText.bringPointIntoView(noteEditText.selectionEnd) } - view.onApplyWindowInsets(insets) } + insets } } - - private fun scrollToEndOfNote() { - val rect = Rect() - noteEditText.getFocusedRect(rect) - binding.notesScrollview.post { - binding.notesScrollview.scrollTo(0, rect.bottom) - } - } - fun setTextWatcher() { noteEditText.apply { removeTextChangedListener(textWatcher) From 94709c917f39d18cd1a940db97690e4513ee504c Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Wed, 9 Jul 2025 08:16:34 -0500 Subject: [PATCH 16/19] add fits system windows --- app/src/main/res/layout/activity_main.xml | 1 + 1 file changed, 1 insertion(+) 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 @@ From f8d11737edf9e1592b57e35ff4ae1b3ccd35e45b Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Wed, 9 Jul 2025 08:21:27 -0500 Subject: [PATCH 17/19] remove extra keyboard listener --- app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt | 1 - 1 file changed, 1 deletion(-) 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 5ab09e5c..151235e0 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -173,7 +173,6 @@ class TextFragment : NoteFragment() { if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) { onGlobalLayout { if (activity?.isDestroyed == false) { - setupKeyboardListener() requestFocus() val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) From eb968e90de856d25a163629cad2a3d3d344365e7 Mon Sep 17 00:00:00 2001 From: btnguyenPersonal Date: Wed, 9 Jul 2025 08:22:16 -0500 Subject: [PATCH 18/19] remove unused imports --- app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt | 2 -- 1 file changed, 2 deletions(-) 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 151235e0..07478148 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -2,7 +2,6 @@ package org.fossify.notes.fragments import android.annotation.SuppressLint import android.content.Context -import android.graphics.Rect import android.graphics.Typeface import android.os.Bundle import android.text.Editable @@ -19,7 +18,6 @@ import android.view.inputmethod.InputMethodManager import android.widget.ImageView import android.widget.TextView import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsAnimationCompat import androidx.core.view.WindowInsetsCompat import androidx.viewbinding.ViewBinding import org.fossify.commons.extensions.* From 755b92b235d46d7cd14d35451b2785bb66c18540 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Wed, 9 Jul 2025 20:23:16 +0530 Subject: [PATCH 19/19] style: add empty line --- app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt | 1 + 1 file changed, 1 insertion(+) 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 07478148..dc969ce5 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt @@ -217,6 +217,7 @@ class TextFragment : NoteFragment() { insets } } + fun setTextWatcher() { noteEditText.apply { removeTextChangedListener(textWatcher)