diff --git a/CHANGELOG.md b/CHANGELOG.md index 75259ee0f..c202b8417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed inconsistent checklist sorting when the "Move checked items to the bottom" option is enabled ([#59]) + ## [1.6.0] - 2025-10-29 ### Changed - Compatibility updates for Android 15 & 16 @@ -91,6 +94,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release +[#59]: https://github.com/FossifyOrg/Notes/issues/59 [#81]: https://github.com/FossifyOrg/Notes/issues/81 [#83]: https://github.com/FossifyOrg/Notes/issues/83 [#99]: https://github.com/FossifyOrg/Notes/issues/99 diff --git a/app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt b/app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt index 11117e10d..f444fd2ba 100644 --- a/app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt +++ b/app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt @@ -288,13 +288,28 @@ class TasksFragment : NoteFragment(), TasksActionListener { override fun moveTask(fromPosition: Int, toPosition: Int) { switchToCustomSorting() + + val sortableIndices = mutableListOf() + val checkedCanBeMoved = config?.moveDoneChecklistItems == false + for (i in 0 until tasks.size) { + if (checkedCanBeMoved || !tasks[i].isDone) { + sortableIndices.add(i) + } + } + if (fromPosition < toPosition) { for (i in fromPosition until toPosition) { - tasks.swap(i, i + 1) + val toMoveIndex = sortableIndices[i] + if (i + 1 < sortableIndices.size) { + val headingIndex = sortableIndices[i + 1] + tasks.swap(toMoveIndex, headingIndex) + } } } else { for (i in fromPosition downTo toPosition + 1) { - tasks.swap(i, i - 1) + val toMoveIndex = sortableIndices[i] + val headingIndex = sortableIndices[i - 1] + tasks.swap(toMoveIndex, headingIndex) } }