fix: keep zoom selection on the new segment after a split - #2254
Open
JebKJ21 wants to merge 2 commits into
Open
Conversation
Comment on lines
+34
to
+36
| const newSegmentIndex = sortTrackSegments(segments).indexOf( | ||
| segments[index + 1], | ||
| ); |
Contributor
There was a problem hiding this comment.
Sorting loses segment identity
sortTrackSegments sorts the array in place before segments[index + 1] is evaluated. If sorting moves the newly created right piece, this lookup instead finds whichever segment now occupies that position. For example, splitting index 1 in [0–10, 30–40, 20–25] returns the left piece's index, so the editor selects the wrong segment and the selection bug remains.
Suggested change
| const newSegmentIndex = sortTrackSegments(segments).indexOf( | |
| segments[index + 1], | |
| ); | |
| const newSegment = segments[index + 1]; | |
| const newSegmentIndex = sortTrackSegments(segments).indexOf(newSegment); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/routes/editor/zoom-segments.ts
Line: 34-36
Comment:
**Sorting loses segment identity**
`sortTrackSegments` sorts the array in place before `segments[index + 1]` is evaluated. If sorting moves the newly created right piece, this lookup instead finds whichever segment now occupies that position. For example, splitting index 1 in `[0–10, 30–40, 20–25]` returns the left piece's index, so the editor selects the wrong segment and the selection bug remains.
```suggestion
const newSegment = segments[index + 1];
const newSegmentIndex = sortTrackSegments(segments).indexOf(newSegment);
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Author
|
Good catch — fixed in 42d704c. The inserted piece is now captured by reference 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.
What
Splitting a zoom segment and then editing the newly created piece could silently edit the pre-split segment instead:
splitZoomSegmentre-sorted the segments array but lefteditorState.timeline.selectionpointing at the old index — which after the sort can belong to the other half. The user then adjusts "the new zoom" while the changes land on the old one, and playback keeps zooming into the old area (#2230).Fix
splitZoomSegmentnow keeps the selection on the new (right) piece after the split + re-sort.zoom-segments.ts(splitZoomSegmentAt), which computes the new piece's post-sort index where the mutation happens and can be unit-tested without Solid stores.didSplitbranch); zoom splits now follow the same principle instead of leaving a stale index.Testing
zoom-segments.test.ts, 5 cases): split geometry, property preservation on both halves, post-sort selection index, <1s rejection, out-of-bounds no-op.vitest runinapps/desktop: 32 files / 270 tests pass.biome checkclean on touched files;tsc --noEmitclean.Fixes #2230
If the team prefers to route this through Algora as a funded bounty, happy to submit it there — otherwise glad to have it reviewed as a regular contribution.
The PR should not merge until the helper preserves the new right piece's identity across sorting, because reordered inputs can still select the wrong segment.
Findings
Prompt To Fix All With AI
Summary