Example #1
0
        /// <summary>
        /// Try to process this KeyInput
        /// </summary>
        internal bool TryProcess(KeyInput keyInput)
        {
            // If this processor is associated with a IVimBuffer then don't fall back to VS commands
            // unless vim is currently disabled
            if (_vimBuffer != null && _vimBuffer.ModeKind != ModeKind.Disabled)
            {
                return(false);
            }

            // When a modal dialog is active don't turn key strokes into commands.  This happens when
            // the editor is hosted as a control in a modal window.  No command routing should
            // take place in this scenario
            if (_vsShell.IsInModalState())
            {
                return(false);
            }

            // Check for any applicable fallback bindings, in order
            VimTrace.TraceInfo("FallbackKeyProcessor::TryProcess {0}", keyInput);
            foreach (var fallbackCommand in _fallbackCommandList)
            {
                if (fallbackCommand.KeyInput == keyInput)
                {
                    return(SafeExecuteCommand(fallbackCommand.Command));
                }
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Try to process this KeyInput
        /// </summary>
        internal bool TryProcess(KeyInput keyInput)
        {
            // If this processor is associated with a IVimBuffer then don't fall back to VS commands
            // unless vim is currently disabled
            if (_vimBuffer != null && _vimBuffer.ModeKind != ModeKind.Disabled)
            {
                _firstChord = null;
                return(false);
            }

            // When a modal dialog is active don't turn key strokes into commands.  This happens when
            // the editor is hosted as a control in a modal window.  No command routing should
            // take place in this scenario
            if (_vsShell.IsInModalState())
            {
                _firstChord = null;
                return(false);
            }

            // Check for any applicable fallback bindings, in order
            VimTrace.TraceInfo("FallbackKeyProcessor::TryProcess {0}", keyInput);
            var findFirstChar      = _firstChord != null ? _firstChord.Char : keyInput.Char;
            var findFirstModifiers = _firstChord != null ? _firstChord.KeyModifiers : keyInput.KeyModifiers;
            var cmds = _fallbackCommandList[findFirstChar]
                       .Where(fallbackCommand => fallbackCommand.KeyBindings[0].KeyModifiers == findFirstModifiers)
                       .OrderBy(fallbackCommand => GetScopeOrder(fallbackCommand.ScopeKind))
                       .ToList();

            if (cmds.Count == 0)
            {
                _firstChord = null;
                return(false);
            }
            else if (cmds.Count == 1 && cmds[0].KeyBindings.Count == 1)
            {
                _firstChord = null;
                var cmd = cmds.First();
                return(SafeExecuteCommand(cmd.Command));
            }
            else if (_firstChord != null)
            {
                var secondChord = cmds
                                  .Where(fallbackCommand => fallbackCommand.KeyBindings[1].KeyModifiers == keyInput.KeyModifiers &&
                                         fallbackCommand.KeyBindings[1].Char == keyInput.Char)
                                  .OrderBy(fallbackCommand => GetScopeOrder(fallbackCommand.ScopeKind))
                                  .ToList();

                if (secondChord.Count == 0)
                {
                    _firstChord = null;
                    return(false);
                }

                _firstChord = null;
                var cmd = secondChord.First();
                return(SafeExecuteCommand(cmd.Command));
            }
            else
            {
                _firstChord = keyInput;
                return(true);
            }
        }