Skip to content

Commit f838ac2

Browse files
committed
Improve ConsoleReadLine input text rendering
1 parent a180e4c commit f838ac2

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

src/PowerShellEditorServices/Console/ConsoleReadLine.cs

+20-31
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ private async Task<string> ReadLine(bool isCommandLine, CancellationToken cancel
170170
int promptStartCol = initialCursorCol;
171171
int promptStartRow = initialCursorRow;
172172

173-
// The effective width of the console is 1 less than
174-
// Console.WindowWidth, all calculations should be
175-
// with respect to that
176-
int consoleWidth = Console.WindowWidth - 1;
173+
int consoleWidth = Console.WindowWidth;
177174

178175
if ((keyInfo.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt ||
179176
(keyInfo.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control)
@@ -223,6 +220,13 @@ private async Task<string> ReadLine(bool isCommandLine, CancellationToken cancel
223220
null,
224221
powerShell);
225222

223+
if (currentCompletion.CompletionMatches.Count == 0)
224+
{
225+
// No completion matches, skip the rest
226+
// TODO: Need to re-render on *NIX?
227+
continue;
228+
}
229+
226230
int replacementEndIndex =
227231
currentCompletion.ReplacementIndex +
228232
currentCompletion.ReplacementLength;
@@ -512,7 +516,8 @@ private int InsertInput(
512516
int replaceLength = 0,
513517
int finalCursorIndex = -1)
514518
{
515-
int consoleWidth = Console.WindowWidth - 1;
519+
// TODO: Right change?
520+
int consoleWidth = Console.WindowWidth;
516521
int previousInputLength = inputLine.Length;
517522

518523
int startCol = -1;
@@ -566,28 +571,17 @@ private int InsertInput(
566571
}
567572

568573
// Re-render affected section
569-
// TODO: Render this in chunks for perf
570-
for (int i = insertIndex;
571-
i < Math.Max(inputLine.Length, previousInputLength);
572-
i++)
573-
{
574-
if (i < inputLine.Length)
575-
{
576-
Console.Write(inputLine[i]);
577-
}
578-
else
579-
{
580-
Console.Write(' ');
581-
}
582-
583-
writeCursorCol++;
574+
Console.Write(
575+
inputLine.ToString(
576+
insertIndex,
577+
inputLine.Length - insertIndex));
584578

585-
if (writeCursorCol == consoleWidth)
586-
{
587-
writeCursorCol = 0;
588-
Console.CursorTop += 1;
589-
Console.CursorLeft = 0;
590-
}
579+
if (inputLine.Length < previousInputLength)
580+
{
581+
Console.Write(
582+
new string(
583+
' ',
584+
previousInputLength - inputLine.Length));
591585
}
592586

593587
// Automatically set the final cursor position to the end
@@ -609,11 +603,6 @@ private int InsertInput(
609603
finalCursorIndex);
610604
}
611605

612-
//Console.Write(
613-
// inputLine.ToString(
614-
// insertIndex,
615-
// inputLine.Length - insertIndex));
616-
617606
// Return the updated cursor index
618607
return finalCursorIndex != -1 ? finalCursorIndex : inputLine.Length;
619608
}

0 commit comments

Comments
 (0)