/// <summary>
        /// This method handles the KeyInput as it applies to command line editor.  Make sure to
        /// mark the key as handled if we use it here.  If we don't then it will propagate out to
        /// the editor and be processed again
        /// </summary>
        internal void HandleKeyEvent(KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Escape:
                _vimBuffer.Process(KeyInputUtil.EscapeKey);
                ChangeEditKind(EditKind.None);
                e.Handled = true;
                break;

            case Key.Return:
                ExecuteCommand(_margin.CommandLineTextBox.Text);
                e.Handled = true;
                break;

            case Key.J:
            case Key.M:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    ExecuteCommand(_margin.CommandLineTextBox.Text);
                    e.Handled = true;
                }
                break;

            case Key.Up:
                e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up));
                break;

            case Key.Down:
                e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Down));
                break;

            case Key.Home:
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0)
                {
                    _margin.UpdateCaretPosition(EditPosition.Start);
                    e.Handled = true;
                }
                break;

            case Key.End:
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0)
                {
                    _margin.UpdateCaretPosition(EditPosition.End);
                    e.Handled = true;
                }
                break;

            case Key.Left:
                // Ignore left arrow if at start position
                e.Handled = _margin.IsCaretAtStart();
                break;

            case Key.Back:
                // Backspacing past the beginning aborts the command/search.
                if (_margin.CommandLineTextBox.Text.Length <= 1)
                {
                    _vimBuffer.Process(KeyInputUtil.EscapeKey);
                    ChangeEditKind(EditKind.None);
                    e.Handled = true;
                }
                break;

            case Key.Tab:
                InsertIntoCommandLine("\t", putCaretAfter: true);
                var commandText = _margin.CommandLineTextBox.Text;
                UpdateVimBufferStateWithCommandText(commandText);
                e.Handled = true;
                break;

            case Key.R:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    // During edits we are responsible for handling the command line.  Need to
                    // put a " into the box at the edit position
                    InsertIntoCommandLine("\"", putCaretAfter: false);

                    // Now move the buffer into paste wait
                    _vimBuffer.Process(KeyInputUtil.ApplyKeyModifiersToChar('r', VimKeyModifiers.Control));
                }
                break;

            case Key.U:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    var textBox = _margin.CommandLineTextBox;
                    var text    = textBox.Text.Substring(textBox.SelectionStart);
                    textBox.Text = text;

                    UpdateVimBufferStateWithCommandText(text);
                }
                break;

            case Key.P:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('p', VimKeyModifiers.Control));
                }
                break;

            case Key.N:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    e.Handled = HandleHistoryNavigation(KeyInputUtil.ApplyKeyModifiersToChar('n', VimKeyModifiers.Control));
                }
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method handles the KeyInput as it applies to command line editor.  Make sure to
        /// mark the key as handled if we use it here.  If we don't then it will propagate out to
        /// the editor and be processed again
        /// </summary>
        internal void HandleKeyEvent(KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Escape:
                _vimBuffer.Process(KeyInputUtil.EscapeKey);
                ChangeEditKind(EditKind.None);
                e.Handled = true;
                break;

            case Key.Return:
                ExecuteCommand(_margin.CommandLineTextBox.Text);
                e.Handled = true;
                break;

            case Key.Up:
                e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up));
                break;

            case Key.Down:
                e.Handled = HandleHistoryNavigation(KeyInputUtil.VimKeyToKeyInput(VimKey.Up));
                break;

            case Key.Home:
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0)
                {
                    _margin.UpdateCaretPosition(EditPosition.Start);
                    e.Handled = true;
                }
                break;

            case Key.End:
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0)
                {
                    _margin.UpdateCaretPosition(EditPosition.End);
                    e.Handled = true;
                }
                break;

            case Key.Left:
            case Key.Back:
                // Ignore backspace if at start position
                e.Handled = _margin.IsCaretAtStart();
                break;

            case Key.R:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    // During edits we are responsible for handling the command line.  Need to
                    // put a " into the box at the edit position
                    var textBox = _margin.CommandLineTextBox;
                    var text    = textBox.Text;
                    var builder = new StringBuilder();
                    var offset  = textBox.SelectionStart;
                    builder.Append(text, 0, offset);
                    builder.Append('"');
                    builder.Append(text, offset, text.Length - offset);
                    UpdateCommandLine(builder.ToString());
                    textBox.Select(offset, 0);

                    // Now move the buffer into paste wait
                    _vimBuffer.Process(KeyInputUtil.ApplyKeyModifiersToChar('r', VimKeyModifiers.Control));
                }
                break;

            case Key.U:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    var textBox = _margin.CommandLineTextBox;
                    var text    = textBox.Text.Substring(textBox.SelectionStart);
                    textBox.Text = text;

                    UpdateVimBufferStateWithCommandText(text);
                }
                break;
            }
        }