Skip to content

Commit 31b14de

Browse files
committed
Add 'AcceptSuggestion'
1 parent b0ff32b commit 31b14de

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

PSReadLine/Movement.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ public static void ForwardChar(ConsoleKeyInfo? key = null, object arg = null)
6161
{
6262
if (TryGetArgAsInt(arg, out var numericArg, 1))
6363
{
64-
SetCursorPosition(_singleton._current + numericArg);
64+
if (_singleton._current == _singleton._buffer.Length && numericArg > 0)
65+
{
66+
AcceptSuggestion();
67+
}
68+
else
69+
{
70+
SetCursorPosition(_singleton._current + numericArg);
71+
}
6572
}
6673
}
6774

PSReadLine/PublicAPI.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,14 @@ public static bool TryGetArgAsInt(object arg, out int numericArg, int defaultNum
236236
return false;
237237
}
238238

239+
/// <summary>
240+
/// Accept the suggestion text if there is one.
241+
/// </summary>
239242
public static void AcceptSuggestion()
240243
{
241244
if (_singleton._suggestionText != null)
242245
{
243-
246+
Replace(0, _singleton._buffer.Length, _singleton._suggestionText);
244247
}
245248
}
246249
}

PSReadLine/Render.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ private string GetSuggestion(string text)
9999
{
100100
if (!_showSuggestion || LineIsMultiLine() || string.IsNullOrWhiteSpace(text))
101101
{
102+
_suggestionText = null;
103+
_lastRenderedTextHash = 0;
102104
return null;
103105
}
104106

0 commit comments

Comments
 (0)