Skip to content

Commit 288e3c0

Browse files
authored
Clear the previous menu rendering correctly (#1073)
1 parent 5d8554e commit 288e3c0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

PSReadLine/Completion.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ public void DrawMenu(Menu previousMenu, bool menuSelect)
500500
// from a previous menu.
501501
if (cells < bufferWidth)
502502
{
503+
// 'BlankRestOfLine' erases rest of the current line, but the cursor is not moved.
503504
console.BlankRestOfLine();
504505
}
505506

@@ -515,6 +516,14 @@ public void DrawMenu(Menu previousMenu, bool menuSelect)
515516
{
516517
if (Rows < previousMenu.Rows + previousMenu.ToolTipLines)
517518
{
519+
// Rest of the current line was erased, but the cursor was not moved to the next line.
520+
if (console.CursorLeft != 0)
521+
{
522+
// There are lines from the previous rendering that need to be cleared,
523+
// so we are sure there is no need to scroll.
524+
MoveCursorDown(1);
525+
}
526+
518527
Singleton.WriteBlankLines(previousMenu.Rows + previousMenu.ToolTipLines - Rows);
519528
}
520529
}

test/CompletionTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,33 @@ public void PossibleCompletionsPrompt()
146146
"Get-Many2 Get-Many5 Get-Many8 Get-Many11 Get-Many14"))));
147147
}
148148

149+
[SkippableFact]
150+
public void MenuCompletions()
151+
{
152+
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+Spacebar", PSConsoleReadLine.MenuComplete));
153+
154+
_console.Clear();
155+
Test("Get-Many4", Keys(
156+
"Get-Many", _.Ctrl_Spacebar,
157+
CheckThat(() => AssertScreenIs(4,
158+
TokenClassification.Command, "Get-Many",
159+
TokenClassification.Selection, "0", NextLine,
160+
TokenClassification.Selection, "Get-Many0 ",
161+
TokenClassification.None,
162+
"Get-Many3 Get-Many6 Get-Many9 Get-Many12", NextLine,
163+
"Get-Many1 Get-Many4 Get-Many7 Get-Many10 Get-Many13", NextLine,
164+
"Get-Many2 Get-Many5 Get-Many8 Get-Many11 Get-Many14")),
165+
"4",
166+
CheckThat(() => AssertScreenIs(4,
167+
TokenClassification.Command, "Get-Many4", NextLine,
168+
TokenClassification.Selection, "Get-Many4 ", NextLine,
169+
" ", NextLine,
170+
" ", NextLine)),
171+
_.Enter,
172+
_.Enter
173+
));
174+
}
175+
149176
[SkippableFact]
150177
public void ShowTooltips()
151178
{

test/UnitTestReadLine.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum TokenClassification
4949
Type,
5050
Number,
5151
Member,
52+
Selection,
5253
}
5354

5455
public abstract partial class ReadLine
@@ -99,6 +100,7 @@ private enum KeyMode
99100
/*Type*/ ConsoleColor.Yellow,
100101
/*Number*/ ConsoleColor.DarkBlue,
101102
/*Member*/ ConsoleColor.DarkMagenta,
103+
/*Selection*/ ConsoleColor.Black,
102104
};
103105

104106
internal static readonly ConsoleColor[] BackgroundColors = new[]
@@ -114,6 +116,7 @@ private enum KeyMode
114116
/*Type*/ ConsoleColor.Black,
115117
/*Number*/ ConsoleColor.Gray,
116118
/*Member*/ ConsoleColor.Yellow,
119+
/*Selection*/ ConsoleColor.Gray
117120
};
118121

119122
class KeyHandler
@@ -476,7 +479,6 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
476479
{ "ContinuationPrompt", MakeCombinedColor(_console.ForegroundColor, _console.BackgroundColor) },
477480
{ "Emphasis", MakeCombinedColor(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor) },
478481
{ "Error", MakeCombinedColor(ConsoleColor.Red, ConsoleColor.DarkRed) },
479-
{ "Selection", MakeCombinedColor(ConsoleColor.Black, ConsoleColor.Gray) },
480482
}
481483
};
482484

@@ -503,7 +505,7 @@ private void TestSetup(KeyMode keyMode, params KeyHandler[] keyHandlers)
503505
var tokenTypes = new[]
504506
{
505507
"Default", "Comment", "Keyword", "String", "Operator", "Variable",
506-
"Command", "Parameter", "Type", "Number", "Member"
508+
"Command", "Parameter", "Type", "Number", "Member", "Selection"
507509
};
508510
var colors = new Hashtable();
509511
for (var i = 0; i < tokenTypes.Length; i++)

0 commit comments

Comments
 (0)