@@ -19,7 +19,6 @@ import { useShallow } from 'zustand/react/shallow'
1919import { useSession } from '@/lib/auth/auth-client'
2020import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/other/oauth-request-access'
2121import type { OAuthProvider } from '@/lib/oauth'
22- import { DEFAULT_HORIZONTAL_SPACING } from '@/lib/workflows/autolayout/constants'
2322import { BLOCK_DIMENSIONS , CONTAINER_DIMENSIONS } from '@/lib/workflows/blocks/block-dimensions'
2423import { TriggerUtils } from '@/lib/workflows/triggers/triggers'
2524import { useWorkspacePermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
@@ -1312,65 +1311,30 @@ const WorkflowContent = React.memo(() => {
13121311 if ( ! type ) return
13131312 if ( type === 'connectionBlock' ) return
13141313
1315- // Calculate smart position - to the right of existing root-level blocks
1316- const calculateSmartPosition = ( ) : { x : number ; y : number } => {
1317- // Get all root-level blocks (no parentId)
1318- const rootBlocks = Object . values ( blocks ) . filter ( ( b ) => ! b . data ?. parentId )
1319-
1320- if ( rootBlocks . length === 0 ) {
1321- // No blocks yet, use viewport center
1314+ const getViewportCenterPosition = ( ) : { x : number ; y : number } => {
1315+ const flowContainer = document . querySelector ( '.react-flow' )
1316+ if ( ! flowContainer ) {
13221317 return screenToFlowPosition ( {
13231318 x : window . innerWidth / 2 ,
13241319 y : window . innerHeight / 2 ,
13251320 } )
13261321 }
1327-
1328- // Find the rightmost block
1329- let maxRight = Number . NEGATIVE_INFINITY
1330- let rightmostBlockY = 0
1331- for ( const block of rootBlocks ) {
1332- const blockWidth =
1333- block . type === 'loop' || block . type === 'parallel'
1334- ? block . data ?. width || CONTAINER_DIMENSIONS . DEFAULT_WIDTH
1335- : BLOCK_DIMENSIONS . FIXED_WIDTH
1336- const blockRight = block . position . x + blockWidth
1337- if ( blockRight > maxRight ) {
1338- maxRight = blockRight
1339- rightmostBlockY = block . position . y
1340- }
1341- }
1342-
1343- // Position to the right with autolayout spacing
1344- const position = {
1345- x : maxRight + DEFAULT_HORIZONTAL_SPACING ,
1346- y : rightmostBlockY ,
1347- }
1348-
1349- // Ensure position doesn't overlap any container
1350- let container = isPointInLoopNode ( position )
1351- while ( container ) {
1352- position . x =
1353- container . loopPosition . x + container . dimensions . width + DEFAULT_HORIZONTAL_SPACING
1354- container = isPointInLoopNode ( position )
1355- }
1356-
1357- return position
1322+ const rect = flowContainer . getBoundingClientRect ( )
1323+ return screenToFlowPosition ( {
1324+ x : rect . width / 2 ,
1325+ y : rect . height / 2 ,
1326+ } )
13581327 }
13591328
1360- const basePosition = calculateSmartPosition ( )
1329+ const basePosition = getViewportCenterPosition ( )
13611330
13621331 // Special handling for container nodes (loop or parallel)
13631332 if ( type === 'loop' || type === 'parallel' ) {
13641333 const id = crypto . randomUUID ( )
13651334 const baseName = type === 'loop' ? 'Loop' : 'Parallel'
13661335 const name = getUniqueBlockName ( baseName , blocks )
13671336
1368- const autoConnectEdge = tryCreateAutoConnectEdge ( basePosition , id , {
1369- blockType : type ,
1370- targetParentId : null ,
1371- } )
1372-
1373- // Add the container node with default dimensions and auto-connect edge
1337+ // No auto-connect edge for click/Cmd+K - only drag-and-drop gets auto-connect
13741338 addBlock (
13751339 id ,
13761340 type ,
@@ -1383,7 +1347,7 @@ const WorkflowContent = React.memo(() => {
13831347 } ,
13841348 undefined ,
13851349 undefined ,
1386- autoConnectEdge
1350+ undefined
13871351 )
13881352
13891353 return
@@ -1405,13 +1369,7 @@ const WorkflowContent = React.memo(() => {
14051369 const baseName = defaultTriggerName || blockConfig . name
14061370 const name = getUniqueBlockName ( baseName , blocks )
14071371
1408- const autoConnectEdge = tryCreateAutoConnectEdge ( basePosition , id , {
1409- blockType : type ,
1410- enableTriggerMode,
1411- targetParentId : null ,
1412- } )
1413-
1414- // Add the block to the workflow with auto-connect edge
1372+ // No auto-connect edge for click/Cmd+K - only drag-and-drop gets auto-connect
14151373 // Enable trigger mode if this is a trigger-capable block from the triggers tab
14161374 addBlock (
14171375 id ,
@@ -1421,7 +1379,7 @@ const WorkflowContent = React.memo(() => {
14211379 undefined ,
14221380 undefined ,
14231381 undefined ,
1424- autoConnectEdge ,
1382+ undefined ,
14251383 enableTriggerMode
14261384 )
14271385 }
@@ -1438,11 +1396,7 @@ const WorkflowContent = React.memo(() => {
14381396 screenToFlowPosition ,
14391397 blocks ,
14401398 addBlock ,
1441- tryCreateAutoConnectEdge ,
1442- isPointInLoopNode ,
14431399 effectivePermissions . canEdit ,
1444- addNotification ,
1445- activeWorkflowId ,
14461400 checkTriggerConstraints ,
14471401 ] )
14481402
0 commit comments