Skip to content

Commit f947fdc

Browse files
committed
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
1 parent d1cc38d commit f947fdc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 3 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
11+
912
## [1.6.0] - 2025-10-29
1013
### Changed
1114
- Compatibility updates for Android 15 & 16

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)