Keep the range-select anchor across taps in selection mode#366
Open
MiMoHo wants to merge 1 commit into
Open
Conversation
Range selection via long-press only worked across two consecutive long-presses: MyRecyclerViewAdapter.viewClicked always reset lastLongPressedItem to -1, so tapping a row in between (to select or skip it) cleared the anchor and the next long-press selected only its own row. Track the tapped row as the anchor while in selection mode, so "tap a row, then long-press a later row" fills in every row between them (headers/non-selectable positions are still skipped by toggleItemSelection). Outside selection mode the anchor is cleared as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Range selection via long-press only works across two consecutive long-presses. As soon as the user taps a row in between (to select or skip it), the range anchor is lost and the next long-press selects only its own single row.
Concretely,
MyRecyclerViewAdapter.viewClicked()always resetlastLongPressedItem = -1at the end — including when the tap happened inside selection mode. So the common gesture:does not fill the range, because the tap in step 1 already cleared the anchor. The same applies to “select one, skip one, select the next, then long-press further”.
Fix
While in selection mode, remember the tapped row as the range anchor instead of clearing it. A following long-press then fills in every row between the last touched row and the long-pressed row (which is exactly what
itemLongClicked()already does when an anchor exists). Outside selection mode the anchor is cleared as before, so normal single-tap navigation is unchanged.Behaviour / edge cases
itemClickfires and the anchor is cleared.toggleItemSelection()returns early for!getIsItemSelectable(pos), so the range fill only affects selectable rows.selectItemRange()resetslastLongPressedItemitself after a drag.itemLongClicked()usesmin/max, so ranges fill both upward and downward.Testing
Verified by tracing every gesture path in
viewClicked/viewLongClicked/itemLongClicked/toggleItemSelection/ the drag path. A single-adapter behavioural change with no effect on non-selection navigation or drag-select.