You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bck-i-search (Ctrl-R) quits accepting input when it finds a very long command #1083
When I press Ctrl-R, I keep having this gigantic line I once pasted in pop up in the history and clobber the bck-i-search. All the keyboard input then goes at the end of the giant command and so I can't finish typing into bck-i-search the rest of what I wanted to search for. Worse still, Ctrl-C does not get me out, and Ctrl-D just puts ^D on the end of the command. Up arrow does get me out, but causes the below exception.
Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -4965.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.HistoryRecall(Int32 direction)
at Microsoft.PowerShell.PSConsoleReadLine.PreviousHistory(Nullable1 key, Object arg) at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
Nathan Harvey (@Narvey), you should give PSReadline 2.0.0-beta5 a try, from PowerShellGallery. I cannot say that it will help or entirely eliminate the issue, but a better error report may be possible, knowing how the latest version handles.
The ArgumentOutOfRangeException exception should be fixed in 2.0.0-beta5, but I'm curious about the clobber the bck-i-search part. Like Carl Morris (@msftrncs) suggested, can you please try 2.0.0-beta5 and if that doesn't work too, please provide a repro.
Nathan Harvey (@Narvey) I will close this issue. If you run into the same issue with 2.0.0-beta5, please re-open the issue and provide a repro. Thanks.
Dongbo Wang (@daxian-dbw), I just had this issue occur on me, when using the CTRL-R search in a 7.0.0-preview5 session in VS Code's terminal, when the resulting found history item was longer than the terminal buffer (which is only a few lines (19). Then things became really goofy, because the search prompt remained on the screen, but keypresses edited the command that was pulled up, even after pressing escape I could not close the search using escape. instead I had to press CTRL-R or CTRL-S to get the input going back to the right place, without any exceptions occurring, and then press escape.
Edit: It was a PowerShell Integrated Console, incase that becomes important.
Reference code (you will probably not be able to paste this in to VS Code's terminal)
(
$ZQZV# because its unique# 2# 3# 4# 5# 6# 7# 8# 9# 10
)
After entering the above as a command and posting it to history, press CTRL-R and type ZQ, the searched for text will scroll off the top of the buffer and an exception will occur.
Exception
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was -2.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.Internal.VirtualTerminal.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Render()
at Microsoft.PowerShell.PSConsoleReadLine.UpdateFromHistory(HistoryMoveCursor moveCursor)
at Microsoft.PowerShell.PSConsoleReadLine.UpdateHistoryDuringInteractiveSearch(String toMatch, Int32 direction, Int32& searchFromPoint)
at Microsoft.PowerShell.PSConsoleReadLine.InteractiveHistorySearchLoop(Int32 direction)
at Microsoft.PowerShell.PSConsoleReadLine.InteractiveHistorySearch(Int32 direction)
at Microsoft.PowerShell.PSConsoleReadLine.ReverseSearchHistory(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
Any less than the # 10 line wouldn't do it... the text that gets selected has to be more than one line off the screen, probably because the exception occurs when the bck-i-search: z_ appears. However, with a 1 line shorter version, the an exception happens when you try to move off this particular item, probably because the selection, which was on the screen initially when it was highlighted, is no longer when it goes to clear it.
The exception when the search is cleared (when it hadn't first asserted an exception) is different:
Exception
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Text.StringBuilder.get_Chars(Int32 index)
at Microsoft.PowerShell.PSConsoleReadLine.ConvertOffsetToPoint(Int32 offset)
at Microsoft.PowerShell.PSConsoleReadLine.RecomputeInitialCoords()
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Render()
at Microsoft.PowerShell.PSConsoleReadLine.ClearStatusMessage(Boolean render)
at Microsoft.PowerShell.PSConsoleReadLine.InteractiveHistorySearch(Int32 direction)
at Microsoft.PowerShell.PSConsoleReadLine.ReverseSearchHistory(Nullable`1 key, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
// 1. when you are adding characters to the first line in the buffer (top = 0) to make the logical line
// wrap to one extra physical line. This would cause the buffer to scroll up and push the line being
// edited up-off the buffer.
// 2. when you are deleting characters backwards from the first line in the buffer without changing the
// number of physical lines (either editing the same logical line or causing the current logical line
// to merge in the previous but still span to the current physical line). The cursor is supposed to
// appear in the previous line (which is off the buffer).
//
// In these case, we move the cursor to the upper-left-most position of the window, where it's closest to
// the previous editing position, and update '_current' appropriately.
_current+=(bufferWidth-point.X);
point.X=point.Y=0;
So the _current value gets set to some ridiculous point way past the end of the command buffer. In this case, the entire command is shorter than the bufferWidth.
Activity
msftrncs commentedon Oct 4, 2019
Nathan Harvey (@Narvey), you should give PSReadline 2.0.0-beta5 a try, from PowerShellGallery. I cannot say that it will help or entirely eliminate the issue, but a better error report may be possible, knowing how the latest version handles.
daxian-dbw commentedon Oct 4, 2019
The
ArgumentOutOfRangeExceptionexception should be fixed in2.0.0-beta5, but I'm curious about theclobber the bck-i-searchpart. Like Carl Morris (@msftrncs) suggested, can you please try2.0.0-beta5and if that doesn't work too, please provide a repro.daxian-dbw commentedon Oct 7, 2019
Nathan Harvey (@Narvey) I will close this issue. If you run into the same issue with
2.0.0-beta5, please re-open the issue and provide a repro. Thanks.msftrncs commentedon Oct 25, 2019
Dongbo Wang (@daxian-dbw), I just had this issue occur on me, when using the CTRL-R search in a 7.0.0-preview5 session in VS Code's terminal, when the resulting found history item was longer than the terminal buffer (which is only a few lines (19). Then things became really goofy, because the search prompt remained on the screen, but keypresses edited the command that was pulled up, even after pressing escape I could not close the search using escape. instead I had to press CTRL-R or CTRL-S to get the input going back to the right place, without any exceptions occurring, and then press escape.
Edit: It was a PowerShell Integrated Console, incase that becomes important.
daxian-dbw commentedon Oct 25, 2019
Thanks Carl Morris (@msftrncs). Re-open this issue.
msftrncs commentedon Oct 26, 2019
To produce a good reproduction of this issue
Reference code (you will probably not be able to paste this in to VS Code's terminal)
After entering the above as a command and posting it to history, press CTRL-R and type
ZQ, the searched for text will scroll off the top of the buffer and an exception will occur.Exception
Any less than the
# 10line wouldn't do it... the text that gets selected has to be more than one line off the screen, probably because the exception occurs when thebck-i-search: z_appears. However, with a 1 line shorter version,thean exception happens when you try to move off this particular item,probably because the selection, which was on the screen initially when it was highlighted, is no longer when it goes to clear it.msftrncs commentedon Oct 26, 2019
Its purposely trying to put the cursor where the text was found, but that location has scrolled off the screen.
msftrncs commentedon Oct 26, 2019
The exception when the search is cleared (when it hadn't first asserted an exception) is different:
Exception
msftrncs commentedon Oct 26, 2019
In the case of this second exception, the
point.Yvalue is -1, and its under neither of the two cases in the comment atPSReadLine/PSReadLine/Render.cs
Lines 796 to 810 in 664b168
So the
_currentvalue gets set to some ridiculous point way past the end of the command buffer. In this case, the entire command is shorter than thebufferWidth.msftrncs commentedon Oct 28, 2019
Experimenting with a solution for this, seems the code causing the exception when right-click pasting in Windows Terminal might be closely related.
adityapatwardhan commentedon Dec 17, 2019
I am also reproing this on RC1