Ejemplo n.º 1
0
 public void Input5()
 {
     _mode.Process('c');
     _mode.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Back));
     _mode.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Back));
     Assert.Equal(String.Empty, _modeRaw.Command);
 }
Ejemplo n.º 2
0
        public void ChangeKeyModifiers_WontChangeChar()
        {
            var ki  = KeyInputUtil.VimKeyToKeyInput(VimKey.OpenBracket);
            var ki2 = KeyInputUtil.ChangeKeyModifiers(ki, KeyModifiers.Shift);

            Assert.AreEqual(ki.Char, ki2.Char);
        }
Ejemplo n.º 3
0
        private Key VimKeyToKey(VimKey vimKey)
        {
            switch (vimKey)
            {
            case VimKey.Escape:
                return(Key.Escape);

            case VimKey.Back:
                return(Key.Back);

            case VimKey.Up:
                return(Key.Up);

            case VimKey.Right:
                return(Key.Right);

            case VimKey.Down:
                return(Key.Down);

            case VimKey.Left:
                return(Key.Left);
            }

            var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);

            if (char.IsLetter(keyInput.Char))
            {
                return(StringToKey(keyInput.Char.ToString()));
            }

            throw new Exception(string.Format("Can't convert {0} to a Wpf Key", vimKey));
        }
Ejemplo n.º 4
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:
                _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Up));
                e.Handled = true;
                break;

            case Key.Down:
                _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Down));
                e.Handled = true;
                break;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Run the specified VimKey against the buffer
 /// </summary>
 internal void Run(params VimKey[] keys)
 {
     foreach (var key in keys)
     {
         Run(KeyInputUtil.VimKeyToKeyInput(key));
     }
 }
Ejemplo n.º 6
0
            public void ShouldSkip_ArrowKeys()
            {
                var binding = CreateCommandKeyBinding(KeyInputUtil.VimKeyToKeyInput(VimKey.Left));

                Create();
                Assert.True(_serviceRaw.ShouldSkip(binding));
            }
Ejemplo n.º 7
0
            public void ShouldSkip_FunctionKeys()
            {
                var binding = CreateCommandKeyBinding(KeyInputUtil.VimKeyToKeyInput(VimKey.F2));

                Create();
                Assert.False(_serviceRaw.ShouldSkip(binding));
            }
Ejemplo n.º 8
0
 public void Control(ModifierKeys modifiers)
 {
     AssertMap(Key.D2, modifiers, KeyInputUtil.VimKeyToKeyInput(VimKey.Null));
     AssertMap(Key.D6, modifiers, KeyInputUtil.CharToKeyInput((char)('^' - '@')));
     AssertMap(Key.OemMinus, modifiers, KeyInputUtil.CharToKeyInput((char)('_' - '@')));
     AssertMap(Key.OemQuestion, modifiers, KeyInputUtil.CharToKeyInput((char)(0x7f)));
 }
Ejemplo n.º 9
0
            public void Keypad1()
            {
                var left  = KeyInputUtil.CharToKeyInput('+');
                var right = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadPlus);

                Assert.NotEqual(left, right);
            }
Ejemplo n.º 10
0
        public void Keypad2()
        {
            var left  = KeyInputUtil.CharToKeyInput('-');
            var right = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadMinus);

            Assert.AreNotEqual(left, right);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Try and convert the given string into a Visual Studio specific key stroke.
        /// </summary>
        private static bool TryConvertVsSpecificKey(string keystroke, out KeyInput keyInput)
        {
            EnsureVsMap();
            if (_vsMap.TryGetValue(keystroke, out keyInput))
            {
                return(true);
            }

            if (keystroke.StartsWith("Num ", StringComparison.OrdinalIgnoreCase))
            {
                keyInput = null;
                switch (keystroke.ToLower())
                {
                case "num +":
                    keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadPlus);
                    break;

                case "num /":
                    keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadDivide);
                    break;

                case "num *":
                    keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadMultiply);
                    break;

                case "num -":
                    keyInput = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadMinus);
                    break;
                }
                return(keyInput != null);
            }

            keyInput = null;
            return(false);
        }
Ejemplo n.º 12
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);
                ExecuteCommand(_commandText);
                e.Handled = true;
                break;

            case Key.Up:
                _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Up));
                e.Handled = true;
                break;

            case Key.Down:
                _vimBuffer.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Down));
                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

                    //                        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;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);

            Assert.True(OleCommandUtil.TryConvert(keyInput, false, out OleCommandData oleCommandData));
            Assert.Equal(VSConstants.VSStd2K, oleCommandData.Group);
            Assert.Equal(new OleCommandData(cmd), oleCommandData);
        }
Ejemplo n.º 14
0
            public void EscapeLessThanLiteral()
            {
                var set = KeyInputSet.NewTwoKeyInputs(
                    KeyInputUtil.CharToKeyInput('\\'),
                    KeyInputUtil.VimKeyToKeyInput(VimKey.Home));

                AssertMany(@"\<home>", set);
            }
Ejemplo n.º 15
0
        public void Search_EscapeShouldEndTheSearch()
        {
            var result = _capture.GetMotionAndCount('/');

            Assert.True(result.IsNeedMoreInput);
            result.AsNeedMoreInput().Item.BindFunction.Invoke(KeyInputUtil.VimKeyToKeyInput(VimKey.Escape));
            Assert.False(_incrementalSearch.InSearch);
        }
Ejemplo n.º 16
0
        private void WellKnownBothWays(VimKey wellKnownKey, Key key)
        {
            var      left = KeyInputUtil.VimKeyToKeyInput(wellKnownKey);
            KeyInput right;

            Assert.IsTrue(KeyUtil.TryConvertToKeyInput(key, out right));
            Assert.AreEqual(left, right);
        }
Ejemplo n.º 17
0
            public void HandlePageUpNormally()
            {
                var count = 0;

                _vimBuffer.KeyInputProcessed += delegate { count++; };
                _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
                Assert.True(RunQueryStatus(KeyInputUtil.VimKeyToKeyInput(VimKey.PageUp)));
                Assert.Equal(0, count);
            }
Ejemplo n.º 18
0
        public void CanProcessAsCommand_KeypadDivideAsForwardSlash()
        {
            var normalMode = CreateAndAddNormalMode();

            normalMode.Setup(x => x.OnEnter(ModeArgument.None)).Verifiable();
            normalMode.Setup(x => x.CanProcess(KeyInputUtil.VimKeyToKeyInput(VimKey.Forwardslash))).Returns(true);
            _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            Assert.True(_vimBuffer.CanProcess(VimKey.KeypadDivide));
        }
Ejemplo n.º 19
0
 public void Numbers()
 {
     foreach (var i in Enumerable.Range(0, 10))
     {
         var keypadName = "Keypad" + i;
         var keypad     = (VimKey)Enum.Parse(typeof(VimKey), keypadName);
         var equivalent = KeyInputUtil.GetNonKeypadEquivalent(KeyInputUtil.VimKeyToKeyInput(keypad));
         Assert.Equal(i.ToString(), equivalent.Value.Char.ToString());
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Process the VimKey values in sequence
        /// </summary>
        public static bool Process(this IVimBuffer buf, params VimKey[] keys)
        {
            var ret = false;

            foreach (var key in keys)
            {
                ret = buf.Process(KeyInputUtil.VimKeyToKeyInput(key)).IsAnyHandled;
            }
            return(ret);
        }
Ejemplo n.º 21
0
 public static BindResult <T> Run <T>(this BindResult <T> result, params VimKey[] keys)
 {
     foreach (var cur in keys)
     {
         var keyInput = KeyInputUtil.VimKeyToKeyInput(cur);
         Assert.IsTrue(result.IsNeedMoreInput);
         result = result.AsNeedMoreInput().Item.BindFunction.Invoke(keyInput);
     }
     return(result);
 }
Ejemplo n.º 22
0
 public void IsDigit_KeyPad()
 {
     foreach (var cur in Enum.GetValues(typeof(VimKey)).Cast <VimKey>().Where(VimKeyUtil.IsKeypadNumberKey))
     {
         var keyInput = KeyInputUtil.VimKeyToKeyInput(cur);
         Assert.True(keyInput.IsDigit);
         Assert.True(keyInput.RawChar.IsSome());
         Assert.True(CharUtil.IsDigit(keyInput.Char));
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Verify we can convert the given VimKey to the specified command id
        /// </summary>
        private void VerifyConvert(VimKey vimKey, VSConstants.VSStd2KCmdID cmd)
        {
            var            keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);
            Guid           commandGroup;
            OleCommandData oleCommandData;

            Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out oleCommandData));
            Assert.AreEqual(VSConstants.VSStd2K, commandGroup);
            Assert.AreEqual(new OleCommandData(cmd), oleCommandData);
        }
Ejemplo n.º 24
0
 public void IsFunction_All()
 {
     foreach (var number in Enumerable.Range(1, 12))
     {
         var name     = "F" + number;
         var vimKey   = (VimKey)(Enum.Parse(typeof(VimKey), name));
         var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);
         Assert.True(keyInput.IsFunctionKey);
     }
 }
Ejemplo n.º 25
0
        public void QueryStatus_HandleBackspaceNormallyInResharperMode()
        {
            var count = 0;

            _buffer.KeyInputProcessed += delegate { count++; };
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _externalEditorManager.SetupGet(x => x.IsResharperLoaded).Returns(true).Verifiable();
            Assert.IsTrue(RunQueryStatus(KeyInputUtil.VimKeyToKeyInput(VimKey.Back)));
            Assert.AreEqual(0, count);
            _factory.Verify();
        }
Ejemplo n.º 26
0
            public void NotationThenAlpha()
            {
                var opt = KeyNotationUtil.TryStringToKeyInputSet("<Home>a");

                Assert.True(opt.IsSome());
                var list = opt.Value.KeyInputs.ToList();

                Assert.Equal(2, list.Count);
                Assert.Equal(KeyInputUtil.VimKeyToKeyInput(VimKey.Home), list[0]);
                Assert.Equal('a', list[1].Char);
            }
Ejemplo n.º 27
0
        public void ApplyModifiers_ShiftToNonSpecialChar()
        {
            var list = new[] { VimKey.Back, VimKey.Escape, VimKey.Tab };

            foreach (var cur in list)
            {
                var keyInput = KeyInputUtil.VimKeyToKeyInput(cur);
                keyInput = KeyInputUtil.ApplyModifiers(keyInput, KeyModifiers.Shift);
                Assert.Equal(KeyModifiers.Shift, keyInput.KeyModifiers);
            }
        }
Ejemplo n.º 28
0
        internal bool TryProcess(VimKey vimKey)
        {
            var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey);

            if (_vimBuffer.CanProcess(keyInput))
            {
                return(_vimBuffer.Process(keyInput).IsAnyHandled);
            }

            return(false);
        }
Ejemplo n.º 29
0
        public void QueryStatus_Reshaprer_HandlePageUpNormally()
        {
            var count = 0;

            _buffer.KeyInputProcessed += delegate { count++; };
            _buffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(true).Verifiable();
            Assert.True(RunQueryStatus(KeyInputUtil.VimKeyToKeyInput(VimKey.PageUp)));
            Assert.Equal(0, count);
            _factory.Verify();
        }
Ejemplo n.º 30
0
        static AlternateKeyUtil()
        {
            VimKeyToWpfKeyMap   = BuildVimKeyToWpfKeyMap();
            WpfKeyToKeyInputMap = new Dictionary <Key, KeyInput>();

            foreach (var pair in VimKeyToWpfKeyMap)
            {
                var keyInput = KeyInputUtil.VimKeyToKeyInput(pair.Key);
                WpfKeyToKeyInputMap[pair.Value] = keyInput;
            }
        }