diff --git a/PSReadLine/Position.cs b/PSReadLine/Position.cs
index 0ea31dfce..32068da91 100644
--- a/PSReadLine/Position.cs
+++ b/PSReadLine/Position.cs
@@ -11,28 +11,17 @@ public partial class PSConsoleReadLine
/// The position in the current logical line.
private static int GetBeginningOfLinePos(int current)
{
- var newCurrent = current;
-
- if (_singleton.LineIsMultiLine())
+ int i = Math.Max(0, current);
+ while (i > 0)
{
- int i = Math.Max(0, current);
- while (i > 0)
+ if (_singleton._buffer[--i] == '\n')
{
- if (_singleton._buffer[--i] == '\n')
- {
- i += 1;
- break;
- }
+ i += 1;
+ break;
}
-
- newCurrent = i;
- }
- else
- {
- newCurrent = 0;
}
- return newCurrent;
+ return i;
}
///
@@ -114,7 +103,7 @@ private static int GetFirstNonBlankOfLogicalLinePos(int current)
var newCurrent = beginningOfLine;
- while (IsVisibleBlank(newCurrent))
+ while (newCurrent < _singleton._buffer.Length && IsVisibleBlank(newCurrent))
{
newCurrent++;
}
diff --git a/test/MovementTest.VI.Multiline.cs b/test/MovementTest.VI.Multiline.cs
index a4606079b..68e49ba62 100644
--- a/test/MovementTest.VI.Multiline.cs
+++ b/test/MovementTest.VI.Multiline.cs
@@ -178,6 +178,16 @@ public void ViMoveToFirstNonBlankOfLogicalLine_NoOp_OnEmptyLine()
));
}
+ [SkippableFact]
+ public void ViDefect2050()
+ {
+ TestSetup(KeyMode.Vi);
+
+ Test("", Keys(
+ _.Escape, _.Underbar
+ ));
+ }
+
[SkippableFact]
public void ViMoveToEndOfLine_NoOp_OnEmptyLine()
{