Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-118878: pyrepl: Show completion menu below current line
The main advantage of this is that the behaviour is less janky,
since the current line no longer jumps up and down.

This also allows fixing the behaviour of arrow keys when the menu is
displayed.
  • Loading branch information
danielhollas committed May 11, 2024
commit eae92aa9580fbc3a0dfb0b583b49b80a598d3e7a
6 changes: 3 additions & 3 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def do(self) -> None:
x, y = r.pos2xy()
new_y = y + 1

if new_y > r.max_row():
if r.eol() == len(b):
Comment thread
pablogsal marked this conversation as resolved.
if r.historyi < len(r.history):
r.select_item(r.historyi + 1)
r.pos = r.eol(0)
Expand All @@ -303,7 +303,7 @@ def do(self) -> None:
class left(MotionCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
for _ in range(r.get_arg()):
p = r.pos - 1
if p >= 0:
r.pos = p
Expand All @@ -315,7 +315,7 @@ class right(MotionCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
for i in range(r.get_arg()):
for _ in range(r.get_arg()):
p = r.pos + 1
if p <= len(b):
r.pos = p
Expand Down
12 changes: 8 additions & 4 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# types
Command = commands.Command
if False:
from .types import Callback, SimpleContextManager, KeySpec, CommandName
from .types import KeySpec, CommandName


def prefix(wordlist: list[str], j: int = 0) -> str:
Expand Down Expand Up @@ -258,10 +258,14 @@ def after_command(self, cmd: Command) -> None:
def calc_screen(self) -> list[str]:
screen = super().calc_screen()
if self.cmpltn_menu_vis:
ly = self.lxy[1]
ly = self.lxy[1] + 1
Comment thread
pablogsal marked this conversation as resolved.
screen[ly:ly] = self.cmpltn_menu
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
self.cxy = self.cxy[0], self.cxy[1] + len(self.cmpltn_menu)
Comment thread
pablogsal marked this conversation as resolved.
# This is a horrible hack. If we're not in the middle
# of multiline edit, don't append to screeninfo
# since that screws up the position calculation
# in pos2xy function.
if self.pos != len(self.buffer):
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
return screen

def finish(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def test_updown_arrow_with_completion_menu(self):
events = itertools.chain(
code_to_events(code),
[
Event(evt="key", data="down", raw=bytearray(b"\x1bOB")),
Event(evt='key', data='up', raw=bytearray(b'\x1bOA')),
Event(evt="key", data="down", raw=bytearray(b"\x1bOB")),
],
Expand Down