Skip to content

Commit

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

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

Co-authored-by: Alastair Stanley <alastairstanley@ntlworld.com>
  • Loading branch information
miss-islington and optim-ally authored May 21, 2024
1 parent 256b791 commit 8860f83
Show file tree
Hide file tree
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
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 8860f83

Please sign in to comment.