mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
Fix GotoBrace to handle the case when the text buffer is empty (#2879)
This commit is contained in:
+19
-14
@@ -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 '{':
|
||||
|
||||
@@ -453,6 +453,11 @@ namespace Test
|
||||
"ddi"
|
||||
));
|
||||
}
|
||||
|
||||
// <%> with empty text buffer should work fine.
|
||||
Test("", Keys(
|
||||
_.Escape, _.Percent,
|
||||
CheckThat(() => AssertCursorLeftIs(0))));
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
|
||||
Reference in New Issue
Block a user