Fix GotoBrace to handle the case when the text buffer is empty (#2879)

This commit is contained in:
Dongbo Wang
2021-09-20 13:49:25 -07:00
committed by GitHub
parent 078a2b3cc4
commit d37599781f
2 changed files with 24 additions and 14 deletions
+19 -14
View File
@@ -159,14 +159,14 @@ namespace Microsoft.PowerShell
/// Move the cursor to the end of the current logical line.
/// </summary>
public static void MoveToEndOfLine(ConsoleKeyInfo? key = null, object arg = null)
{
var eol = GetEndOfLogicalLinePos(_singleton._current);
if (eol != _singleton._current)
{
_singleton.MoveCursor(eol);
}
_singleton._moveToEndOfLineCommandCount++;
_singleton._moveToLineDesiredColumn = int.MaxValue;
{
var eol = GetEndOfLogicalLinePos(_singleton._current);
if (eol != _singleton._current)
{
_singleton.MoveCursor(eol);
}
_singleton._moveToEndOfLineCommandCount++;
_singleton._moveToLineDesiredColumn = int.MaxValue;
}
/// <summary>
@@ -189,7 +189,7 @@ namespace Microsoft.PowerShell
public static void GotoColumn(ConsoleKeyInfo? key = null, object arg = null)
{
int col = arg as int? ?? -1;
if (col < 0)
if (col < 0)
{
Ding();
return;
@@ -210,11 +210,11 @@ namespace Microsoft.PowerShell
/// Move the cursor to the first non-blank character in the line.
/// </summary>
public static void GotoFirstNonBlankOfLine(ConsoleKeyInfo? key = null, object arg = null)
{
var newCurrent = GetFirstNonBlankOfLogicalLinePos(_singleton._current);
if (newCurrent != _singleton._current)
{
_singleton.MoveCursor(newCurrent);
{
var newCurrent = GetFirstNonBlankOfLogicalLinePos(_singleton._current);
if (newCurrent != _singleton._current)
{
_singleton.MoveCursor(newCurrent);
}
}
@@ -234,6 +234,11 @@ namespace Microsoft.PowerShell
private int ViFindBrace(int i)
{
if (_buffer.Length == 0)
{
return i;
}
switch (_buffer[i])
{
case '{':
+5
View File
@@ -453,6 +453,11 @@ namespace Test
"ddi"
));
}
// <%> with empty text buffer should work fine.
Test("", Keys(
_.Escape, _.Percent,
CheckThat(() => AssertCursorLeftIs(0))));
}
[SkippableFact]