Skip to content

Commit c0f134c

Browse files
fix: Prevent broken/strange checklist reordering (#282)
* fix: Prevent broken/strange checklist reordering Updates the checklist reorder moves to filter and just consider those which are visually re-orderable within the UI, since odd behaviour could occur when the fundemental task data had checked items between unchecked items while the "Move checked items to the bottom" setting was enabled. This could occur from toggling the "Move checked items to the bottom" option, or by attempting to move a task item into/below the "Checked items" list. This also adds a check when moving an item down, since the move handling would consider the "Checked items" as an element when emitting position changes. Related to #59 * docs(changelog): reference issue in changelog entry It helps in the release notes. --------- Co-authored-by: Naveen Singh <[email protected]>
1 parent d1cc38d commit c0f134c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Fixed inconsistent checklist sorting when the "Move checked items to the bottom" option is enabled ([#59])
11+
912
## [1.6.0] - 2025-10-29
1013
### Changed
1114
- Compatibility updates for Android 15 & 16
@@ -91,6 +94,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9194
### Added
9295
- Initial release
9396

97+
[#59]: https://github.com/FossifyOrg/Notes/issues/59
9498
[#81]: https://github.com/FossifyOrg/Notes/issues/81
9599
[#83]: https://github.com/FossifyOrg/Notes/issues/83
96100
[#99]: https://github.com/FossifyOrg/Notes/issues/99

app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,28 @@ class TasksFragment : NoteFragment(), TasksActionListener {
288288

289289
override fun moveTask(fromPosition: Int, toPosition: Int) {
290290
switchToCustomSorting()
291+
292+
val sortableIndices = mutableListOf<Int>()
293+
val checkedCanBeMoved = config?.moveDoneChecklistItems == false
294+
for (i in 0 until tasks.size) {
295+
if (checkedCanBeMoved || !tasks[i].isDone) {
296+
sortableIndices.add(i)
297+
}
298+
}
299+
291300
if (fromPosition < toPosition) {
292301
for (i in fromPosition until toPosition) {
293-
tasks.swap(i, i + 1)
302+
val toMoveIndex = sortableIndices[i]
303+
if (i + 1 < sortableIndices.size) {
304+
val headingIndex = sortableIndices[i + 1]
305+
tasks.swap(toMoveIndex, headingIndex)
306+
}
294307
}
295308
} else {
296309
for (i in fromPosition downTo toPosition + 1) {
297-
tasks.swap(i, i - 1)
310+
val toMoveIndex = sortableIndices[i]
311+
val headingIndex = sortableIndices[i - 1]
312+
tasks.swap(toMoveIndex, headingIndex)
298313
}
299314
}
300315

0 commit comments

Comments
 (0)