-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-118878: Pyrepl: show completions menu below the current line #118939
base: main
Are you sure you want to change the base?
Changes from all commits
dc98b55
eae92aa
9e2170c
da921c1
dd90c2e
4498c29
14805a8
119c01d
c5407d5
af90634
d150136
f7f346a
ce0641d
aa9a3a3
c686ce2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,10 +260,15 @@ def after_command(self, cmd: Command) -> None: | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a version of this already in the works and was going to open a PR but delayed it for the Windows PR to get in first. In my version, I just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, would you mind posting the relevant part of your patch? The problem is not with screen but screeninfo, which is used to calculate cursor position. Have you tried pressing the left or down arrow while the completion menu is displayed? Without the hack below the cursor would jump down into the completions menu in my case, but perhaps you solution works better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this should be enough once #120042 lands. diff --git a/Lib/_pyrepl/completing_reader.py b/Lib/_pyrepl/completing_reader.py
index c11d2dabdd2..db3c26c0627 100644
--- a/Lib/_pyrepl/completing_reader.py
+++ b/Lib/_pyrepl/completing_reader.py
@@ -258,10 +258,7 @@ def after_command(self, cmd: Command) -> None:
def calc_complete_screen(self) -> list[str]:
screen = super().calc_complete_screen()
if self.cmpltn_menu_visible:
- ly = self.lxy[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)
+ screen.extend(self.cmpltn_menu)
return screen
def finish(self) -> None: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to have to look at that PR more closely, but just looking at this patch, it seems that the completions menu would always get appended at the very bottom of the screen right? I thought about doing it this way as well, but I don't know if this will work well during multiline editing. You can imagine a corner case where you would be editing a large multiline code, and the completions menu will appear well below the current cursor position or even outside the visible screen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@lysnikolaou I have now tested your version and for large multiline editing it is indeed a problematic since the menu will always be displayed at the very bottom, even if you're editing a line at the very top of screen. For large enough editing context, the menu will not be visible at all (e.g. when editing a first line in a function with many lines. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this problem still relevant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, this PR has no problem afaik. I was pointing out issues with the suggestion above. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the big win here, we no longer need to mess with the cursor when displaying the 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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Show tab completions menu below the current line, which results in less | ||
janky behaviour, and fixes a cursor movement bug. Patch by Daniel Hollas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This an equivalent fix as in #118936