https://github.com/python/cpython/commit/0398d9339217aa0710c0de45a7e9b587136e7129
commit: 0398d9339217aa0710c0de45a7e9b587136e7129
branch: main
author: Alastair Stanley <[email protected]>
committer: ambv <[email protected]>
date: 2024-05-21T18:17:41+02:00
summary:

gh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to new repl (#119248)

add word-skipping ctrl keybindings to new repl

files:
M Lib/_pyrepl/keymap.py
M Lib/_pyrepl/reader.py

diff --git a/Lib/_pyrepl/keymap.py b/Lib/_pyrepl/keymap.py
index e1421730e75717..a303589280e7f1 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 d15a150180811d..2c8c9e7dc4b5da 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -136,7 +136,9 @@ def make_default_commands() -> dict[CommandName, 
type[Command]]:
         (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"),

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to