prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Unable to redo after undo
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
While tweaking my ipython REPL keybindings, I discovered that buf.redo() never works.
Here is a little script that shows the issue:
#!/usr/bin/env python
from prompt_toolkit import PromptSession
from prompt_toolkit.key_binding import KeyBindings
def dyn_prompt(buf):
def inner():
return f"undo: {len(buf._undo_stack)} | redo: {len(buf._redo_stack)}"
return inner
def main():
kb = KeyBindings()
@kb.add("escape", "u")
def _(event):
event.current_buffer.undo()
@kb.add("escape", "r")
def _(event):
event.current_buffer.redo()
print("Try to type some text, then try: Alt-u to undo | Alt-r to redo")
s = PromptSession("> ", key_bindings=kb)
s.rprompt = dyn_prompt(s.app.current_buffer)
try:
s.prompt()
except (EOFError, KeyboardInterrupt):
pass
if __name__ == "__main__":
main()
- Input
abcdef - RPrompt is now
undo: 6 | redo: 0 - Type
Alt-uto undo (removef) - RPrompt is now
undo: 5 | redo: 1 - Type
Alt-uto undo again (removee) - RPrompt is now
undo: 4 | redo: 1(redo didn't change!) - Type
Alt-rto try to redo (adde) - ⚠️
eis not added, redo didn't work! - RPrompt is now
undo: 5 | redo: 0
Is that the right way to try to use undo/redo ?
Is that a bug on your side maybe?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with the provided PromptSession and KeyBindings script, then inspect the buffer undo() and redo() entry points and their undo/redo stack handling. Done means repeated undo operations preserve the expected redo history and Alt-r restores the removed character, with regression coverage for this sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100