Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Jul 15, 2025

This PR implements undo functionality for the "Enhance prompt with additional context" feature, addressing issue #5741.

Problem

Users reported that after using the enhance prompt feature, their original prompt was lost with no way to undo the changes using common shortcuts like Cmd+Z.

Solution

Added undo functionality that allows users to restore their original prompt after enhancement:

Changes Made

  • State Management: Added originalPromptBeforeEnhancement state to store the original prompt before enhancement
  • Keyboard Shortcut: Implemented Cmd+Z/Ctrl+Z handling to restore the original prompt
  • Auto-clear: Original prompt is cleared when user manually edits the input to prevent stale undo state
  • Dependency Updates: Updated callback dependency arrays to include the new state

How It Works

  1. When user clicks the enhance button, the original prompt is stored
  2. After enhancement, user can press Cmd+Z (Mac) or Ctrl+Z (Windows/Linux) to restore original prompt
  3. Once user manually edits the input, the undo functionality is cleared
  4. Undo only works immediately after enhancement, preventing confusion

Technical Implementation

  • Modified ChatTextArea.tsx component
  • Added keyboard event handling in handleKeyDown function
  • Updated handleEnhancePrompt to store original prompt
  • Updated handleInputChange to clear undo state on manual edits

Testing

  • ✅ TypeScript compilation passes
  • ✅ ESLint checks pass
  • ✅ All existing functionality preserved

Fixes

Closes #5741


Important

Adds undo functionality for enhanced prompts in ChatTextArea.tsx, allowing users to revert changes with Cmd+Z/Ctrl+Z, and updates tests accordingly.

  • Behavior:
    • Adds originalPromptBeforeEnhancement state in ChatTextArea.tsx to store original prompt.
    • Implements Cmd+Z/Ctrl+Z shortcut in handleKeyDown to restore original prompt.
    • Clears original prompt on manual input edits to prevent stale state.
  • Technical Implementation:
    • Updates handleEnhancePrompt in ChatTextArea.tsx to store original prompt.
    • Modifies handleInputChange to clear undo state on edits.
    • Adds keyboard event handling in handleKeyDown.
  • Testing:
    • Adds tests in ChatTextArea.spec.tsx for enhanced prompt response and undo functionality.
    • Updates vitest.setup.ts to force React into development mode for testing.

This description was created by Ellipsis for ad2d05e. You can customize this summary. It will automatically update as commits are pushed.

- Add state to store original prompt before enhancement
- Implement Cmd+Z/Ctrl+Z keyboard shortcut to undo enhancement
- Clear original prompt when user manually edits input
- Fixes #5741: Users can now undo enhanced prompts to restore original text
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 15, 2025 13:27
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 15, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 15, 2025
@mrubens
Copy link
Collaborator

mrubens commented Jul 15, 2025

@roomote-agent is there some way to add it directly to the vscode textarea's undo stack?

Copy link
Author

roomote bot commented Jul 15, 2025

Hi @mrubens! I've seen your comment about integrating with VSCode's textarea undo stack. That's an excellent suggestion - it would provide a more native undo experience. Let me examine the current implementation and explore how we can integrate with VSCode's built-in undo functionality. I'll investigate this and get back to you with findings and implementation options.

- Replace custom undo state management with native browser methods
- Use document.execCommand("insertText") for text replacement to preserve undo history
- Add setRangeText fallback for browsers without execCommand support
- Remove originalPromptBeforeEnhancement state and custom Cmd+Z handling
- Add comprehensive tests for native browser method usage
- Fix React development mode in test environment for act() support

This provides users with the expected VSCode textarea undo experience
when using the enhance prompt feature, as requested in PR feedback.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 15, 2025
Copy link
Author

roomote bot commented Jul 15, 2025

Native Browser Undo Stack Integration Complete

@mrubens I have successfully implemented native browser undo stack integration for the enhance prompt feature as you requested! Here's what was accomplished:

🔧 Implementation Changes

Replaced Custom Undo with Native Browser Methods:

  • ❌ Removed originalPromptBeforeEnhancement state management
  • ❌ Removed custom Cmd+Z/Ctrl+Z keyboard event handling
  • ✅ Implemented document.execCommand('insertText') for text replacement
  • ✅ Added setRangeText() fallback for browser compatibility
  • ✅ Preserved native browser undo history throughout the process

Key Technical Details:

// Focus textarea and select all text
textarea.focus()
textarea.select()

// Use native browser method to replace text while preserving undo history
if (document.execCommand) {
    document.execCommand('insertText', false, message.text)
} else {
    // Fallback for browsers without execCommand support
    textarea.setRangeText(message.text, 0, textarea.value.length, 'select')
    textarea.dispatchEvent(new Event('input', { bubbles: true }))
}

🧪 Testing & Quality Assurance

  • ✅ Added comprehensive test coverage for native browser method usage
  • ✅ Tests verify execCommand('insertText') is called correctly
  • ✅ Tests ensure fallback to setRangeText when execCommand unavailable
  • ✅ Tests validate error handling when textarea ref is not available
  • ✅ Fixed React development mode in test environment for proper act() support
  • ✅ All existing tests continue to pass (33/33 tests passing)

🚀 CI/CD Status

All checks have passed successfully:

  • ✅ TypeScript compilation
  • ✅ Linting (ESLint)
  • ✅ Unit tests (Ubuntu & Windows)
  • ✅ Integration tests
  • ✅ Code analysis & security checks

🎯 User Experience

Users now get the expected VSCode textarea undo experience when using the enhance prompt feature:

  • Cmd+Z/Ctrl+Z will properly undo the enhanced prompt back to the original text
  • Multiple undo levels work as expected with the browser's native undo stack
  • No custom state management means more reliable and predictable behavior
  • Cross-browser compatibility with graceful fallbacks

The implementation provides exactly what you requested - direct integration with VSCode's textarea undo stack instead of custom undo handling. Users can now seamlessly undo enhanced prompts using familiar keyboard shortcuts! 🎉

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 15, 2025
@mrubens mrubens merged commit ab17569 into main Jul 15, 2025
16 checks passed
@mrubens mrubens deleted the feature/enhance-prompt-undo-5741 branch July 15, 2025 14:26
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 15, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 15, 2025
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

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

👍

fxcl added a commit to tameslabs/Roo-Cline that referenced this pull request Jul 16, 2025
* main:
  fix: Resolve confusing auto-approve checkbox states (RooCodeInc#5602)
  fix: prevent empty mode names from being saved (RooCodeInc#5766) (RooCodeInc#5794)
  Format time in ISO 8601 (RooCodeInc#5793)
  fix: resolve DirectoryScanner memory leak and improve file limit handling (RooCodeInc#5785)
  Fix settings dirty check (RooCodeInc#5779)
  feat: increase Ollama API timeout values and extract as constants (RooCodeInc#5778)
  fix: Exclude Terraform and Terragrunt cache directories from checkpoints (RooCodeInc#4601) (RooCodeInc#5750)
  Move less commonly used provider settings into an advanced dropdown (RooCodeInc#5762)
  feat: Add configurable error & repetition limit with unified control (RooCodeInc#5654) (RooCodeInc#5752)
  list-files must include at least the first-level directory contents (RooCodeInc#5303)
  Update evals repo link (RooCodeInc#5758)
  Feature/vertex ai model name conversion (RooCodeInc#5728)
  fix(litellm): handle baseurl with paths correctly (RooCodeInc#5697)
  Add telemetry for todos (RooCodeInc#5746)
  feat: add undo functionality for enhance prompt feature (fixes RooCodeInc#5741) (RooCodeInc#5742)
  Fix max_tokens limit for moonshotai/kimi-k2-instruct on Groq (RooCodeInc#5740)
  Changeset version bump (RooCodeInc#5735)
  Add changeset for v3.23.12 patch release (RooCodeInc#5734)
  Update the max-token calculation in model-params to use the shared logic (RooCodeInc#5720)
  Changeset version bump (RooCodeInc#5719)
  chore: add changeset for v3.23.11 patch release (RooCodeInc#5718)
  Add Kimi K2 model and better support (RooCodeInc#5717)
  Fix: Remove invalid skip-checkout parameter from GitHub Actions workflows (RooCodeInc#5676)
  feat: add Cmd+Shift+. keyboard shortcut for previous mode switching (RooCodeInc#5695)
  Changeset version bump (RooCodeInc#5708)
  chore: add changeset for v3.23.10 patch release (RooCodeInc#5707)
  Add padding to the index model options (RooCodeInc#5706)
  fix: prioritize built-in model dimensions over custom dimensions (RooCodeInc#5705)
  Update CHANGELOG.md
  Changeset version bump (RooCodeInc#5702)
  chore: add changeset for v3.23.9 patch release (RooCodeInc#5701)
  Tweaks to command timeout error (RooCodeInc#5700)
  Update contributors list (RooCodeInc#5639)
  feat: enable Claude Code provider to run natively on Windows (RooCodeInc#5615)
  feat: Add configurable timeout for command execution (RooCodeInc#5668)
  feat: add gemini-embedding-001 model to code-index service (RooCodeInc#5698)
  fix: resolve vector dimension mismatch error when switching embedding models (RooCodeInc#5616) (RooCodeInc#5617)
  fix: [5424] return the cwd in the exec tool's response so that the model is not lost after subsequent calls (RooCodeInc#5667)
  Changeset version bump (RooCodeInc#5670)
  chore: add changeset for v3.23.8 patch release (RooCodeInc#5669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

enhancePrompt should be cancellable through cmd + z
2 participants