Skip to content

recorder: auto-scroll segment bar when a clip is added - #171

Merged
morepriyam merged 2 commits into
mainfrom
feat/segment-bar-autoscroll
Aug 26, 2026
Merged

recorder: auto-scroll segment bar when a clip is added#171
morepriyam merged 2 commits into
mainfrom
feat/segment-bar-autoscroll

Conversation

@morepriyam

@morepriyam morepriyam commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #167.

Stacked on #170 (same file); only the last commit is this PR's change.

Scroll-to-newest existed in f2a1e38 but was dropped in 400fc68 with the scroll-preservation work — since then a clip recorded or imported past the right edge of a full bar lands invisibly off-screen.

Change

Reinstated alongside the preservation logic as one direction-keyed effect — reorder never changes the segment count, so the branches are mutually exclusive by construction:

  • Length increase (recording finalized or library import — both arrive through the same live query) in record mode → animated scrollToEnd, deferred to onContentSizeChange so the new thumb has laid out before the scroll fires
  • Length decrease (delete) → the existing restore-offset behavior, untouched
  • Gated on the cursor being absent — while previewing, playhead-follow owns the scroll, so the two mechanisms can't fight

Testing

  • tsc --noEmit, ESLint, and the jest suite clean
  • Verified on device: new recordings and library imports scroll the newest thumb into view on an overflowing bar; scroll position still preserved on delete; playhead-follow unaffected while previewing

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores “scroll-to-newest” behavior for the recorder segment bar when a new clip is added, while preserving existing delete offset restoration and avoiding conflicts with playhead-follow during preview.

Changes:

  • Track segment-count direction changes and schedule an animated scrollToEnd on length increases (new recording/import) when not previewing.
  • Keep existing “restore previous offset” behavior for length decreases (delete).
  • Defer the scroll-to-end until onContentSizeChange so the new thumbnail has measured before scrolling.
Suppressed comments (1)

src/features/recorder/segment-bar.tsx:172

  • onContentSizeChange will execute scrollToEnd whenever stickToEnd is set, even if the user has entered preview mode since the segment was added (cursor now truthy). Also, if both restoreOffset and stickToEnd are set (e.g. batched updates), the current two independent if blocks will restore the offset and then immediately scroll to end, breaking the delete-preservation behavior. Guard the scroll-to-end by !cursor and make the two branches mutually exclusive, cancelling any pending stick-to-end when previewing.
              // Honor a pending scroll-to-newest now that the added thumb has been measured.
              if (stickToEnd.current) {
                stickToEnd.current = false;
                scrollRef.current?.scrollToEnd({ animated: true });
              }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/features/recorder/segment-bar.tsx

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/features/recorder/segment-bar.tsx:108

  • stickToEnd can remain set across a subsequent length DECREASE (delete) if a clip is removed before the pending scrollToEnd runs. In that case onContentSizeChange will restore the offset and then immediately scroll to end, defeating the delete-preservation behavior. Clear any pending stickToEnd when a decrease is detected so deletes can never trigger an unintended auto-scroll.
    if (cursor) stickToEnd.current = false;
    if (segments.length < prevCount.current) restoreOffset.current = scrollOffset.value;
    else if (segments.length > prevCount.current && !cursor) stickToEnd.current = true;
    prevCount.current = segments.length;

@morepriyam morepriyam self-assigned this Aug 14, 2026

@SarkarShubhdeep SarkarShubhdeep left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto scroll to newly added clip works with no issues.

Base automatically changed from feat/playback-scopes to main August 26, 2026 05:35
Scroll-to-newest existed (f2a1e38) but was dropped in 400fc68 along with
the scroll-preservation work — a new recording or library import off the
right edge of a full bar landed invisibly.

Reinstate it alongside the preservation logic as one direction-keyed
effect (reorder never changes length, so the branches are mutually
exclusive):

- length increase (recording or import) in record mode → animated
  scrollToEnd, deferred to onContentSizeChange so the added thumb has
  laid out before the scroll
- length decrease (delete) → the existing restore-offset behavior,
  untouched
- gated on the cursor being absent: while previewing, playhead-follow
  owns the scroll

Closes #167
A clip add armed stickToEnd, but if the preview opened before
onContentSizeChange ran, the stale flag survived and fired an unexpected
scrollToEnd on a later content-size change while previewing. Clear it
whenever the cursor is present — in the length effect and re-checked in
the handler, since the native event can land before the effect re-runs.
@morepriyam
morepriyam force-pushed the feat/segment-bar-autoscroll branch from c6e015d to f664992 Compare August 26, 2026 05:35
@morepriyam
morepriyam added this pull request to the merge queue Aug 26, 2026
Merged via the queue into main with commit 4a6c96a Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

recorder: restore auto-scroll of segment bar when a new segment is added

3 participants