From 35df56ec8bbd9051bf83cd9f06e5de497699accf Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 6 Jul 2022 11:47:12 -0700 Subject: [PATCH] Fix wrong cursor position in menu completion --- PSReadLine/Completion.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/PSReadLine/Completion.cs b/PSReadLine/Completion.cs index 6506f24c9..0e7f8108f 100644 --- a/PSReadLine/Completion.cs +++ b/PSReadLine/Completion.cs @@ -561,6 +561,7 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips // Determine if showing the tooltip would scroll the top of our buffer off the screen. int lineLength = 0; + bool fullLine = false; for (var i = 0; i < toolTip.Length; i++) { char c = toolTip[i]; @@ -572,8 +573,13 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips if (c == '\r' || c == '\n') { - toolTipLines += 1; - lineLength = 0; + // If we happened to have a full line right before the newline character, then we + // skip this newline character because we already increased the line count. + if (!fullLine) + { + toolTipLines += 1; + lineLength = 0; + } } else { @@ -582,8 +588,14 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips { toolTipLines += 1; lineLength = 0; + + // Indicate that we just had a full line. + fullLine = true; + continue; } } + + fullLine = false; } // The +1 is for the blank line between the menu and tooltips.