Skip to content

Commit e9d4242

Browse files
authored
Fix wrong cursor position in menu completion (#3373)
1 parent fbaba3e commit e9d4242

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

PSReadLine/Completion.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips
561561
// Determine if showing the tooltip would scroll the top of our buffer off the screen.
562562

563563
int lineLength = 0;
564+
bool fullLine = false;
564565
for (var i = 0; i < toolTip.Length; i++)
565566
{
566567
char c = toolTip[i];
@@ -572,8 +573,13 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips
572573

573574
if (c == '\r' || c == '\n')
574575
{
575-
toolTipLines += 1;
576-
lineLength = 0;
576+
// If we happened to have a full line right before the newline character, then we
577+
// skip this newline character because we already increased the line count.
578+
if (!fullLine)
579+
{
580+
toolTipLines += 1;
581+
lineLength = 0;
582+
}
577583
}
578584
else
579585
{
@@ -582,8 +588,14 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips
582588
{
583589
toolTipLines += 1;
584590
lineLength = 0;
591+
592+
// Indicate that we just had a full line.
593+
fullLine = true;
594+
continue;
585595
}
586596
}
597+
598+
fullLine = false;
587599
}
588600

589601
// The +1 is for the blank line between the menu and tooltips.

0 commit comments

Comments
 (0)