Skip to content
Merged
Changes from 5 commits
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
51 changes: 35 additions & 16 deletions PSReadLine/Completion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,25 @@ void EnsureMenuAndInputIsVisible(IConsole console, int tooltipLineCount)
}
}

public void DrawMenu(Menu previousMenu)
public void DrawMenu(Menu previousMenu, bool menuSelect)
{
IConsole console = Singleton._console;

// Move cursor to the start of the first line after our input.
this.Top = Singleton.ConvertOffsetToPoint(Singleton._buffer.Length).Y + 1;
EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0);
if (menuSelect)
{
// Move cursor to the start of the first line after our input.
this.Top = Singleton.ConvertOffsetToPoint(Singleton._buffer.Length).Y + 1;
EnsureMenuAndInputIsVisible(console, tooltipLineCount: 0);

console.CursorVisible = false;
console.SaveCursor();
console.SetCursorPosition(0, this.Top);
console.CursorVisible = false;
console.SaveCursor();
console.SetCursorPosition(0, this.Top);
}
else
{
// Start a new line to show the menu contents
console.Write("\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could write over some of the buffer if you press Tab anywhere that is not the last line, e.g.:

PS> & { Get-C<Tab><Tab>
>> }

After pressing Tab Tab, the screen might look like:

PS> & { Get-C<Tab><Tab>
Get-C1   Get-C2    Get-C3
PS> & { Get-C
>> }

When it should look like:

PS> & { Get-C<Tab><Tab>
>> }
Get-C1   Get-C2    Get-C3
PS> & { Get-C
>> }

Copy link
Contributor Author

@jianyunt jianyunt Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jason, I submitted the fix and tested it. It seems working fine now. Please take a look it again. Thanks!

}

var bufferWidth = console.BufferWidth;
var columnWidth = this.ColumnWidth;
Expand Down Expand Up @@ -532,8 +540,18 @@ public void DrawMenu(Menu previousMenu)
}
}

console.RestoreCursor();
console.CursorVisible = true;
if (menuSelect)
{
console.RestoreCursor();
console.CursorVisible = true;
}
else
{
// Update the cursor coordinates after showing the menu.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this block necessary? InvokePrompt is called immediately after the call site that passes menuSelect: false and InvokePrompt is correctly updating these fields.

I tested briefly with these commented out and didn't see any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We do not need it. I added it because I used Console.Write("\n") before. Removed it now. Thanks.

_singleton._initialX = console.CursorLeft;
_singleton._initialY = console.CursorTop;
_singleton._previousRender = _initialPrevRender;
}
}

public void Clear()
Expand Down Expand Up @@ -591,7 +609,8 @@ public void UpdateMenuSelection(int selectedItem, bool select, bool showTooltips
}
}

if (BufferLines + Rows + toolTipLines > console.WindowHeight)
// The +1 is for a new line after showing the tool tips
if ((Top + Rows + toolTipLines + 1) > console.WindowHeight)
{
showTooltips = false;
}
Expand Down Expand Up @@ -742,8 +761,8 @@ private void PossibleCompletionsImpl(CommandCompletion completions, bool menuSel
}
else
{
menu.DrawMenu(null);
InvokePrompt(key: null, arg: menu.Top + menu.Rows);
menu.DrawMenu(null, menuSelect:false);
InvokePrompt(key: null, arg: _console.CursorTop);
}
}

Expand Down Expand Up @@ -790,7 +809,7 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
var userInitialCompletionLength = userCompletionText.Length;

completions.CurrentMatchIndex = 0;
menu.DrawMenu(null);
menu.DrawMenu(null, menuSelect:true);

bool processingKeys = true;
int previousSelection = -1;
Expand Down Expand Up @@ -821,7 +840,7 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
if (topAdjustment != 0)
{
menu.Top += topAdjustment;
menu.DrawMenu(null);
menu.DrawMenu(null, menuSelect:true);
}
if (topAdjustment > 0)
{
Expand Down Expand Up @@ -898,7 +917,7 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
{
var newMenu = menuStack.Pop();

newMenu.DrawMenu(menu);
newMenu.DrawMenu(menu, menuSelect:true);
previousSelection = -1;

menu = newMenu;
Expand Down Expand Up @@ -960,7 +979,7 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
{
var newMenu = CreateCompletionMenu(newMatches);

newMenu.DrawMenu(menu);
newMenu.DrawMenu(menu, menuSelect:true);
previousSelection = -1;

// Remember the current menu for when we see Backspace.
Expand Down