Skip to content

Commit b995497

Browse files
springcompdaxian-dbw
authored andcommitted
Fix an IndexOutOfRangeException in VI mode (#1200)
1 parent f657c8b commit b995497

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

PSReadLine/Movement.vi.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ public static void ViNextGlob(ConsoleKeyInfo? key = null, object arg = null)
9494
i = _singleton.ViFindNextGlob(i);
9595
}
9696

97-
_singleton.MoveCursor(Math.Min(i, _singleton._buffer.Length - 1));
97+
int newPosition = Math.Min(i, Math.Max(0, _singleton._buffer.Length - 1));
98+
if (newPosition != _singleton._current)
99+
{
100+
_singleton.MoveCursor(newPosition);
101+
}
102+
else
103+
{
104+
Ding();
105+
}
98106
}
99107

100108
/// <summary>

test/MovementTest.VI.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ public void ViDotWordMovement()
364364
));
365365
}
366366

367+
[SkippableFact]
368+
public void ViGlobMovement_EmptyBuffer_Defect1195()
369+
{
370+
TestSetup(KeyMode.Vi);
371+
372+
TestMustDing("", Keys(
373+
_.Escape, "W"
374+
));
375+
}
376+
367377
[SkippableFact]
368378
public void ViCursorMovement()
369379
{

0 commit comments

Comments
 (0)