Skip to content

Conversation

@pmartinonales
Copy link
Contributor

@pmartinonales pmartinonales commented Dec 10, 2025

Fix: Split action respects segment timescale (speed)

Problem

#1445 When using the split tool (scissors) on the timeline, if a previous segment had a modified playback speed (timescale), the split would occur at the wrong position instead of where the user clicked.

Root Cause

The code was mixing two different time representations:

Time Space Formula Description
Timeline time (end - start) / timescale Visual duration on the timeline
Recording time end - start Raw source video duration

The splitClipSegment function searched for the target segment using recording time durations instead of timeline time, causing incorrect segment detection when earlier segments had modified speeds.

Example

Consider this timeline:

  • Segment 0: 100 frames at 2x speed → 50s visible on timeline
  • Segment 1: 100 frames at 1x speed → 100s visible on timeline

When clicking to split at 25% into Segment 1 (which is at 75s into the timeline):

Before Fix After Fix
Result ❌ Splits Segment 0 at frame 75 ✅ Splits Segment 1 at frame 25

Changes

apps/desktop/src/routes/editor/context.ts

  • Account for timescale when calculating segment duration during search
  • Convert timeline time back to recording time when setting the split position

apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx

  • Calculate splitTime in timeline time (divide by timescale) to be consistent with prevDuration()

Testing

  • Split works correctly when all segments are at 1x speed
  • Split works correctly when previous segments have modified speed (0.5x, 2x, 4x, etc.)
  • Split at current playhead position (C key) works correctly with modified speeds
  • Click-to-split in split mode works correctly with modified speeds

Summary by CodeRabbit

  • Bug Fixes
    • Clip splitting now accounts for each segment's timescale, ensuring splits occur at the correct absolute position for clips with varying playback rates — improving timeline accuracy and editing reliability.
  • Style
    • Updated track button background styling for a more consistent appearance in the editor UI.

✏️ Tip: You can customize this high-level summary in your review settings.


Note

Ensure clip splitting uses timeline time and converts to recording time so splits occur at correct positions with speed-adjusted segments; minor add-button style tweak.

  • Bug fix — clip splitting respects timescale
    • Update projectActions.splitClipSegment in apps/desktop/src/routes/editor/context.ts to search by timeline duration (end - start) / timescale and convert split position back to recording time (* timescale).
    • In apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx, compute splitTime as fraction * (end - start) / timescale before calling splitClipSegment.
  • UI
    • Tweak apps/desktop/src/routes/editor/Timeline/TrackManager.tsx add button styling (class changes).

Written by Cursor Bugbot for commit 73b4b71. This will update automatically on new commits. Configure here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Walkthrough

Split and duration calculations for clip segments were made timescale-aware: splitting now normalizes computed times against the segment's timescale, and segment start/end updates use timescale-adjusted values. A minor UI style tweak updated a TrackManager button background class.

Changes

Cohort / File(s) Summary
Timescale-aware split logic
apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx, apps/desktop/src/routes/editor/context.ts
Split and duration math updated to account for segment.timescale. splitTime/duration are normalized by timescale; split position is computed in recording units and used to update segment start/end.
TrackManager styling
apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
Button background class changed from bg-gray-2/60 to bg-gray-1 (visual/style-only change).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Verify arithmetic and unit consistency around timescale conversions in both files.
  • Check for off-by-one/rounding and boundary conditions when splitting at segment edges.
  • Validate UI behavior in split mode across varied timescales and playback rates.
  • Confirm the style change has no unintended visual regressions (dark mode variants).

Possibly related PRs

Suggested labels

Desktop

Suggested reviewers

  • Brendonovich

Poem

🐰 I hopped through code with careful paws,

split times now heed their silent laws.
Segments line up, neat and kind,
each timescale tick now well aligned.

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: enabling the split action to respect segment timescale (speed), which directly addresses the core bug being fixed across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@richiemcilroy
Copy link
Member

Amazing!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/desktop/src/routes/editor/Timeline/TrackManager.tsx (1)

60-60: Consider moving unrelated UI styling to a separate PR.

This background color change appears unrelated to the PR's stated objective of fixing the timescale bug in the split tool. Mixing cosmetic UI changes with bug fixes can make code review and git history less clear.

Additionally, note that TrackIcon at line 72 still uses bg-gray-2/60. If this background change is intentional, verify whether TrackIcon should be updated for visual consistency.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5761eab and 73b4b71.

📒 Files selected for processing (1)
  • apps/desktop/src/routes/editor/Timeline/TrackManager.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

Use React Query hooks with Server Actions for mutations and perform precise cache updates using setQueryData/setQueriesData instead of broad invalidations

Files:

  • apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Use strict TypeScript; avoid any type; leverage shared types from @cap/* packages
Follow camelCase naming for variables and functions; PascalCase for components; hooks must start with 'use' prefix
Use Biome for linting and formatting; match existing formatting conventions in the codebase
Use Tailwind CSS for styling in web components; stay consistent with spacing and tokens
Use static skeletons for loading states that mirror content; avoid bouncing animations
Memoize expensive work, code-split naturally, and use Next/Image for remote assets

**/*.{ts,tsx,js,jsx}: Use 2-space indent for TypeScript files; format with Biome using pnpm format
Use Biome for code formatting and linting; run pnpm format regularly
Use kebab-case for file names (e.g., user-menu.tsx); use PascalCase for components

Files:

  • apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Never add any form of comments to code (single-line //, multi-line /* /, JSDoc /* */, or any other comment syntax); code must be self-explanatory through naming, types, and structure
Directory naming must use lowercase-dashed convention

Files:

  • apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
**/*.{ts,tsx,js,jsx,rs}

📄 CodeRabbit inference engine (AGENTS.md)

Never add comments to code (//, /* */, ///, //!, #, etc.); code must be self-explanatory through naming, types, and structure

Files:

  • apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot

@richiemcilroy richiemcilroy merged commit 68ad6bb into CapSoftware:main Dec 17, 2025
12 of 13 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.

2 participants