notes: hide reorder handles while searching the notes list
- Commit
eb2ae03340c3488d151a4e413cceed9995657922- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:23 UTC (28 days ago)
- Parents
47c1fe2
Reordering while a search filter was active corrupted note order: onMove reassigns positions within the visible filtered subset and upsertAll persists them, silently scrambling the global order of the hidden notes. The drag handle is now only shown when the search query is blank, so positions can only be reassigned against the full list. Covered by listSearchHidesDragHandles, which asserts zero reorder handles are present while a query is active. Verified: full :notes:testDevUnitTest suite green (153 tests, 0 failures).
Diff
notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.ktindex 297046f689..84329c54f0 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt@@ -256,7 +256,10 @@ fun NotesListScreen( }, trailingContent = { Row(verticalAlignment = Alignment.CenterVertically) {- if (localData.size > 1 && selectedIds.size < localData.size && (!isSelectionMode || isContiguous)) {+ // No drag handle while searching: onMove reassigns positions within+ // the visible (filtered) subset and upsertAll persists them, which+ // would corrupt the global order of the hidden notes.+ if (searchQuery.isBlank() && localData.size > 1 && selectedIds.size < localData.size && (!isSelectionMode || isContiguous)) { IconButton( modifier = Modifier.reorderDragHandle( reorderState = reorderState,
notes/src/test/java/com/vayunmathur/notes/ui/NotesComposeTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/ui/NotesComposeTest.kt b/notes/src/test/java/com/vayunmathur/notes/ui/NotesComposeTest.ktindex 616c4c07a0..6edeab1986 100644--- a/notes/src/test/java/com/vayunmathur/notes/ui/NotesComposeTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/ui/NotesComposeTest.kt@@ -231,6 +231,17 @@ class NotesComposeTest { rule.onNodeWithContentDescription("Add image").assertIsDisplayed() } + @Test fun listSearchHidesDragHandles() {+ // "title" matches Alpha + Beta (2 rows, so handles would show unfiltered):+ // while searching, no reorder handle may exist — a drag would persist+ // positions computed from the filtered subset and corrupt global order.+ val actions = RecordingListActions()+ rule.setContent { NotesListScreen(NotesListUiState(notes()), actions, initialSearchQuery = "title") }+ rule.onNodeWithText("Alpha Title").assertIsDisplayed()+ rule.onNodeWithText("Beta Title").assertIsDisplayed()+ assertTrue(rule.onAllNodesWithContentDescription("Reorder").fetchSemanticsNodes().isEmpty())+ }+ @Test fun listDragHandleSwipeDoesNotCrash() { val actions = RecordingListActions() rule.setContent { NotesListScreen(NotesListUiState(notes()), actions) }