fix: use character as insert_text for character-valued ANSI_SEQUENCES entries - #2089
fix: use character as insert_text for character-valued ANSI_SEQUENCES entries#2089dajiaohuang wants to merge 1 commit into
Conversation
… entries When a character-valued entry is added to ANSI_SEQUENCES (e.g., for xterm modifyOtherKeys support), the KeyPress data should be the character, not the raw escape sequence. Otherwise, self-insert bindings will insert the escape sequence instead of the character. Fixes prompt-toolkit#2086
|
Thanks for picking this up — I filed #2086 and had not expected a fix this quickly. I have verified the patch rather than just read it, because the issue was terse and I owed The bug reproduces on a clean install, no downstream patches, prompt_toolkit 3.0.52: from prompt_toolkit.input.vt100_parser import Vt100Parser
from prompt_toolkit.input.ansi_escape_sequences import ANSI_SEQUENCES
ANSI_SEQUENCES["\x1b[27;2;78~"] = "N" # Shift+N via xterm modifyOtherKeys=2
out = []; Vt100Parser(out.append).feed("\x1b[27;2;78~")
# KeyPress(key='N', data='\x1b[27;2;78~')
With this PR applied to that commit: Test suite, run against the cloned source rather than an installed wheel ( And the new test is genuinely red on base — stashing only One data point on the shape of the fix, since
The tuple and bracketed-paste branches return before this line, and for a plain typed Why it matters beyond the one-line repro: every project adding xterm modifyOtherKeys or |
Description
When a character-valued entry is added to
ANSI_SEQUENCES(e.g., for xterm modifyOtherKeys support), theKeyPressdata should be the character, not the raw escape sequence. Otherwise, self-insert bindings will insert the escape sequence instead of the character.Fixes
Fixes #2086
Changes
src/prompt_toolkit/input/vt100_parser.py: In_call_handler, whenkeyis a plain character (not aKeysmember), use the character asinsert_textinstead of the raw escape sequencetests/test_inputstream.py: Add regression testtest_character_valued_ansi_sequenceBehavior Change
Before:
ANSI_SEQUENCES["\x1b[27;2;78~"] = "N"would causeKeyPress("N", "\x1b[27;2;78~")to be created, and self-insert would insert the raw escape sequenceAfter:
KeyPress("N", "N")is created, and self-insert correctly inserts "N"