Skip to content

Commit 8e7900b

Browse files
srdubyalzybkr
authored andcommitted
Fixed CompleteMenu in vi insert mode (#656)
Fix by exiting insert mode to clear the GroupEdit and then re-entering insert mode. Fixes #651
1 parent 14c5ee0 commit 8e7900b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

PSReadLine/Completion.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ private string GetUnambiguousPrefix(Collection<CompletionResult> matches, out bo
219219

220220
private void CompleteImpl(bool menuSelect)
221221
{
222+
if (InViInsertMode()) // must close out the current edit group before engaging menu completion
223+
{
224+
ViCommandMode();
225+
ViInsertWithAppend();
226+
}
227+
222228
var completions = GetCompletions();
223229
if (completions == null || completions.CompletionMatches.Count == 0)
224230
return;

PSReadLine/ReadLine.vi.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ public static void ViInsertMode(ConsoleKeyInfo? key = null, object arg = null)
480480
/// </summary>
481481
public static bool InViCommandMode() => _singleton._dispatchTable == _viCmdKeyMap;
482482

483+
/// <summary>
484+
/// Returns true if in Vi Insert mode, otherwise false.
485+
/// </summary>
486+
public static bool InViInsertMode() => _singleton._dispatchTable == _viInsKeyMap;
487+
483488
/// <summary>
484489
/// Temporarily swap in Vi-Command dispatch tables. Used for setting handlers.
485490
/// </summary>

test/BasicEditingTest.VI.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,18 @@ public void ViChange()
726726
));
727727
}
728728

729+
[Fact]
730+
public void ViDefect651()
731+
{
732+
TestSetup(KeyMode.Vi, new KeyHandler("Tab", PSConsoleReadLine.MenuComplete));
733+
734+
Test("ls -Hidden", Keys(
735+
"abcd", _.Escape, "0Cls -H", _.Tab, CheckThat(() => AssertLineIs("ls -Hidden")),
736+
_.Enter
737+
));
738+
}
739+
740+
729741
[Fact]
730742
public void ViInsertLine()
731743
{

test/CompletionTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ internal static CommandCompletion MockedCompleteInput(string input, int cursor,
257257
replacementLength = int.MaxValue;
258258
completions.Add(new CompletionResult("result"));
259259
break;
260+
case "ls -H":
261+
replacementIndex = cursor;
262+
replacementLength = 0;
263+
completions.Add(new CompletionResult("idden"));
264+
break;
260265
case "none":
261266
break;
262267
}

0 commit comments

Comments
 (0)