Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Cmd-z after refocus should not clear subblock. Should be consistent with text input subblocks.

Type of Change

  • Bug fix

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
Copy link

vercel bot commented Dec 21, 2025

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 21, 2025 0:07am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 21, 2025

Greptile Summary

Prevented Cmd-Z after refocus from clearing the code subblock by tracking whether edits have been made since focus.

  • Added hasEditedSinceFocusRef to track edit state between focus events
  • Set flag to true on all edit operations (typing, tag selection, env var selection, drag-and-drop)
  • Reset flag to false on focus to establish new baseline
  • Prevent default undo behavior when flag is false to avoid clearing content after refocus
  • Ensures consistent behavior with text input subblocks

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is straightforward and well-implemented: it adds a simple ref-based flag to track whether edits have occurred since focus, then uses that flag to conditionally prevent undo operations. The implementation is consistent across all edit paths (typing, tag/env var selection, drag-and-drop), properly resets on focus, and the logic is sound. This is a focused bug fix that addresses a specific UX issue without introducing complexity or side effects.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx Adds undo prevention when refocusing without edits to prevent clearing subblock content, consistent with text input behavior

Sequence Diagram

sequenceDiagram
    participant User
    participant CodeEditor
    participant hasEditedSinceFocusRef
    participant StoreValue
    
    User->>CodeEditor: Focus on code editor
    CodeEditor->>hasEditedSinceFocusRef: Set to false
    
    alt User edits code (onChange, tag select, env var select, or drop)
        User->>CodeEditor: Make edit (type, select tag, etc)
        CodeEditor->>hasEditedSinceFocusRef: Set to true
        CodeEditor->>StoreValue: Update store with new value
    end
    
    alt User presses Cmd+Z/Ctrl+Z
        User->>CodeEditor: Press Cmd+Z or Ctrl+Z
        CodeEditor->>hasEditedSinceFocusRef: Check value
        alt hasEditedSinceFocusRef is false
            CodeEditor->>CodeEditor: Prevent default (block undo)
            Note over CodeEditor: Prevents clearing subblock<br/>after refocus without edits
        else hasEditedSinceFocusRef is true
            CodeEditor->>CodeEditor: Allow undo operation
            Note over CodeEditor: Normal undo behavior<br/>for user edits
        end
    end
Loading

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 21, 2025

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@icecrasher321 icecrasher321 merged commit 1ddbac1 into staging Dec 21, 2025
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/code-cmdz branch December 21, 2025 01:12
Sign up for free to 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.

2 participants