@@ -237,8 +237,50 @@ class ControllerNodeConnectionClass extends ControllerClass {
237237 private mouseUp ( event : MouseEvent ) {
238238 const releaseWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
239239 const releaseTargetEntity = StageManager . findConnectableEntityByLocation ( releaseWorldLocation ) ;
240- // 判断轨迹
241- // 根据点状数组生成折线段
240+
241+ // 根据轨迹判断方向
242+ const [ sourceDirection , targetDirection ] = this . getConnectDirectionByMouseTrack ( ) ;
243+
244+ // 结束连线
245+ if ( releaseTargetEntity !== null ) {
246+ // 在目标节点上弹起
247+
248+ // 区分是拖拽松开连线还是点击松开连线
249+ if ( releaseWorldLocation . distance ( this . _lastRightMousePressLocation ) < 5 ) {
250+ // 距离过近,说明是点击事件,而不是拖拽事件
251+ // 这个可能歪打误撞地被用户触发
252+ this . clickMultiConnect ( releaseWorldLocation ) ;
253+ } else {
254+ // 鼠标在待连接节点上抬起
255+ if ( this . connectToEntity ) {
256+ this . multiConnect ( this . connectToEntity , sourceDirection , targetDirection ) ;
257+ }
258+ }
259+ } else {
260+ // 鼠标在空白位置抬起
261+ // 额外复制一个数组,因为回调函数执行前,这个数组已经被清空了
262+ const newConnectFromEntities = this . connectFromEntities ;
263+
264+ addTextNodeByLocation ( releaseWorldLocation , true , ( uuid ) => {
265+ const createdNode = StageManager . getTextNodeByUUID ( uuid ) as ConnectableEntity ;
266+ for ( const fromEntity of newConnectFromEntities ) {
267+ const connectResult = StageManager . connectEntity ( fromEntity , createdNode ) ;
268+ if ( connectResult ) {
269+ this . addConnectEffect ( fromEntity , createdNode ) ;
270+ }
271+ }
272+ } ) ;
273+ }
274+ this . clear ( ) ;
275+ Controller . setCursorNameHook ( CursorNameEnum . Default ) ;
276+ }
277+
278+ /**
279+ * // 判断轨迹
280+ * // 根据点状数组生成折线段
281+ * @returns
282+ */
283+ private getConnectDirectionByMouseTrack ( ) : [ Direction | null , Direction | null ] {
242284 const lines = [ ] ;
243285 for ( let i = 0 ; i < this . mouseLocations . length - 1 ; i ++ ) {
244286 const start = this . mouseLocations [ i ] ;
@@ -297,40 +339,7 @@ class ControllerNodeConnectionClass extends ControllerClass {
297339 }
298340 }
299341 }
300- console . log ( sourceDirection , targetDirection ) ;
301-
302- // 结束连线
303- if ( releaseTargetEntity !== null ) {
304- // 在目标节点上弹起
305-
306- // 区分是拖拽松开连线还是点击松开连线
307- if ( releaseWorldLocation . distance ( this . _lastRightMousePressLocation ) < 5 ) {
308- // 距离过近,说明是点击事件,而不是拖拽事件
309- // 这个可能歪打误撞地被用户触发
310- this . clickMultiConnect ( releaseWorldLocation ) ;
311- } else {
312- // 鼠标在待连接节点上抬起
313- if ( this . connectToEntity ) {
314- this . multiConnect ( this . connectToEntity , sourceDirection , targetDirection ) ;
315- }
316- }
317- } else {
318- // 鼠标在空白位置抬起
319- // 额外复制一个数组,因为回调函数执行前,这个数组已经被清空了
320- const newConnectFromEntities = this . connectFromEntities ;
321-
322- addTextNodeByLocation ( releaseWorldLocation , true , ( uuid ) => {
323- const createdNode = StageManager . getTextNodeByUUID ( uuid ) as ConnectableEntity ;
324- for ( const fromEntity of newConnectFromEntities ) {
325- const connectResult = StageManager . connectEntity ( fromEntity , createdNode ) ;
326- if ( connectResult ) {
327- this . addConnectEffect ( fromEntity , createdNode ) ;
328- }
329- }
330- } ) ;
331- }
332- this . clear ( ) ;
333- Controller . setCursorNameHook ( CursorNameEnum . Default ) ;
342+ return [ sourceDirection , targetDirection ] ;
334343 }
335344
336345 /**
0 commit comments