Skip to content

Commit 761a980

Browse files
committed
Fixed cursor placement issues with 'o' & 'O'.
1 parent 8483f0e commit 761a980

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

PSReadLine/ReadLine.vi.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ public static void ViInsertLine(ConsoleKeyInfo? key = null, object arg = null)
981981
_singleton._groupUndoHelper.StartGroup(ViInsertLine, arg);
982982
_singleton.MoveToBeginningOfPhrase();
983983
_singleton._buffer.Insert(_singleton._current, '\n');
984-
_singleton._current = Math.Max(0, _singleton._current - 1);
984+
//_singleton._current = Math.Max(0, _singleton._current - 1);
985985
_singleton.SaveEditItem(EditItemInsertChar.Create( '\n', _singleton._current));
986986
_singleton.Render();
987987
ViInsertMode();
@@ -1016,16 +1016,19 @@ public static void ViAppendLine(ConsoleKeyInfo? key = null, object arg = null)
10161016
{
10171017
_singleton._groupUndoHelper.StartGroup(ViInsertLine, arg);
10181018
_singleton.MoveToEndOfPhrase();
1019+
int insertPoint = 0;
10191020
if (_singleton.IsAtEndOfLine(_singleton._current))
10201021
{
1022+
insertPoint = _singleton._buffer.Length;
10211023
_singleton._buffer.Append('\n');
1024+
_singleton._current = insertPoint;
10221025
}
10231026
else
10241027
{
1025-
_singleton._buffer.Insert(++_singleton._current, '\n');
1028+
insertPoint = _singleton._current + 1;
1029+
_singleton._buffer.Insert(insertPoint, '\n');
10261030
}
1027-
_singleton._current++;
1028-
_singleton.SaveEditItem(EditItemInsertChar.Create('\n', _singleton._current));
1031+
_singleton.SaveEditItem(EditItemInsertChar.Create('\n', insertPoint));
10291032
_singleton.Render();
10301033
ViInsertWithAppend();
10311034
}

UnitTestPSReadLine/BasicEditingTest.VI.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,20 +673,21 @@ public void ViTestChange()
673673
[TestMethod]
674674
public void ViTestInsertLine()
675675
{
676+
int adder = PSConsoleReadlineOptions.DefaultContinuationPrompt.Length;
676677
TestSetup(KeyMode.Vi);
677678

678679
Test("line1\n", Keys(
679680
_.Escape, "Oline1", CheckThat(() => AssertCursorLeftIs(5))
680681
));
681682

682683
Test("\nline1", Keys(
683-
_.Escape, "oline1", CheckThat(() => AssertCursorLeftIs(8)), CheckThat(() => AssertLineIs("\nline1")),
684-
_.Escape, CheckThat(() => AssertCursorLeftIs(7))
684+
_.Escape, "oline1", CheckThat(() => AssertCursorLeftIs(5 + adder)), CheckThat(() => AssertLineIs("\nline1")),
685+
_.Escape, CheckThat(() => AssertCursorLeftIs(4 + adder))
685686
));
686687

687688
Test("", Keys(
688689
"line2", _.Escape, CheckThat(() => AssertLineIs("line2")),
689-
"Oline1", _.Escape, CheckThat(() => AssertLineIs("line1\nline2")),
690+
"Oline1", _.Escape, CheckThat(() => AssertLineIs("line1\nline2")), CheckThat(() => AssertCursorLeftIs(4)),
690691
"joline3", _.Escape, CheckThat(() => AssertLineIs("line1\nline2\nline3")),
691692
'u', CheckThat(() => AssertLineIs("line1\nline2")),
692693
'u', CheckThat(() => AssertLineIs("line2")),
@@ -703,6 +704,16 @@ public void ViTestInsertLine()
703704
'u', CheckThat(() => AssertLineIs("line")),
704705
"uuuu"
705706
));
707+
708+
Test("", Keys(
709+
_.Escape, "oline4", CheckThat(() => AssertLineIs("\nline4")), CheckThat(() => AssertCursorLeftIs(5 + adder)),
710+
_.Escape, "Oline2", CheckThat(() => AssertLineIs("\nline2\nline4")), CheckThat(() => AssertCursorLeftIs(5 + adder)),
711+
_.Escape, "oline3", CheckThat(() => AssertLineIs("\nline2\nline3\nline4")),
712+
_.Escape, CheckThat(() => AssertLineIs("\nline2\nline3\nline4")), CheckThat(() => AssertCursorLeftIs(4 + adder)),
713+
'u', CheckThat(() => AssertLineIs("\nline2\nline4")),
714+
'u', CheckThat(() => AssertLineIs("\nline4")),
715+
'u'
716+
));
706717
}
707718

708719
[TestMethod]

0 commit comments

Comments
 (0)