@@ -10342,14 +10342,25 @@ LGraphNode.prototype.executeAction = function(action)
1034210342 *
1034310343 * @param {LGraphNode[] } nodes a list of nodes
1034410344 * @param {"top"|"bottom"|"left"|"right" } direction Direction to align the nodes
10345+ * @param {LGraphNode? } align_to Node to align to (if null, align to the furthest node in the given direction)
1034510346 */
10346- LGraphCanvas . alignNodes = function ( nodes , direction ) {
10347+ LGraphCanvas . alignNodes = function ( nodes , direction , align_to ) {
1034710348 if ( ! nodes ) {
1034810349 return ;
1034910350 }
1035010351
1035110352 const canvas = LGraphCanvas . active_canvas ;
10352- const boundaryNodes = LGraphCanvas . getBoundaryNodes ( nodes )
10353+ let boundaryNodes = [ ]
10354+ if ( align_to === undefined ) {
10355+ boundaryNodes = LGraphCanvas . getBoundaryNodes ( nodes )
10356+ } else {
10357+ boundaryNodes = {
10358+ "top" : align_to ,
10359+ "right" : align_to ,
10360+ "bottom" : align_to ,
10361+ "left" : align_to
10362+ }
10363+ }
1035310364
1035410365 for ( const [ _ , node ] of Object . entries ( canvas . selected_nodes ) ) {
1035510366 switch ( direction ) {
@@ -10372,6 +10383,18 @@ LGraphNode.prototype.executeAction = function(action)
1037210383 canvas . dirty_bgcanvas = true ;
1037310384 } ;
1037410385
10386+ LGraphCanvas . onNodeAlign = function ( value , options , event , prev_menu , node ) {
10387+ new LiteGraph . ContextMenu ( [ "Top" , "Bottom" , "Left" , "Right" ] , {
10388+ event : event ,
10389+ callback : inner_clicked ,
10390+ parentMenu : prev_menu ,
10391+ } ) ;
10392+
10393+ function inner_clicked ( value ) {
10394+ LGraphCanvas . alignNodes ( LGraphCanvas . active_canvas . selected_nodes , value . toLowerCase ( ) , node ) ;
10395+ }
10396+ }
10397+
1037510398 LGraphCanvas . onGroupAlign = function ( value , options , event , prev_menu ) {
1037610399 new LiteGraph . ContextMenu ( [ "Top" , "Bottom" , "Left" , "Right" ] , {
1037710400 event : event ,
@@ -13106,6 +13129,14 @@ LGraphNode.prototype.executeAction = function(action)
1310613129 callback : LGraphCanvas . onMenuNodeToSubgraph
1310713130 } ) ;
1310813131
13132+ if ( Object . keys ( this . selected_nodes ) . length > 1 ) {
13133+ options . push ( {
13134+ content : "Align Selected To" ,
13135+ has_submenu : true ,
13136+ callback : LGraphCanvas . onNodeAlign ,
13137+ } )
13138+ }
13139+
1310913140 options . push ( null , {
1311013141 content : "Remove" ,
1311113142 disabled : ! ( node . removable !== false && ! node . block_delete ) ,
0 commit comments