Beispiel #1
0
        /// <summary>
        /// This maps letters which are pressed to a KeyInput value by looking at the virtual
        /// key vs the textual input.  When Visual Studio is processing key mappings it's doing
        /// so in PreTraslateMessage and using the virtual key codes.  We need to simulate this
        /// as best as possible when forwarding keys
        /// </summary>
        private bool TryConvertLetterToKeyInput(KeyEventArgs keyEventArgs, out KeyInput keyInput)
        {
            keyInput = KeyInput.DefaultValue;

            var keyboardDevice = keyEventArgs.Device as KeyboardDevice;
            var keyModifiers   = keyboardDevice != null
                ? _keyUtil.GetKeyModifiers(keyboardDevice.Modifiers)
                : VimKeyModifiers.Alt;

            if (keyModifiers == VimKeyModifiers.None)
            {
                return(false);
            }

            var key = keyEventArgs.Key;

            if (key < Key.A || key > Key.Z)
            {
                return(false);
            }

            var c = (char)('a' + (key - Key.A));

            keyInput = KeyInputUtil.ChangeKeyModifiersDangerous(KeyInputUtil.CharToKeyInput(c), keyModifiers);
            return(true);
        }
Beispiel #2
0
            public void ChangeKeyModifiers_WontChangeChar()
            {
                var ki  = KeyInputUtil.CharToKeyInput('[');
                var ki2 = KeyInputUtil.ChangeKeyModifiersDangerous(ki, VimKeyModifiers.Shift);

                Assert.Equal(ki.Char, ki2.Char);
            }
Beispiel #3
0
        public void ChangeKeyModifiers_WontChangeChar()
        {
            var ki  = KeyInputUtil.VimKeyToKeyInput(VimKey.OpenBracket);
            var ki2 = KeyInputUtil.ChangeKeyModifiersDangerous(ki, KeyModifiers.Shift);

            Assert.Equal(ki.Char, ki2.Char);
        }
Beispiel #4
0
            public void ShiftSymbolDoesNotChangeChar()
            {
                Map("<S-#>", "pound");
                AssertNoMapping("#");
                var keyInput = KeyInputUtil.CharToKeyInput('#');

                keyInput = KeyInputUtil.ChangeKeyModifiersDangerous(keyInput, KeyModifiers.Shift);
                Assert.True(_map.GetKeyMappingResult(keyInput, KeyRemapMode.Normal).IsMapped);
            }
Beispiel #5
0
        public void CompareSemantics()
        {
            var allKeyInputs = Enumerable.Concat(KeyInputUtil.VimKeyInputList, KeyInputUtil.AlternateKeyInputList);
            var all          = allKeyInputs.SelectMany(x => new[] {
                x,
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Control),
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Shift),
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Alt)
            });

            foreach (var left in all)
            {
                foreach (var right in all)
                {
                    var altLeft  = left.GetAlternate();
                    var altRight = right.GetAlternate();
                    var result1  = left.CompareTo(right);
                    var result2  = right.CompareTo(left);
                    if (result1 == result2)
                    {
                        Assert.Equal(0, result1);
                        Assert.Equal(left.GetHashCode(), right.GetHashCode());
                        if (altLeft.IsSome())
                        {
                            Assert.Equal(0, altLeft.Value.CompareTo(right));
                        }
                        if (altRight.IsSome())
                        {
                            Assert.Equal(0, left.CompareTo(altRight.Value));
                        }
                    }
                    else if (result1 < 0)
                    {
                        Assert.True(result2 > 0);
                        if (altLeft.IsSome())
                        {
                            Assert.True(altLeft.Value.CompareTo(right) < 0);
                            Assert.True(right.CompareTo(altLeft.Value) > 0);
                        }
                    }
                    else if (result2 < 0)
                    {
                        Assert.True(result1 > 0);
                        if (altLeft.IsSome())
                        {
                            Assert.True(altLeft.Value.CompareTo(right) > 0);
                            Assert.True(right.CompareTo(altLeft.Value) < 0);
                        }
                    }
                    else
                    {
                        throw new Exception("failed");
                    }
                }
            }
        }
Beispiel #6
0
 public void ChangeKeyModifiers_RemoveShiftWontLowerAlpha()
 {
     foreach (var letter in CharLettersLower)
     {
         var lower        = KeyInputUtil.CharToKeyInput(letter);
         var upper        = KeyInputUtil.CharToKeyInput(Char.ToUpper(letter));
         var upperNoShift = KeyInputUtil.ChangeKeyModifiersDangerous(upper, VimKeyModifiers.None);
         Assert.NotEqual(lower, upperNoShift);
     }
 }
Beispiel #7
0
 public void ChangeKeyModifiers_ShiftWontChangeAlpha()
 {
     foreach (var letter in CharLettersLower)
     {
         var lower          = KeyInputUtil.CharToKeyInput(letter);
         var upper          = KeyInputUtil.CharToKeyInput(Char.ToUpper(letter));
         var lowerWithShift = KeyInputUtil.ChangeKeyModifiersDangerous(lower, VimKeyModifiers.Shift);
         Assert.NotEqual(lowerWithShift, upper);
     }
 }
            public void StringToKeyInput8()
            {
                var ki = KeyInputUtil.CharToKeyInput(' ');

                ki = KeyInputUtil.ChangeKeyModifiersDangerous(ki, VimKeyModifiers.Shift);
                var all = new string[] { "<S-space>", "<S-SPACE>" };

                foreach (var cur in all)
                {
                    Assert.Equal(ki, KeyNotationUtil.StringToKeyInput(cur));
                }
            }
Beispiel #9
0
        /// <summary>
        /// Run the KeyInput directly in the Wpf control
        /// </summary>
        private void RunInWpf(KeyInput keyInput)
        {
            Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(UIPermissionAttribute));
            var presentationSource = _factory.Create <PresentationSource>();

            // Normalize upper case letters here to lower and add the shift key modifier if
            // necessary
            if (Char.IsUpper(keyInput.Char))
            {
                var lowerKeyInput = KeyInputUtil.CharToKeyInput(Char.ToLower(keyInput.Char));
                keyInput = KeyInputUtil.ChangeKeyModifiersDangerous(lowerKeyInput, keyInput.KeyModifiers | KeyModifiers.Shift);
            }

            Key key;

            if (!KeyUtil.TryConvertToKeyOnly(keyInput.Key, out key))
            {
                throw new Exception("Couldn't get the WPF key for the given KeyInput");
            }

            // First raise the KeyDown event
            var keyDownEventArgs = new KeyEventArgs(
                _defaultKeyboardDevice,
                presentationSource.Object,
                0,
                key);

            keyDownEventArgs.RoutedEvent = UIElement.KeyDownEvent;
            _defaultInputController.HandleKeyDown(this, keyDownEventArgs);

            // If the event is handled then return
            if (keyDownEventArgs.Handled)
            {
                return;
            }

            // Now raise the TextInput event
            var textInputEventArgs = new TextCompositionEventArgs(
                _defaultKeyboardDevice,
                new TextComposition(InputManager.Current, _wpfTextView.VisualElement, keyInput.Char.ToString()));

            textInputEventArgs.RoutedEvent = UIElement.TextInputEvent;
            _defaultInputController.HandleTextInput(this, textInputEventArgs);

            var keyUpEventArgs = new KeyEventArgs(
                _defaultKeyboardDevice,
                presentationSource.Object,
                0,
                key);

            keyUpEventArgs.RoutedEvent = UIElement.KeyUpEvent;
            _defaultInputController.HandleKeyUp(this, keyUpEventArgs);
        }
Beispiel #10
0
        public void Equality_AlternatesNotEquivalentWhenModifierPresent()
        {
            Action <KeyInput, KeyInput> func = (left, right) =>
            {
                Assert.NotEqual(KeyInputUtil.ChangeKeyModifiersDangerous(left, KeyModifiers.Control), right);
                Assert.NotEqual(KeyInputUtil.ChangeKeyModifiersDangerous(left, KeyModifiers.Alt), right);
                Assert.NotEqual(KeyInputUtil.ChangeKeyModifiersDangerous(left, KeyModifiers.Shift), right);
            };

            foreach (var cur in KeyInputUtil.AlternateKeyInputPairList)
            {
                func(cur.Item1, cur.Item2);
            }
        }
Beispiel #11
0
        public void CompareSemantics()
        {
            var allKeyInputs = KeyInputUtil.VimKeyInputList;
            var all          = allKeyInputs.SelectMany(x => new[] {
                x,
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Control),
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Shift),
                KeyInputUtil.ChangeKeyModifiersDangerous(x, KeyModifiers.Alt)
            });

            foreach (var left in all)
            {
                foreach (var right in all)
                {
                    var result1 = left.CompareTo(right);
                    var result2 = right.CompareTo(left);
                    if (result1 == result2)
                    {
                        Assert.Equal(0, result1);
                        Assert.Equal(left.GetHashCode(), right.GetHashCode());
                    }
                    else if (result1 < 0)
                    {
                        Assert.True(result2 > 0);
                    }
                    else if (result2 < 0)
                    {
                        Assert.True(result1 > 0);
                    }
                    else
                    {
                        throw new Exception("failed");
                    }
                }
            }
        }