fix(seek-slider): correct cluster seek rebuild and live drag index#298
Merged
Conversation
Seeking back to an image not in the buffer (e.g. after a sequential
slideshow stops at the last image of a cluster) could land on the wrong
image and show a corrupted position badge ("3" for image #1, "0"/"-1"
when swiping left).
seekToSlideIndex rebuilt the buffer by stepping globalIndex and
searchIndex together (globalIndex + i, searchIndex + i). That assumes
search-result order is contiguous in global-album index, which is false
for clusters/searches — their members are scattered. It loaded
album-adjacent images and, with the -2 origin, tagged prepended slides
with out-of-range search indices (-1, -2). The badge renders index + 1,
so those surfaced as "0" and "-1", and mistagged slides corrupted the
displayed position. The rebuild now resolves each neighbour through
searchToGlobal in search mode and clamps to [0, totalCount).
Exposed by the above fix, the live seek-slider badge also double-counted:
onSliderInput passed targetIndex + 1 to showCluster/showSearchScore,
which already add 1, so the position read one too high while dragging
(release used a different, correct path). Pass the 0-based targetIndex.
Adds regression tests for both paths.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Reproduce: select an image cluster, enter swiper view, run the sequential slideshow until it stops on the last image, then drag the seek-slider back to image #1.
Root cause
SwiperManager.seekToSlideIndexrebuilds the windowed slide buffer when the target isn't loaded. The old loop stepped the global album index and the search index together (globalIndex + i,searchIndex + i). That assumes search-result order is contiguous in global-album index, which is false for clusters/searches — their members are scattered across the album. As a result it:-2origin, tagged the prepended slides with out-of-range search indices (-1,-2).The position badge renders
index + 1(score-display.js), so those mistagged slides displayed as "0" and "-1", and a slide actually showing image #1 could carry a stale search index and read "3".Fix
swiper.js— the rebuild now branches on mode: in search/cluster mode it resolves each neighbour's global index throughsearchToGlobal(searchIndex + i)and clamps to[0, totalCount); album mode keeps the contiguousglobalIndex + istepping. No slide is ever loaded with the wrong picture or an out-of-range index.seek-slider.js— a pre-existing live-drag off-by-one, exposed once the release-time display became correct:onSliderInputpassedtargetIndex + 1toshowCluster/showSearchScore, which already add 1, so the badge read one too high while dragging. Now passes the 0-basedtargetIndex, matching the album branch and the release-time path.Tests
tests/frontend/seek-search-rebuild.test.js— verifies the rebuild loads adjacent cluster images, never tags slides with out-of-range search indices, and lands on image Bump version #1 with the correct badge. Fails on the old code, passes on the fix.tests/frontend/seek-slider-live-index.test.js— verifies the live-drag badge uses the 0-based index for cluster and scored-search results. Fails on the old code, passes on the fix.🤖 Generated with Claude Code