From 8860f83e4b451181e46b0400a4c5019387776b1d Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 21 May 2024 23:16:06 +0200 Subject: =?UTF-8?q?[3.13]=20gh-119035:=20Add=20Ctrl+=E2=86=90=20and=20Ctrl?= =?UTF-8?q?+=E2=86=92=20word-skipping=20keybindings=20to=20new=20repl=20(G?= =?UTF-8?q?H-119248)=20(#119323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add word-skipping ctrl keybindings to new repl (cherry picked from commit 0398d9339217aa0710c0de45a7e9b587136e7129) Co-authored-by: Alastair Stanley --- Lib/_pyrepl/keymap.py | 9 ++++++--- Lib/_pyrepl/reader.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/_pyrepl/keymap.py b/Lib/_pyrepl/keymap.py index 31a0264..9f1aff8 100644 --- a/Lib/_pyrepl/keymap.py +++ b/Lib/_pyrepl/keymap.py @@ -177,9 +177,12 @@ def _parse_key1(key, s): ret = key[s] s += 1 if ctrl: - if len(ret) > 1: - raise KeySpecError("\\C- must be followed by a character") - ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl() + if len(ret) == 1: + ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl() + elif ret in {"left", "right"}: + ret = f"ctrl {ret}" + else: + raise KeySpecError("\\C- followed by invalid key") if meta: ret = ["\033", ret] else: diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index d15a150..2c8c9e7 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -136,7 +136,9 @@ default_keymap: tuple[tuple[KeySpec, CommandName], ...] = tuple( (r"\", "up"), (r"\", "down"), (r"\", "left"), + (r"\C-\", "backward-word"), (r"\", "right"), + (r"\C-\", "forward-word"), (r"\", "delete"), (r"\", "backspace"), (r"\M-\", "backward-kill-word"), -- cgit v0.12