Skip to content

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

Open
muratclk wants to merge 1 commit intosiddharthvaddem:mainfrom
muratclk:fix/trim-handle-boundary-clamp
Open

fix: clamp trim handle end position to timeline boundary#399
muratclk wants to merge 1 commit intosiddharthvaddem:mainfrom
muratclk:fix/trim-handle-boundary-clamp

Conversation

@muratclk
Copy link
Copy Markdown

@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. Timeline selections now properly clamp to the video's total time, preventing ranges from exceeding the video's end.

@coderabbitai
Copy link
Copy Markdown

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: ecc1e526-c46a-4eea-bd72-45a60e313f20

📥 Commits

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

📒 Files selected for processing (1)
  • src/components/video-editor/timeline/TimelineWrapper.tsx
✅ Files skipped from review due to trivial 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.

Changes

Cohort / File(s) Summary
Timeline Boundary Clamping
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

Poem

🎬 a handle wandered past the line, lowkey cursed and free,
now Math.min tugs gently—no more boundary spree.
snap, clamp, and breathe: the timeline stays in place,
neat edges, calm UI, a tiny win for grace ✨

🚥 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 The title accurately describes the main fix: clamping the trim handle end position to the timeline boundary, which directly addresses the bug in #393.
Description check ✅ Passed The description covers the bug summary, root cause analysis, fix explanation, and test plan; all key sections from the template are present or adequately addressed.
Linked Issues check ✅ Passed The code change directly satisfies #393 requirements by clamping the end position to totalMs, preventing the trim handle from exceeding timeline boundaries.
Out of Scope Changes check ✅ Passed The single-line change is tightly scoped to fix the clampSpanToBounds function for the reported issue, with no extraneous modifications.

✏️ 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.

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
@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 ❤️

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

2 participants