x, y = r.pos2xy()
new_y = y + 1
- if new_y > r.max_row():
+ if r.eol() == len(b):
if r.historyi < len(r.history):
r.select_item(r.historyi + 1)
r.pos = r.eol(0)
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
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
def calc_screen(self) -> list[str]:
screen = super().calc_screen()
if self.cmpltn_menu_visible:
- ly = self.lxy[1]
+ # We display the completions menu below the current prompt
+ ly = self.lxy[1] + 1
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)
+ # 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
def finish(self) -> None:
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."""
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")),
],
actual = reader.screen
self.assertEqual(len(actual), 2)
- self.assertEqual(actual[0].rstrip(), "itertools.accumulate(")
- self.assertEqual(actual[1], f"{code}a")
+ self.assertEqual(actual[0], f"{code}a")
+ self.assertEqual(actual[1].rstrip(), "itertools.accumulate(")
def test_key_press_on_tab_press_once(self):
namespace = {"itertools": itertools}
--- /dev/null
+Show tab completions menu below the current line, which results in less
+janky behaviour, and fixes a cursor movement bug. Patch by Daniel Hollas