@@ -64,6 +64,9 @@ export default function MasksAndZonesView({
6464 ) ;
6565 const containerRef = useRef < HTMLDivElement | null > ( null ) ;
6666 const [ editPane , setEditPane ] = useState < PolygonType | undefined > ( undefined ) ;
67+ const editPaneRef = useRef ( editPane ) ;
68+ editPaneRef . current = editPane ;
69+ const prevScaledRef = useRef < { w : number ; h : number } | null > ( null ) ;
6770 const [ activeLine , setActiveLine ] = useState < number | undefined > ( ) ;
6871 const [ snapPoints , setSnapPoints ] = useState ( false ) ;
6972
@@ -350,12 +353,36 @@ export default function MasksAndZonesView({
350353 ...globalObjectMasks ,
351354 ...objectMasks ,
352355 ] ) ;
353- setEditingPolygons ( [
354- ...zones ,
355- ...motionMasks ,
356- ...globalObjectMasks ,
357- ...objectMasks ,
358- ] ) ;
356+ // Don't overwrite editingPolygons during editing – layout shifts
357+ // from switching to the edit pane can trigger a resize which
358+ // recalculates scaledWidth/scaledHeight and would discard the
359+ // newly-added polygon. Instead, rescale existing points
360+ // proportionally.
361+ if ( editPaneRef . current === undefined ) {
362+ setEditingPolygons ( [
363+ ...zones ,
364+ ...motionMasks ,
365+ ...globalObjectMasks ,
366+ ...objectMasks ,
367+ ] ) ;
368+ } else if (
369+ prevScaledRef . current &&
370+ ( prevScaledRef . current . w !== scaledWidth ||
371+ prevScaledRef . current . h !== scaledHeight )
372+ ) {
373+ const prevW = prevScaledRef . current . w ;
374+ const prevH = prevScaledRef . current . h ;
375+ setEditingPolygons ( ( prev ) =>
376+ prev . map ( ( poly ) => ( {
377+ ...poly ,
378+ points : poly . points . map ( ( [ x , y ] ) => [
379+ ( x / prevW ) * scaledWidth ,
380+ ( y / prevH ) * scaledHeight ,
381+ ] ) ,
382+ } ) ) ,
383+ ) ;
384+ }
385+ prevScaledRef . current = { w : scaledWidth , h : scaledHeight } ;
359386 }
360387 // we know that these deps are correct
361388 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -431,7 +458,7 @@ export default function MasksAndZonesView({
431458 { cameraConfig && editingPolygons && (
432459 < div className = "flex size-full flex-col md:flex-row" >
433460 < Toaster position = "top-center" closeButton = { true } />
434- < div className = "scrollbar-container order-last mb-2 mt-2 flex h-full w-full flex-col overflow-y-auto rounded-lg border-[1px] border-secondary-foreground bg-background_alt p-2 md:order-none md:mr-3 md:mt-0 md:w-3/12" >
461+ < div className = "scrollbar-container order-last mb-2 mt-2 flex h-full w-full flex-col overflow-y-auto rounded-lg border-[1px] border-secondary-foreground bg-background_alt p-2 md:order-none md:mr-3 md:mt-0 md:w-3/12 md:min-w-0 md:shrink-0 " >
435462 { editPane == "zone" && (
436463 < ZoneEditPane
437464 polygons = { editingPolygons }
@@ -707,7 +734,7 @@ export default function MasksAndZonesView({
707734 < div
708735 ref = { containerRef }
709736 className = { cn (
710- "flex max-h-[50%] md:h-dvh md:max-h-full md:w-7/12 md:grow" ,
737+ "flex max-h-[50%] min-w-0 md:h-dvh md:max-h-full md:w-7/12 md:grow" ,
711738 isDesktop && "md:mr-3" ,
712739 ) }
713740 >
0 commit comments