diff --git a/PSReadLine/Movement.vi.cs b/PSReadLine/Movement.vi.cs index d900233e6..011c146d9 100644 --- a/PSReadLine/Movement.vi.cs +++ b/PSReadLine/Movement.vi.cs @@ -159,14 +159,14 @@ public static void ViEndOfPreviousGlob(ConsoleKeyInfo? key = null, object arg = /// Move the cursor to the end of the current logical line. /// 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; } /// @@ -189,7 +189,7 @@ public static void NextWordEnd(ConsoleKeyInfo? key = null, object arg = null) 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 @@ public static void GotoColumn(ConsoleKeyInfo? key = null, object arg = null) /// Move the cursor to the first non-blank character in the line. /// 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 @@ public static void ViGotoBrace(ConsoleKeyInfo? key = null, object arg = null) private int ViFindBrace(int i) { + if (_buffer.Length == 0) + { + return i; + } + switch (_buffer[i]) { case '{': diff --git a/test/MovementTest.VI.cs b/test/MovementTest.VI.cs index 9bc75e672..09b4fca41 100644 --- a/test/MovementTest.VI.cs +++ b/test/MovementTest.VI.cs @@ -453,6 +453,11 @@ public void ViGotoBrace() "ddi" )); } + + // <%> with empty text buffer should work fine. + Test("", Keys( + _.Escape, _.Percent, + CheckThat(() => AssertCursorLeftIs(0)))); } [SkippableFact]