fix(video-editor): correct cursor drift after cropping#65
Conversation
The synthetic telemetry cursor overlay (PixiCursorOverlay) mapped the full-frame normalized cursor position directly onto the cropped viewport (maskRect), so after a crop the cursor drifted away from the underlying pixel. Re-normalize the position against the crop rect before projecting it onto the viewport, and hide the cursor when it falls outside the crop. This mirrors the native-cursor path (getCroppedCursorPosition / projectNativeCursorToLocal). Fixes getopenscreen#64 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds crop-aware cursor positioning to the video editor. Cursor coordinates are remapped into cropped viewport pixels, the overlay hides cursors outside the crop, playback passes the active crop region, and tests cover mapping and drift regression behavior. ChangesCrop-aware Cursor Mapping
Estimated code review effort: 2 (Simple) | ~15 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
🧹 Nitpick comments (1)
src/components/video-editor/videoPlayback/cursorRenderer.test.ts (1)
50-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNon-null assertion could be avoided.
mapped!.pxrelies on a non-null assertion right after atoEqualon the previous line already implicitly provedmappedis non-null. Could useexpect(mapped).not.toBeNull()first to narrow the type without!, but this is purely stylistic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/video-editor/videoPlayback/cursorRenderer.test.ts` at line 50, The test in cursorRenderer.test.ts uses a non-null assertion on mapped after already asserting its value, so update the cursor mapping test to narrow mapped without using !. In the relevant test around the mapped and buggyPx assertions, replace the direct mapped!.px access by first asserting mapped is not null (or otherwise narrowing its type) and then compare its px value, keeping the same expectation semantics while removing the assertion operator.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/video-editor/videoPlayback/cursorRenderer.test.ts`:
- Line 50: The test in cursorRenderer.test.ts uses a non-null assertion on
mapped after already asserting its value, so update the cursor mapping test to
narrow mapped without using !. In the relevant test around the mapped and
buggyPx assertions, replace the direct mapped!.px access by first asserting
mapped is not null (or otherwise narrowing its type) and then compare its px
value, keeping the same expectation semantics while removing the assertion
operator.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 73b61c1f-898e-4500-abc9-43ad080f105f
📒 Files selected for processing (3)
src/components/video-editor/VideoPlayback.tsxsrc/components/video-editor/videoPlayback/cursorRenderer.test.tssrc/components/video-editor/videoPlayback/cursorRenderer.ts
…fault
Replace inline `{ x: 0, y: 0, width: 1, height: 1 }` crop literals with the
shared DEFAULT_CROP_REGION constant, and let PixiCursorOverlay.update() own the
default so the call site no longer double-defaults cropRegion.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Fixes #64. After cropping a video, the synthetic cursor overlay drifted and no longer lined up with the real mouse position in the frame.
Cursor telemetry (
cx/cy) is normalized to the full, uncropped video, butPixiCursorOverlay.update()projected those coordinates directly onto the cropped viewport (maskRect) without re-normalizing against the crop rect, so the cursor shifted. The native-cursor path (getCroppedCursorPosition/projectNativeCursorToLocal) already handled this correctly — only the synthetic overlay introduced in #61 was missing the transform.Changes
mapCursorToCroppedViewport()that re-normalizes the cursor position against the crop rect before projecting it onto the viewport, and returnsnullwhen the cursor falls outside the visible crop (so it is hidden, matching the native-cursor path).PixiCursorOverlay.update()takes an optionalcropRegionand uses the helper.VideoPlayback.tsxpasses the currentcropRegion.Test plan
cursorRenderer.test.ts(5 cases, including a regression test for [Bug]: Mouse drifting after cropping the video #64).tsc --noEmitandbiome checkpass.Summary by CodeRabbit