mirror of
https://github.com/FossifyOrg/Notes.git
synced 2025-12-23 23:59:34 -05:00
fix: reset search state on page change (#216)
Refs: https://github.com/FossifyOrg/Notes/issues/190
This commit is contained in:
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Fixed crash in search ([#190])
|
||||
|
||||
## [1.4.1] - 2025-09-01
|
||||
### Changed
|
||||
@@ -80,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#157]: https://github.com/FossifyOrg/Notes/issues/157
|
||||
[#164]: https://github.com/FossifyOrg/Notes/issues/164
|
||||
[#178]: https://github.com/FossifyOrg/Notes/issues/178
|
||||
[#190]: https://github.com/FossifyOrg/Notes/issues/190
|
||||
[#201]: https://github.com/FossifyOrg/Notes/issues/201
|
||||
|
||||
[Unreleased]: https://github.com/FossifyOrg/Notes/compare/1.4.1...HEAD
|
||||
|
||||
@@ -107,6 +107,7 @@ import org.fossify.notes.extensions.config
|
||||
import org.fossify.notes.extensions.getPercentageFontSize
|
||||
import org.fossify.notes.extensions.notesDB
|
||||
import org.fossify.notes.extensions.parseChecklistItems
|
||||
import org.fossify.notes.extensions.safeSetSelection
|
||||
import org.fossify.notes.extensions.updateWidgets
|
||||
import org.fossify.notes.extensions.widgetsDB
|
||||
import org.fossify.notes.fragments.TextFragment
|
||||
@@ -608,6 +609,9 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
binding.viewPager.onPageChangeListener {
|
||||
searchIndex = 0
|
||||
searchMatches = emptyList()
|
||||
|
||||
currentTextFragment?.removeTextWatcher()
|
||||
currentNotesView()?.let { noteView ->
|
||||
noteView.text!!.clearBackgroundSpans()
|
||||
@@ -641,7 +645,7 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
if (searchMatches.isNotEmpty()) {
|
||||
noteView.requestFocus()
|
||||
noteView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
|
||||
noteView.safeSetSelection(searchMatches.getOrNull(searchIndex) ?: 0)
|
||||
}
|
||||
|
||||
searchQueryET.postDelayed({
|
||||
@@ -681,7 +685,7 @@ class MainActivity : SimpleActivity() {
|
||||
private fun selectSearchMatch(editText: MyEditText) {
|
||||
if (searchMatches.isNotEmpty()) {
|
||||
editText.requestFocus()
|
||||
editText.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
|
||||
editText.safeSetSelection(searchMatches.getOrNull(searchIndex) ?: 0)
|
||||
} else {
|
||||
hideKeyboard()
|
||||
}
|
||||
@@ -694,7 +698,7 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
currentNotesView()?.let { noteView ->
|
||||
noteView.requestFocus()
|
||||
noteView.setSelection(0)
|
||||
noteView.safeSetSelection(0)
|
||||
}
|
||||
|
||||
searchQueryET.postDelayed({
|
||||
|
||||
@@ -16,3 +16,9 @@ fun MyEditText.enforcePlainText() {
|
||||
}
|
||||
filters = (filters ?: emptyArray()) + stripSpans
|
||||
}
|
||||
|
||||
fun MyEditText.safeSetSelection(position: Int) {
|
||||
val length = text?.length ?: 0
|
||||
setSelection(position.coerceIn(0, length))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user