Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -608,6 +609,9 @@ class MainActivity : SimpleActivity() {
}

binding.viewPager.onPageChangeListener {
searchIndex = 0
searchMatches = emptyList()

currentTextFragment?.removeTextWatcher()
currentNotesView()?.let { noteView ->
noteView.text!!.clearBackgroundSpans()
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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()
}
Expand All @@ -694,7 +698,7 @@ class MainActivity : SimpleActivity() {

currentNotesView()?.let { noteView ->
noteView.requestFocus()
noteView.setSelection(0)
noteView.safeSetSelection(0)
}

searchQueryET.postDelayed({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Loading