@@ -3,7 +3,7 @@ use std::{collections::HashSet, sync::Arc};
33use gpui:: { Bounds , Element , MouseButton , Pixels , Point , canvas, px, rgb} ;
44
55use crate :: {
6- DefaultEdgeValidator , EdgeValidator , PortId , PortKind , PortPosition , ToastMessage ,
6+ DefaultEdgeValidator , EdgeValidator , Graph , PortId , PortKind , PortPosition , ToastMessage ,
77 canvas:: Interaction ,
88 plugin:: { FlowEvent , InputEvent , Plugin , RenderContext } ,
99 plugins:: port:: { edge_bezier, filled_disc_path, port_screen_big_bounds, port_screen_bounds} ,
@@ -75,17 +75,31 @@ impl PortInteractionPlugin {
7575 return ;
7676 } ;
7777
78- let x: f32 = p. end_world . x . into ( ) ;
79- let y: f32 = p. end_world . y . into ( ) ;
80-
8178 let mut builder = ctx. create_node ( "" ) ;
82- builder = builder. position ( x, y) ;
8379 builder = match source. kind ( ) {
8480 PortKind :: Output => builder. input ( ) ,
8581 PortKind :: Input => builder. output ( ) ,
8682 } ;
8783
88- let ( new_node, new_ports, _) = builder. build_raw ( ) ;
84+ let ( mut new_node, new_ports, _) = builder. build_raw ( ) ;
85+
86+ let Some ( connect_port) = ( match source. kind ( ) {
87+ PortKind :: Output => new_ports. iter ( ) . find ( |p| p. kind ( ) == PortKind :: Input ) ,
88+ PortKind :: Input => new_ports. iter ( ) . find ( |p| p. kind ( ) == PortKind :: Output ) ,
89+ } ) else {
90+ return ;
91+ } ;
92+
93+ let mut scratch = Graph :: new ( ) ;
94+ scratch. add_node ( new_node. clone ( ) ) ;
95+ for port in & new_ports {
96+ scratch. add_port ( port. clone ( ) ) ;
97+ }
98+ let offset = ctx. port_world_offset_relative ( & scratch, & new_node, connect_port) ;
99+ new_node. set_position_with_point ( Point :: new (
100+ p. end_world . x - offset. x ,
101+ p. end_world . y - offset. y ,
102+ ) ) ;
89103
90104 let edge = match source. kind ( ) {
91105 PortKind :: Output => {
0 commit comments