Python 3.13.0b1 REPL does not travel words when pressing Ctrl+← or Ctrl+→
Bug report
Bug description:
When I type this to older Python REPLs:
>>> text = "I can travel the words."
And I press Ctrl+←, my cursor moves in front of w. I can press Ctrl+← again to go in front of the t etc. I can then press Ctrl+→ to travel the words in the other direction. My bash behaves the same. Again, I don't know if this is Fedora's configuration of readline, or the default.
In Python 3.13.0b1 REPL, this no longer works. Pressing Ctrl+← or Ctrl+→ seemingly does nothing.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-119248
It seems that Ctrl+← is converted into ctrl left which is treated as an invalid character (same for Ctrl+→). Not sure how to represent this key combination in the keymap but this dirty hack makes it work:
diff --git a/Lib/_pyrepl/input.py b/Lib/_pyrepl/input.py
index 21c24eb5cd..0b804e9252 100644
--- a/Lib/_pyrepl/input.py
+++ b/Lib/_pyrepl/input.py
@@ -61,6 +61,8 @@ def empty(self) -> bool:
class KeymapTranslator(InputTranslator):
def __init__(self, keymap, verbose=False, invalid_cls=None, character_cls=None):
self.verbose = verbose
from .keymap import compile_keymap, parse_keys
@@ -73,7 +75,14 @@ def __init__(self, keymap, verbose=False, invalid_cls=None, character_cls=None):
d[keyseq] = command
if self.verbose:
print(d)
self.k = self.ck = compile_keymap(d, ())
+ self.k['ctrl left'] = 'backward-word'
+ self.k['ctrl right'] = 'forward-word'
self.results = deque()
See https://github.com/python/cpython/issues/119034#issuecomment-2121142576 for a list of things we will be implementing as additional keyboard mappings.