Skip to content

Commit 1f28287

Browse files
authored
Make 'ViForwardChar' able to accept suggestions (#1528)
1 parent ba5294f commit 1f28287

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

PSReadLine/Movement.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ private static void ViForwardChar(ConsoleKeyInfo? key = null, object arg = null)
9191
{
9292
if (TryGetArgAsInt(arg, out var numericArg, 1))
9393
{
94-
ViOffsetCursorPosition(+ numericArg);
94+
if (InViInsertMode() && _singleton._current == _singleton._buffer.Length && numericArg > 0)
95+
{
96+
AcceptSuggestion(key, arg);
97+
}
98+
else
99+
{
100+
ViOffsetCursorPosition(+ numericArg);
101+
}
95102
}
96103
}
97104

PSReadLine/UndoRedo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ public static void Undo(ConsoleKeyInfo? key = null, object arg = null)
9292
}
9393
_singleton._edits[_singleton._undoEditIndex - 1].Undo();
9494
_singleton._undoEditIndex--;
95+
9596
if (_singleton._options.EditMode == EditMode.Vi && _singleton._current >= _singleton._buffer.Length)
9697
{
97-
_singleton._current = Math.Max(0, _singleton._buffer.Length - 1);
98+
_singleton._current = Math.Max(0, _singleton._buffer.Length + ViEndOfLineFactor);
9899
}
99100
_singleton.Render();
100101
}

test/SuggestionTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,40 @@ public void HistoryEditsCanUndoProperly()
289289
TokenClassification.None, " checkout ")),
290290
_.Escape));
291291
}
292+
293+
[SkippableFact]
294+
public void AcceptSuggestionInVIMode()
295+
{
296+
TestSetup(KeyMode.Vi);
297+
298+
SetHistory("echo -bar", "eca -zoo");
299+
Test("ech", Keys(
300+
'e', CheckThat(() => AssertScreenIs(1,
301+
TokenClassification.Command, 'e',
302+
TokenClassification.Prediction, "ca -zoo")),
303+
'c', CheckThat(() => AssertScreenIs(1,
304+
TokenClassification.Command, "ec",
305+
TokenClassification.Prediction, "a -zoo")),
306+
'h', CheckThat(() => AssertScreenIs(1,
307+
TokenClassification.Command, "ech",
308+
TokenClassification.Prediction, "o -bar")),
309+
CheckThat(() => AssertCursorLeftIs(3)),
310+
_.RightArrow, CheckThat(() => AssertScreenIs(1,
311+
TokenClassification.Command, "echo",
312+
TokenClassification.None, ' ',
313+
TokenClassification.Parameter, "-bar")),
314+
CheckThat(() => AssertCursorLeftIs(9)),
315+
_.Ctrl_z, CheckThat(() => AssertScreenIs(1,
316+
TokenClassification.Command, "ech",
317+
TokenClassification.Prediction, "o -bar")),
318+
CheckThat(() => AssertCursorLeftIs(3)),
319+
320+
_.RightArrow, _.Escape,
321+
CheckThat(() => AssertCursorLeftIs(8)),
322+
_.Ctrl_z, CheckThat(() => AssertScreenIs(1,
323+
TokenClassification.Command, "ech")),
324+
CheckThat(() => AssertCursorLeftIs(2))
325+
));
326+
}
292327
}
293328
}

0 commit comments

Comments
 (0)