Skip to content

fix: clamp trim handle end position to timeline boundary#399

Merged
siddharthvaddem merged 1 commit into
siddharthvaddem:mainfrom
muratclk:fix/trim-handle-boundary-clamp
May 9, 2026
Merged

fix: clamp trim handle end position to timeline boundary#399
siddharthvaddem merged 1 commit into
siddharthvaddem:mainfrom
muratclk:fix/trim-handle-boundary-clamp

Conversation

@muratclk
Copy link
Copy Markdown
Contributor

@muratclk muratclk commented Apr 8, 2026

Summary

Fixes #393 — the right-side trim handle could be dragged indefinitely past the end of the timeline.

Root cause: clampSpanToBounds in TimelineWrapper.tsx computed end = start + duration without capping it at totalMs. The sibling function clampToNeighbours does clamp end to totalMs, but it's only invoked when there's overlap with neighboring regions — so when no neighbor exists to the right, the handle was unconstrained.

Fix: Add Math.min(start + duration, totalMs) to ensure the end position never exceeds the video duration.

Test plan

  • Open the video editor/trimmer interface
  • Select a clip on the timeline
  • Drag the right trim handle past the end of the timeline
  • Verify the handle stops/snaps at the timeline boundary
  • Verify left trim handle still works correctly
  • Verify dragging the entire clip still clamps correctly

Summary by CodeRabbit

  • Bug Fixes
    • Fixed video editor timeline behavior where selection spans could extend beyond the video's maximum duration. Selections are now clamped to the video's total time so range start/end values cannot exceed the video's end, preventing out-of-bounds ranges and improving timeline accuracy when trimming or selecting segments.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f6068ab-eeb0-4999-a0e0-a10412cdf3e8

📥 Commits

Reviewing files that changed from the base of the PR and between a72c3eb and c771bf8.

📒 Files selected for processing (1)
  • src/components/video-editor/timeline/TimelineWrapper.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/video-editor/timeline/TimelineWrapper.tsx

📝 Walkthrough

Walkthrough

Clamped timeline span end to never exceed totalMs: end is computed as Math.min(start + duration, totalMs) in clampSpanToBounds, ensuring returned { start, end } stays within the timeline's maximum duration.

Timeline Boundary Clamping

Layer / File(s) Summary
Core clamp logic
src/components/video-editor/timeline/TimelineWrapper.tsx
Changed clampSpanToBounds so end = Math.min(start + duration, totalMs) rather than start + duration, preventing span endpoints (e.g., right trim handle) from exceeding the timeline's total duration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

a trim handle went rogue, stretching past the end,
lowkey cursed the edge — chaos to mend.
Math.min whispered gently, "that's where we stop,"
now the timeline breathes easy, no more crop.
small fix, calm UI — nightshift win, my friend.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely describes the main fix: clamping trim handle end position to the timeline boundary.
Description check ✅ Passed Description covers root cause, fix explanation, and test plan. Most template sections are present; Type of Change checkbox is unchecked but the fix is evident from context.
Linked Issues check ✅ Passed The PR directly addresses issue #393 by implementing the exact fix needed: clamping end position with Math.min(start + duration, totalMs) to prevent handles from exceeding timeline boundaries.
Out of Scope Changes check ✅ Passed Single-line change in clampSpanToBounds is scoped precisely to fix the trim handle boundary issue; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@muratclk muratclk force-pushed the fix/trim-handle-boundary-clamp branch from a957efb to a72c3eb Compare April 8, 2026 23:17
@selmamehdi48
Copy link
Copy Markdown

Thanks for this fix ❤️

@siddharthvaddem
Copy link
Copy Markdown
Owner

@muratclk linting and type checks failing

The right-side trim handle could be dragged past the end of the
timeline because clampSpanToBounds did not cap the computed end
value at totalMs. This adds Math.min(…, totalMs) so the handle
snaps to the timeline edge.

Fixes siddharthvaddem#393
@siddharthvaddem siddharthvaddem force-pushed the fix/trim-handle-boundary-clamp branch from a72c3eb to c771bf8 Compare May 9, 2026 17:17
@siddharthvaddem siddharthvaddem self-requested a review as a code owner May 9, 2026 17:17
@siddharthvaddem siddharthvaddem merged commit d3e397e into siddharthvaddem:main May 9, 2026
11 checks passed
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.

[Bug]: Trim handle exceeds timeline boundaries and fails to snap at terminal edge

3 participants