diff options
-rw-r--r-- | Lib/_pyrepl/keymap.py | 9 | ||||
-rw-r--r-- | 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>", "up"), (r"\<down>", "down"), (r"\<left>", "left"), + (r"\C-\<left>", "backward-word"), (r"\<right>", "right"), + (r"\C-\<right>", "forward-word"), (r"\<delete>", "delete"), (r"\<backspace>", "backspace"), (r"\M-\<backspace>", "backward-kill-word"), |