Skip to content

Fix redo after custom undo bindings - #2083

Open
giri256 wants to merge 1 commit into
prompt-toolkit:mainfrom
giri256:fix/custom-binding-redo
Open

Fix redo after custom undo bindings#2083
giri256 wants to merge 1 commit into
prompt-toolkit:mainfrom
giri256:fix/custom-binding-redo

Conversation

@giri256

@giri256 giri256 commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #1703.

Custom key bindings use save_before=True by default, so the key processor saves the current buffer before calling Buffer.undo() or Buffer.redo(). save_to_undo_stack() previously cleared the redo stack immediately. As a result, a second custom undo discarded the state created by the first undo, and a custom redo discarded its own redo state before it could use it.

This defers redo invalidation until the next actual text change. Undo and redo cancel the pending invalidation because they navigate existing history rather than create a new edit. A normal edit after undo still clears redo.

The new tests cover both behaviors:

  • repeated undo/redo calls with the default pre-handler snapshots preserve the complete history;
  • inserting new text after undo invalidates redo.

Validation:

  • pytest tests/test_buffer.py — 11 passed
  • ruff check src/prompt_toolkit/buffer.py tests/test_buffer.py
  • ruff format --check src/prompt_toolkit/buffer.py tests/test_buffer.py
  • mypy src/prompt_toolkit/buffer.py
  • full suite — 149 passed, 5 skipped, 4 environment/baseline failures; the same four failures reproduce on untouched upstream (2 Windows console-buffer failures and 2 existing CLI history-input failures)

AI assistance was used during diagnosis and implementation. I reproduced the failure before changing code, reviewed the final two-file diff, verified the edit-invalidates-redo control, and classified the full-suite failures against an untouched upstream worktree.

Signed-off-by: p1 <giridharpavan593@gmail.com>
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.

Unable to redo after undo

1 participant