diff --git a/Src/VimMac/VimKeyProcessor.cs b/Src/VimMac/VimKeyProcessor.cs index eb2917b1e..fc7db648f 100644 --- a/Src/VimMac/VimKeyProcessor.cs +++ b/Src/VimMac/VimKeyProcessor.cs @@ -75,9 +75,32 @@ public override void KeyDown(KeyEventArgs e) // Attempt to map the key information into a KeyInput value which can be processed // by Vim. If this works and the key is processed then the input is considered // to be handled + if (_keyUtil.TryConvertSpecialToKeyInput(e.Event, out KeyInput keyInput)) { + var bufferedKeyInputsWasEmpty = VimBuffer.BufferedKeyInputs.IsEmpty; + handled = TryProcess(keyInput); + + if (handled + && BufferedKeysWasEmptyAndIsEmpty() + && oldMode == ModeKind.Insert + && CharTriggersCompletion(keyInput.Char) + && !_completionBroker.IsCompletionActive(VimBuffer.TextView)) + { + // Because VsVim handled the key press for us in insert mode, + // we need to trigger the completion window to open. + _completionBroker.TriggerCompletion(VimBuffer.TextView); + } + + bool BufferedKeysWasEmptyAndIsEmpty() + { + // We don't want the completion window to appear if we + // have something like `inoremap fd ` + // and we just typed the first 'f' or the 'd' + return bufferedKeyInputsWasEmpty + && VimBuffer.BufferedKeyInputs.IsEmpty; + } } } @@ -94,6 +117,11 @@ public override void KeyDown(KeyEventArgs e) e.Handled = handled; } + private bool CharTriggersCompletion(char c) + { + return c == '_' || c == '.' || char.IsLetterOrDigit(c); + } + /// /// Try and process the given KeyInput with the IVimBuffer. This is overridable by /// derived classes in order for them to prevent any KeyInput from reaching the