-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(editor): duplicate annotations #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,6 +831,33 @@ export default function VideoEditor() { | |
| [pushState], | ||
| ); | ||
|
|
||
| const handleAnnotationDuplicate = useCallback( | ||
| (id: string) => { | ||
| const duplicateId = `annotation-${nextAnnotationIdRef.current++}`; | ||
| const duplicateZIndex = nextAnnotationZIndexRef.current++; | ||
| pushState((prev) => { | ||
| const source = prev.annotationRegions.find((region) => region.id === id); | ||
| if (!source) return {}; | ||
|
|
||
| const duplicate: AnnotationRegion = { | ||
| ...source, | ||
| id: duplicateId, | ||
| zIndex: duplicateZIndex, | ||
| position: { x: source.position.x + 4, y: source.position.y + 4 }, | ||
| size: { ...source.size }, | ||
| style: { ...source.style }, | ||
| figureData: source.figureData ? { ...source.figureData } : undefined, | ||
| }; | ||
|
|
||
| return { annotationRegions: [...prev.annotationRegions, duplicate] }; | ||
| }); | ||
| setSelectedAnnotationId(duplicateId); | ||
| setSelectedZoomId(null); | ||
| setSelectedTrimId(null); | ||
| }, | ||
| [pushState], | ||
| ); | ||
|
Comment on lines
+834
to
+859
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard duplicate flow when the source annotation is missing. At Line 840, returning Suggested fix const handleAnnotationDuplicate = useCallback(
(id: string) => {
+ const source = annotationRegions.find((region) => region.id === id);
+ if (!source) return;
+
const duplicateId = `annotation-${nextAnnotationIdRef.current++}`;
const duplicateZIndex = nextAnnotationZIndexRef.current++;
pushState((prev) => {
- const source = prev.annotationRegions.find((region) => region.id === id);
- if (!source) return {};
-
const duplicate: AnnotationRegion = {
...source,
id: duplicateId,
zIndex: duplicateZIndex,
position: { x: source.position.x + 4, y: source.position.y + 4 },
size: { ...source.size },
style: { ...source.style },
figureData: source.figureData ? { ...source.figureData } : undefined,
};
return { annotationRegions: [...prev.annotationRegions, duplicate] };
});
setSelectedAnnotationId(duplicateId);
setSelectedZoomId(null);
setSelectedTrimId(null);
},
- [pushState],
+ [annotationRegions, pushState],
);🤖 Prompt for AI Agents |
||
|
|
||
| const handleAnnotationDelete = useCallback( | ||
| (id: string) => { | ||
| pushState((prev) => ({ | ||
|
|
@@ -1680,6 +1707,7 @@ export default function VideoEditor() { | |
| onAnnotationTypeChange={handleAnnotationTypeChange} | ||
| onAnnotationStyleChange={handleAnnotationStyleChange} | ||
| onAnnotationFigureDataChange={handleAnnotationFigureDataChange} | ||
| onAnnotationDuplicate={handleAnnotationDuplicate} | ||
| onAnnotationDelete={handleAnnotationDelete} | ||
| selectedSpeedId={selectedSpeedId} | ||
| selectedSpeedValue={ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localize the new Duplicate button label.
Line 612 hardcodes
"Duplicate"while the panel otherwise uses translation keys. This introduces a localization gap in non-English locales.Suggested fix
<Button onClick={() => onDuplicate?.()} variant="outline" size="sm" disabled={!onDuplicate} className="w-full gap-2 bg-white/5 text-slate-200 border border-white/10 hover:bg-white/10 hover:border-white/20 transition-all" > <Copy className="w-4 h-4" /> - Duplicate + {t("annotation.duplicateAnnotation")} </Button>📝 Committable suggestion
🤖 Prompt for AI Agents