Skip to content

feat(copy-paste): allow cross workflow selection, paste, move for blocks - #2649

Merged
icecrasher321 merged 11 commits into
stagingfrom
feat/sim-540
Dec 31, 2025
Merged

feat(copy-paste): allow cross workflow selection, paste, move for blocks#2649
icecrasher321 merged 11 commits into
stagingfrom
feat/sim-540

Conversation

@icecrasher321

@icecrasher321icecrasher321 commented Dec 31, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Copy/Paste using cmd-c and cmd-v
  • Can select sections of blocks using shift + drag
  • Refactor sockets and undo/redo to use batch update funcs for duplication, add, remove, update position.
  • Remove legacy duplicate variable event handlers

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Dec 31, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentReviewUpdated (UTC)
docsSkippedSkippedDec 31, 2025 10:41am

@greptile-apps

greptile-appsBot commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR implements cross-workflow copy/paste functionality for blocks using Cmd+C and Cmd+V keyboard shortcuts. The implementation refactors the codebase to use batch operations (batch-add-blocks and batch-remove-blocks) instead of individual block operations, improving performance and enabling atomic multi-block operations.

Key Changes:

  • Added clipboard management in WorkflowRegistry with copyBlocks(), preparePasteData(), and hasClipboard() methods
  • Implemented regenerateBlockIds() utility to handle ID regeneration, name uniquification, and reference updates during paste
  • Refactored socket operations to support batch operations with proper validation schemas and permission checks
  • Updated undo/redo system to record batch operations with proper inverse operations
  • Integrated keyboard shortcuts (Cmd+C/Cmd+V) in the workflow canvas
  • Removed legacy duplicate event handlers and cleaned up code

Architecture Improvements:

  • Batch operations are atomic, improving consistency
  • Direct state updates for loops/parallels in collaborativeBatchAddBlocks() bypass individual store methods for efficiency
  • Parent subflow node lists are collected before deletion to avoid race conditions

Confidence Score: 4/5

  • This PR is generally safe to merge with solid architecture and comprehensive test coverage
  • The implementation is well-structured with proper batch operations, undo/redo support, and permission handling. Tests have been updated to reflect the new batch operation patterns. The direct state updates for loops/parallels (line 1371-1380) are intentional for performance. The parent ID collection before deletion addresses potential race conditions. Code is production-ready with good attention to edge cases.
  • No files require special attention - the implementation is solid across all modified files

Important Files Changed

FilenameOverview
apps/sim/stores/workflows/utils.tsAdded utility functions for block preparation, duplication, and ID regeneration for copy/paste functionality
apps/sim/hooks/use-collaborative-workflow.tsRefactored to use batch operations (batch-add-blocks, batch-remove-blocks) replacing individual block operations
apps/sim/hooks/use-undo-redo.tsAdded batch operation recording for undo/redo with proper inverse operation handling
apps/sim/socket/database/operations.tsImplemented batch-add-blocks and batch-remove-blocks database operations with proper subflow handling
apps/sim/stores/workflows/registry/store.tsAdded clipboard management functions (copyBlocks, preparePasteData, hasClipboard) for cross-workflow copy/paste
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsxIntegrated keyboard shortcuts (Cmd+C/Cmd+V) and refactored to use batch operations instead of individual block adds

Sequence Diagram

sequenceDiagram
participant User
participant UI as workflow.tsx
participant Registry as WorkflowRegistry
participant Collab as useCollaborativeWorkflow
participant UndoRedo as useUndoRedo
participant Queue as OperationQueue
participant Socket as Socket Handler
participant DB as Database
Note over User,DB: Copy Operation (Cmd+C)
User->>UI: Press Cmd+C
UI->>Registry: copyBlocks(blockIds)
Registry->>Registry: Store blocks, edges, loops, parallels in clipboard
Note over Registry: Includes nested subflow nodes automatically
Note over User,DB: Paste Operation (Cmd+V)
User->>UI: Press Cmd+V
UI->>Registry: preparePasteData()
Registry->>Registry: regenerateBlockIds()
Note over Registry: Generate new IDs, update references,<br/>apply position offset
Registry-->>UI: {blocks, edges, loops, parallels, subBlockValues}
UI->>Collab: collaborativeBatchAddBlocks()
Note over Collab,DB: Batch Add Blocks Flow
Collab->>Queue: addToQueue(batch-add-blocks operation)
Collab->>Collab: Add blocks to local state
Collab->>Collab: Add edges, loops, parallels
Collab->>Collab: Apply subblock values
Collab->>UndoRedo: recordBatchAddBlocks()
UndoRedo->>UndoRedo: Create operation + inverse
UndoRedo->>UndoRedo: Push to undo stack
Queue->>Socket: emit('workflow-operation')
Socket->>Socket: Validate schema
Socket->>Socket: Check permissions
Socket->>DB: persistWorkflowOperation()
DB->>DB: Insert blocks in transaction
DB->>DB: Insert edges
DB->>DB: Insert subflows (loops/parallels)
DB-->>Socket: Success
Socket->>Socket: Broadcast to other clients
Socket-->>Queue: operation-confirmed
Note over User,DB: Undo Operation
User->>UI: Press Cmd+Z
UI->>UndoRedo: undo()
UndoRedo->>UndoRedo: Pop from undo stack
UndoRedo->>UndoRedo: Get inverse operation
Note over UndoRedo: inverse = batch-remove-blocks
UndoRedo->>Queue: addToQueue(batch-remove-blocks)
UndoRedo->>Collab: Remove blocks locally
Queue->>Socket: emit('workflow-operation')
Socket->>DB: Delete blocks, edges, subflows
Socket->>Socket: Broadcast to other clients
Loading

@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (2)

  1. apps/sim/socket/middleware/permissions.test.ts, line 83-86 (link)

    style: Test description is outdated - read role now allows both update-position and batch-update-positions

  2. apps/sim/socket/middleware/permissions.test.ts, line 263 (link)

    logic: Test uses old 'remove' operation that no longer exists - should use 'batch-remove-blocks'

24 files reviewed, 8 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/docs/content/docs/en/keyboard-shortcuts/index.mdx
Comment threadapps/sim/stores/workflows/utils.ts
Comment threadpackages/testing/src/factories/undo-redo.factory.ts
Comment threadapps/sim/hooks/use-undo-redo.ts Outdated
Comment threadapps/sim/hooks/use-collaborative-workflow.ts
Comment threadapps/sim/socket/database/operations.ts Outdated
@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@icecrasher321
icecrasher321 merged commit bf5d0a5 into stagingDec 31, 2025
10 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/sim-540 branch January 1, 2026 03:00
Sg312 pushed a commit that referenced this pull request Jan 3, 2026
…cks (#2649)
* feat(copy-paste): allow cross workflow selection, paste, move for blocks
* fix drag options
* add keyboard and mouse controls into docs
* refactor sockets and undo/redo for batch additions and removals
* fix tests
* cleanup more code
* fix perms issue
* fix subflow copy/paste
* remove log file
* fit paste in viewport bounds
* fix deselection
waleedlatif1 pushed a commit that referenced this pull request Jan 8, 2026
…cks (#2649)
* feat(copy-paste): allow cross workflow selection, paste, move for blocks
* fix drag options
* add keyboard and mouse controls into docs
* refactor sockets and undo/redo for batch additions and removals
* fix tests
* cleanup more code
* fix perms issue
* fix subflow copy/paste
* remove log file
* fit paste in viewport bounds
* fix deselection
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@icecrasher321