Skip to content

Commit

Permalink
[3.13] gh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to …
Browse files Browse the repository at this point in the history
…new repl (GH-119248) (#119323)

add word-skipping ctrl keybindings to new repl
(cherry picked from commit 0398d93)

Co-authored-by: Alastair Stanley <alastairstanley@ntlworld.com>
miss-islington and optim-ally authored May 21, 2024
1 parent 256b791 commit 8860f83
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Lib/_pyrepl/keymap.py
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
@@ -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"),

0 comments on commit 8860f83

Please sign in to comment.