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
Add test
  • Loading branch information
danielhollas committed May 22, 2024
commit 4498c2915721b175a172f52b65b1490c5918235b
9 changes: 5 additions & 4 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ def after_command(self, cmd: Command) -> None:
def calc_complete_screen(self) -> list[str]:
screen = super().calc_complete_screen()
if self.cmpltn_menu_visible:
# We display the completions menu below the current prompt
ly = self.lxy[1] + 1
Comment thread
pablogsal marked this conversation as resolved.
screen[ly:ly] = self.cmpltn_menu
# 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 we're not in the middle of multiline edit, don't append to screeninfo
# since that screws up the position calculation in pos2xy function.
# This is a hack to prevent the cursor jumping
# into the completions menu when pressing left or down arrow.
if self.pos != len(self.buffer):
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
return screen
Expand Down
26 changes: 25 additions & 1 deletion Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def test_global_namespace_completion(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "python")

def test_updown_arrow_with_completion_menu(self):
def test_up_down_arrow_with_completion_menu(self):
"""Up arrow in the middle of unfinished tab completion when the menu is displayed
should work and trigger going back in history. Down arrow should subsequently
get us back to the incomplete command."""
Expand All @@ -571,6 +571,30 @@ def test_updown_arrow_with_completion_menu(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "os.")

# TODO: This test doesn't seem to work as intended, it always succeeds
def test_right_down_arrows_with_completion_menu(self):
"""Right / Down arrows while the tab completion menu is displayed
should do nothing"""
code = "os.\t\t"
namespace = {"os": os}

events = itertools.chain(
code_to_events(code),
[
Event(evt="key", data="down", raw=bytearray(b"\x1bOB")),
Event(evt="key", data="right", raw=bytearray(b"\x1bOC")),
],
code_to_events("\n")
)
reader = self.prepare_reader(events, namespace=namespace)
output = multiline_input(reader, namespace)
self.assertEqual(output, "os.")
# When we press right and/or down arrow while
# the completions menu is displayed,
# the cursor should stay where it was on the line.
self.assertEqual(reader.cmpltn_menu_vis, 1)
self.assertEqual(reader.cxy, (6, 0))

@patch("_pyrepl.readline._ReadlineWrapper.get_reader")
@patch("sys.stderr", new_callable=io.StringIO)
def test_completion_with_warnings(self, mock_stderr, mock_get_reader):
Expand Down