prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Commit 148833e9 (released in 3.0.4) changed undo's behavior in vi mode
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
It looks like undo behavior when undoing inserted bytes changed unexpectedly between 3.0.3 and 3.0.4.
- Behavior in versions <=3.0.3: an undo (the
ukey when in nav mode) would undo an entire insert at a time. For example, if the user is in nav mode, hitsito enter ins mode, typesasdf, hitsescto get back to nav mode, and hitsu, all four characters ofasdfwould disappear. - Behavior in versions >= 3.0.4 (including master): a vi undo works on a character at a time. If the user is in nav mode, hits
ito enter ins mode, typesasdf, hitsescto get back to nav mode, and hitsu, onlyfdisappears.
Bisecting the codebase led me to commit 148833e9, and stashing random stuff tracked it to this specific change: https://github.com/prompt-toolkit/python-prompt-toolkit/commit/148833e982cc0ed427a862e0d2725b353af39d04#diff-5324a319d7483c6ee86efe14bfdd6dc1ed139f1b6046461681e209b6fc3b79fdL41
I mirrored it here for completeness:
diff --git a/prompt_toolkit/key_binding/bindings/named_commands.py b/prompt_toolkit/key_binding/bindings/named_commands.py
index 4796cf7c..17c1c5c4 100644
--- a/prompt_toolkit/key_binding/bindings/named_commands.py
+++ b/prompt_toolkit/key_binding/bindings/named_commands.py
@@ -38,8 +38,12 @@ def register(name: str) -> Callable[[_T], _T]:
"""
def decorator(handler: _T) -> _T:
- " `handler` is a callable or _Binding. "
- _readline_commands[name] = handler
+ " `handler` is a callable or Binding. "
+ if isinstance(handler, Binding):
+ _readline_commands[name] = handler
+ else:
+ _readline_commands[name] = key_binding()(cast(_Handler, handler))
+
return handler
return decorator
I am not sure of the implication of this change or why it would cause the observed change in behavior, though...
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 with prompt_toolkit/key_binding/bindings/named_commands.py and inspect the register change introduced by commit 148833e9. Reproduce the vi-mode sequence described in the issue and trace how undo handles the inserted bytes. Done means undo once again removes the complete insert, with regression coverage added if the existing test layout identifies a suitable location.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100