File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
packages/excalidraw/actions Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -71,19 +71,21 @@ const performDuplication: (intoNextFrame?: boolean) => ActionFn =
7171 const frames = elements . filter (
7272 ( e ) => ! e . isDeleted && e . type === "frame" ,
7373 ) ;
74- frames . sort ( ( e1 , e2 ) => e1 . y - e2 . y ) ;
7574 const origFrame = frames . find ( ( f ) => f . id === origElement . frameId ) ;
7675
77- let newFrame = origFrame ;
78- for ( let i = 0 ; i < frames . length - 1 ; ++ i ) {
79- if ( frames [ i ] . id === origElement . frameId ) {
80- newFrame = frames [ i + 1 ] ;
81- break ;
76+ let newFrame = null ;
77+ for ( const frame of frames ) {
78+ if (
79+ origFrame &&
80+ frame . y > origFrame . y &&
81+ ( newFrame === null || frame . y < newFrame . y )
82+ ) {
83+ newFrame = frame ;
8284 }
8385 }
8486
85- // Only if frame is not last, otherwise it's going to be a normal duplication
86- if ( newFrame && origFrame && newFrame !== origFrame ) {
87+ // Only if frame is not last — otherwise it's going to be a normal duplication
88+ if ( newFrame && origFrame ) {
8789 return {
8890 x : newFrame . x + ( origElement . x - origFrame . x ) ,
8991 y : newFrame . y + ( origElement . y - origFrame . y ) ,
You can’t perform that action at this time.
0 commit comments