Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions PSReadLine/Completion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
// getting shorter or longer.
var endOfCommandLine = ConvertOffsetToPoint(_buffer.Length);
var topAdjustment = (endOfCommandLine.Y + 1) - menu.Top;
int oldInitialY = _initialY;

if (topAdjustment != 0)
{
Expand All @@ -877,6 +878,14 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
// Render did not clear the rest of the command line which flowed
// into the menu, so we must do that here.
menu.SaveCursor();

if (oldInitialY > _initialY)
{
// Scrolling happened when drawing the menu, so we need to adjust
// this point as it was calculated before drawing the menu.
endOfCommandLine.Y -= oldInitialY - _initialY;
}

_console.SetCursorPosition(endOfCommandLine.X, endOfCommandLine.Y);
_console.Write(Spaces(_console.BufferWidth - endOfCommandLine.X));
menu.RestoreCursor();
Expand Down
4 changes: 3 additions & 1 deletion PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@ private static string GetPrompt()

internal static bool IsRunningCI(IConsole console)
{
return console.GetType().FullName == "Test.TestConsole";
Type consoleType = console.GetType();
return consoleType.FullName == "Test.TestConsole"
|| consoleType.BaseType.FullName == "Test.TestConsole";
}
}
}
479 changes: 479 additions & 0 deletions test/CompletionTest.cs

Large diffs are not rendered by default.

156 changes: 153 additions & 3 deletions test/DynamicHelpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void DynHelp_GetParameterHelpMultiLine_And_Clear()

Test("Get-MultiLineHelp -OneAndHalf", Keys(
"Get-MultiLineHelp -OneAndHalf", _.Alt_h,
CheckThat(() => AssertScreenIs(9,
CheckThat(() => AssertScreenIs(8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf",
Expand All @@ -172,8 +172,7 @@ public void DynHelp_GetParameterHelpMultiLine_And_Clear()
TokenClassification.None, "60 characters but shorter than 120.",
NextLine,
TokenClassification.None, "Required: false, Position: 0, Default Value: None, Pipeline ",
NextLine,
"Input: True (ByPropertyName, ByValue), WildCard: false")),
TokenClassification.None, "Input: True (ByPropertyName, ByValue), WildCard: false")),
_.LeftArrow,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, "Get-MultiLineHelp",
Expand All @@ -183,6 +182,157 @@ public void DynHelp_GetParameterHelpMultiLine_And_Clear()
));
}

[SkippableFact]
public void DynHelp_GetParameterHelpMultiLine_And_Clear_WithScrolling1()
{
// This test case covers the fix to https://github.com/PowerShell/PSReadLine/issues/2950.
var basicScrollingConsole = new BasicScrollingConsole(keyboardLayout: _, width: 60, height: 10);
TestSetup(basicScrollingConsole, KeyMode.Cmd);

// Write 12 new-lines, so that the next input will be at the last line of the screen buffer.
basicScrollingConsole.Write(new string('\n', 12));
AssertCursorLeftTopIs(0, 9);

Test("Get-MultiLineHelp -OneAndHalf", Keys(
"Get-MultiLineHelp -OneAndHalf",
CheckThat(() => AssertCursorLeftTopIs(29, 9)),
_.Alt_h,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf",
NextLine,
NextLine,
TokenClassification.None, $"-Date <name>",
NextLine,
NextLine,
TokenClassification.None, "DESC: Some very long description that is over the buffer width of ",
TokenClassification.None, "60 characters but shorter than 120.",
NextLine,
TokenClassification.None, "Required: false, Position: 0, Default Value: None, Pipeline ",
TokenClassification.None, "Input: True (ByPropertyName, ByValue), WildCard: false")),
_.Alt_h,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf", NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine)),
_.Alt_h,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf",
NextLine,
NextLine,
TokenClassification.None, $"-Date <name>",
NextLine,
NextLine,
TokenClassification.None, "DESC: Some very long description that is over the buffer width of ",
TokenClassification.None, "60 characters but shorter than 120.",
NextLine,
TokenClassification.None, "Required: false, Position: 0, Default Value: None, Pipeline ",
TokenClassification.None, "Input: True (ByPropertyName, ByValue), WildCard: false")),
_.LeftArrow,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf", NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine)),
_.Enter),
resetCursor: false);
}

[SkippableFact]
public void DynHelp_GetParameterHelpMultiLine_And_Clear_WithScrolling2()
{
// This test case covers the new changes in 'RecomputeInitialCoords', to verify that the
// previous cursor position gets updated when scrolling happens.
var basicScrollingConsole = new BasicScrollingConsole(keyboardLayout: _, width: 60, height: 10);
TestSetup(basicScrollingConsole, KeyMode.Cmd);

// Write 12 new-lines, so that the next input will be at the last line of the screen buffer.
basicScrollingConsole.Write(new string('\n', 12));
AssertCursorLeftTopIs(0, 9);

Test("Get-MultiLineHelp -OneAndHalf", Keys(
"Get-MultiLineHelp -OneAndHalf",
CheckThat(() => AssertCursorLeftTopIs(29, 9)),
_.Alt_h,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf",
NextLine,
NextLine,
TokenClassification.None, $"-Date <name>",
NextLine,
NextLine,
TokenClassification.None, "DESC: Some very long description that is over the buffer width of ",
TokenClassification.None, "60 characters but shorter than 120.",
NextLine,
TokenClassification.None, "Required: false, Position: 0, Default Value: None, Pipeline ",
TokenClassification.None, "Input: True (ByPropertyName, ByValue), WildCard: false")),
_.Escape,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf", NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine)),
// Write more characters after clearing the inline help content, verify that the initial coordinates are up-to-date.
"abc",
CheckThat(() => AssertCursorLeftTopIs(32, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalfabc", NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine)),
_.Backspace, _.Backspace, _.Backspace,
CheckThat(() => AssertCursorLeftTopIs(29, 2)),
CheckThat(() => AssertScreenIs(top: 12, lines: 8,
TokenClassification.Command, "Get-MultiLineHelp",
TokenClassification.None, " ",
TokenClassification.Parameter, "-OneAndHalf", NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine,
NextLine)),
_.Enter),
resetCursor: false);
}

[SkippableFact]
public void DynHelp_GetParameterHelpTwoLines_And_Clear()
{
Expand Down
2 changes: 1 addition & 1 deletion test/InlinePredictionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public void Inline_HistoryAndPluginSource_ExecutionStatus()
[SkippableFact]
public void Inline_TruncateVeryLongSuggestion()
{
TestSetup(new TestConsole(width: 10, height: 2, keyboardLayout: _), KeyMode.Cmd);
TestSetup(new TestConsole(keyboardLayout: _, width: 10, height: 2), KeyMode.Cmd);
using var disp = SetPrediction(PredictionSource.History, PredictionViewStyle.InlineView);

// Truncate long suggestion to make sure the user input is not scrolled up-off the console buffer.
Expand Down
Loading