Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat: add crop functionality with snapshot handling in SettingsPanel

Prayas Lashkarie3c922d03266
diff --git a/src/components/video-editor/SettingsPanel.tsx b/src/components/video-editor/SettingsPanel.tsx
index 15be76eb2..e445ac0d8 100644
--- a/src/components/video-editor/SettingsPanel.tsx
+++ b/src/components/video-editor/SettingsPanel.tsx
@@ -233,6 +233,7 @@ export function SettingsPanel({
const [selectedColor, setSelectedColor] = useState("#ADADAD");
const [gradient, setGradient] = useState<string>(GRADIENTS[0]);
const [showCropDropdown, setShowCropDropdown] = useState(false);
+ const cropSnapshotRef = useRef<CropRegion | null>(null);
const zoomEnabled = Boolean(selectedZoomDepth);
const trimEnabled = Boolean(selectedTrimId);
@@ -296,6 +297,20 @@ export function SettingsPanel({
}
};
+ const handleCropToggle = () => {
+ if (!showCropDropdown && cropRegion) {
+ cropSnapshotRef.current = { ...cropRegion };
+ }
+ setShowCropDropdown(!showCropDropdown);
+ };
+
+ const handleCropCancel = () => {
+ if (cropSnapshotRef.current && onCropChange) {
+ onCropChange(cropSnapshotRef.current);
+ }
+ setShowCropDropdown(false);
+ };
+
// Find selected annotation
const selectedAnnotation = selectedAnnotationId
? annotationRegions.find((a) => a.id === selectedAnnotationId)
@@ -527,7 +542,7 @@ export function SettingsPanel({
</div>
<Button
- onClick={() => setShowCropDropdown(!showCropDropdown)}
+ onClick={handleCropToggle}
variant="outline"
className="w-full mt-2 gap-1.5 bg-white/5 text-slate-200 border-white/10 hover:bg-white/10 hover:border-white/20 hover:text-white text-[10px] h-8 transition-all"
>
@@ -707,7 +722,7 @@ export function SettingsPanel({
<>
<div
className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 animate-in fade-in duration-200"
- onClick={() => setShowCropDropdown(false)}
+ onClick={handleCropCancel}
/>
<div className="fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-[60] bg-[#09090b] rounded-2xl shadow-2xl border border-white/10 p-8 w-[90vw] max-w-5xl max-h-[90vh] overflow-auto animate-in zoom-in-95 duration-200">
<div className="flex items-center justify-between mb-6">
@@ -720,7 +735,7 @@ export function SettingsPanel({
<Button
variant="ghost"
size="icon"
- onClick={() => setShowCropDropdown(false)}
+ onClick={handleCropCancel}
className="hover:bg-white/10 text-slate-400 hover:text-white"
>
<X className="w-5 h-5" />