fix(editor): place added audio on the first free track#324
fix(editor): place added audio on the first free track#324meiiie wants to merge 2 commits intowebadderallorg:mainfrom
Conversation
📝 WalkthroughWalkthroughThe changes extract audio region placement logic from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/video-editor/timeline/TimelineEditor.tsx (1)
1275-1276:⚠️ Potential issue | 🟠 MajorMake audio overlap validation track-aware.
The add flow can now create valid overlapping audio on different tracks, but this still checks against every audio region. Dragging/resizing an audio item can be blocked by a region on another audio track.
🐛 Proposed fix
if (isAudioItem) { - return checkOverlap(audioRegions); + const currentAudio = audioRegions.find((region) => region.id === excludeId); + const trackIndex = currentAudio?.trackIndex ?? 0; + return checkOverlap( + audioRegions.filter((region) => (region.trackIndex ?? 0) === trackIndex), + ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/video-editor/timeline/TimelineEditor.tsx` around lines 1275 - 1276, The current audio overlap check in TimelineEditor.tsx returns checkOverlap(audioRegions) for isAudioItem, which compares against all audio regions across tracks; update the logic so audio overlap validation is track-aware by filtering audioRegions to only those with the same track identifier as the item being added/dragged/resized (e.g., region.trackId or region.track) and then call checkOverlap(filteredAudioRegions). Alternatively, extend checkOverlap to accept a trackId parameter and perform the same-track filter internally; apply this change for add/drag/resize flows (where isAudioItem is used) to avoid blocking operations due to regions on other audio tracks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/components/video-editor/timeline/TimelineEditor.tsx`:
- Around line 1275-1276: The current audio overlap check in TimelineEditor.tsx
returns checkOverlap(audioRegions) for isAudioItem, which compares against all
audio regions across tracks; update the logic so audio overlap validation is
track-aware by filtering audioRegions to only those with the same track
identifier as the item being added/dragged/resized (e.g., region.trackId or
region.track) and then call checkOverlap(filteredAudioRegions). Alternatively,
extend checkOverlap to accept a trackId parameter and perform the same-track
filter internally; apply this change for add/drag/resize flows (where
isAudioItem is used) to avoid blocking operations due to regions on other audio
tracks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f1d05c2e-b75a-409c-b848-92334bd9c4f1
📒 Files selected for processing (3)
src/components/video-editor/timeline/TimelineEditor.tsxsrc/components/video-editor/timeline/audioTrackPlacement.test.tssrc/components/video-editor/timeline/audioTrackPlacement.ts
Description
Fix the editor add-audio flow so a new audio region is placed on the first non-overlapping audio track instead of being rejected immediately when the playhead is already inside another audio region.
Motivation
Issue #322 comes from the editor already supporting audio track rows internally, but the current Add Audio flow still blocks insertion as soon as the current timestamp overlaps any existing audio region. That makes it impossible to add a second overlapping audio source on a separate track.
Type of Change
Related Issue(s)
Changes Made
Testing Guide
Add Audioand choose another audio file.Checklist
Local checks run:
vitest run src/components/video-editor/timeline/audioTrackPlacement.test.ts src/components/video-editor/types.test.tstsc --noEmitbiome check src/components/video-editor/timeline/audioTrackPlacement.ts src/components/video-editor/timeline/audioTrackPlacement.test.ts src/components/video-editor/timeline/TimelineEditor.tsxRuntime A/B smoke on Windows (same local project state in both runs):
origin/main: one existing audio region at0mson track 0, then Add Audio at0msleaves the editor with only that original region0msontrackIndex: 1existing-trackstays on the first audio row andadded-trackappears on the next rowSummary by CodeRabbit
Refactor
Tests