Skip to content

feat(input): add undo/redo shortcuts with Ctrl+Z and Ctrl+R#4625

Merged
jacob314 merged 19 commits intogoogle-gemini:mainfrom
masiafrest:feat/undo-redo
Sep 12, 2025
Merged

feat(input): add undo/redo shortcuts with Ctrl+Z and Ctrl+R#4625
jacob314 merged 19 commits intogoogle-gemini:mainfrom
masiafrest:feat/undo-redo

Conversation

@masiafrest
Copy link
Copy Markdown
Contributor

TLDR

This PR implements undo (Ctrl+Z) and redo (Ctrl+R) functionality directly within the CLI's input prompt, leveraging existing capabilities to prevent data loss from accidental key presses.

Ctrl+Y is yolo mode so to avoid keymaps conflict choose Ctrl+R for redo

Dive Deeper

Users often type prompts directly into the CLI, and accidental key presses (e.g., Cmd+Delete on macOS instead of Option+Delete) can lead to the complete loss of carefully crafted input. This forces users to resort to external notepads, which disrupts workflow and reduces efficiency.

This change maps the standard keyboard shortcuts for undo and redo to the input prompt, providing a crucial safety net. This improves user experience by offering a familiar text editing feature and enhances productivity by allowing users to stay within the CLI for prompt composition.

The implementation leverages existing undo/redo capabilities within the text-buffer.ts shared component.

Reviewer Test Plan

To validate this change, reviewers can:

  1. Pull this branch locally.
  2. Run the CLI: npm build && npm start
  3. In the input prompt, type some text.
  4. Press Ctrl+Z multiple times to observe the undo functionality.
  5. Press Ctrl+R multiple times to observe the redo functionality.
  6. Verify that text is correctly undone and redone, and that the cursor position behaves as expected.

Testing Matrix

npm run npx Docker Podman Seatbelt
Input Prompt Undo/Redo N/A N/A N/A

Note: The undo/redo functionality is specific to the input prompt UI and should work consistently across different execution environments (npm run, npx). Docker, Podman, and Seatbelt are not directly relevant to the input prompt's text manipulation features.

Linked issues / bugs

Fixes #3509

@masiafrest masiafrest requested a review from a team as a code owner July 21, 2025 23:44
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @masiafrest, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces crucial undo and redo capabilities to the CLI's input prompt, allowing users to recover from accidental key presses and maintain their workflow within the command-line interface. The implementation integrates seamlessly with the existing text buffer logic, providing a familiar text editing experience.

Highlights

  • Input Prompt Functionality: Implemented standard undo (Ctrl+Z) and redo (Ctrl+R) keyboard shortcuts directly within the CLI's input prompt, leveraging existing text-buffer capabilities to enhance user experience and prevent data loss.
  • Documentation Update: Added a new section to the CLI documentation (docs/cli/commands.md) detailing the newly introduced input prompt shortcuts for undo and redo.
  • Test Coverage: Introduced new unit tests for the InputPrompt component to verify that Ctrl+Z correctly triggers the undo functionality and Ctrl+R triggers the redo functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces undo (Ctrl+Z) and redo (Ctrl+R) shortcuts to the CLI input prompt, which is a great usability improvement. The code changes are well-contained, tested, and documented. My review focuses on a minor correctness issue with shortcut handling to ensure a consistent and intuitive user experience.

@gemini-cli gemini-cli bot added kind/enhancement priority/p2 Important but can be addressed in a future release. labels Jul 21, 2025
@NTaylorMullen NTaylorMullen requested a review from jacob314 July 22, 2025 06:12
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

thanks for the pull request. It would be good to get proper undo and redo shortcuts. please add that directly to text-buffer.ts rather than InputPrompt unless the behavior depends on functionality only available in InputPrompt.

@jacob314
Copy link
Copy Markdown
Contributor

any chance you can update this to use text-buffer.ts over the next couple days? would love to be able to land this as a lot of users are asking for undo+redo.

@masiafrest
Copy link
Copy Markdown
Contributor Author

masiafrest commented Jul 24, 2025

any chance you can update this to use text-buffer.ts over the next couple days? would love to be able to land this as a lot of users are asking for undo+redo.

will move it to text-buffer by delete the undo/redo check on inputPrompt and let it default handle with the text-buffer, also will delete the mock test call to undo/redo on inputPrompt.test (since text-buffer.test already test the undo/redo behaviour), so tomorrow maybe will submit those changes

Implement undo/redo functionality in the input prompt using Ctrl+Z and Ctrl+R shortcuts
Update documentation to include the new shortcuts
Add corresponding test cases
Copy link
Copy Markdown
Collaborator

@mattKorwel mattKorwel left a comment

Choose a reason for hiding this comment

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

@masiafrest I think this one is all good to go, setting to merge when tests pass. cc @jacob314

@mattKorwel mattKorwel enabled auto-merge August 22, 2025 18:37
@mattKorwel mattKorwel self-assigned this Aug 22, 2025
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtmCtrl+R!
lgtm

@mattKorwel mattKorwel disabled auto-merge August 22, 2025 18:44
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

Sorry we have to figure out an alternative shortcut to Ctrl+R as Ctrl+R is also important for reverse search.

@mattKorwel
Copy link
Copy Markdown
Collaborator

Actually, I see there is another PR that adds terminal search as ctrl+r. #5539 I think that's a more natural fit for that key combo. marking as needs changes so we can figure out the right keys.

@gemini-cli gemini-cli bot added the Stale label Sep 10, 2025
@jacob314 jacob314 added this pull request to the merge queue Sep 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 12, 2025
@jacob314 jacob314 added this pull request to the merge queue Sep 12, 2025
Merged via the queue into google-gemini:main with commit 811a2e9 Sep 12, 2025
25 checks passed
WangWanyue pushed a commit to WangWanyue/gemini-cli that referenced this pull request Sep 15, 2025
…emini#4625)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
thacio added a commit to thacio/auditaria that referenced this pull request Oct 1, 2025
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
…emini#4625)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p2 Important but can be addressed in a future release.

5 participants