Skip to content

Commit

Permalink
pythongh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to n…
Browse files Browse the repository at this point in the history
…ew repl (python#119248)

add word-skipping ctrl keybindings to new repl
  • Loading branch information
optim-ally authored May 21, 2024
1 parent c4722cd commit 0398d93
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 0398d93

Please sign in to comment.