Ejemplo n.º 1
0
        public void Tab_WithShift()
        {
            var keyInput = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.TabKey, VimKeyModifiers.Shift);

            Assert.Equal(VimKeyModifiers.Shift, keyInput.KeyModifiers);
            VerifyConvert(VSConstants.VSStd2KCmdID.TAB, VimKeyModifiers.Shift, keyInput, EditCommandKind.UserInput);
        }
Ejemplo n.º 2
0
            public void DoubleApplyControl()
            {
                var keyInput1 = KeyInputUtil.CharWithControlToKeyInput(';');
                var keyInput2 = KeyInputUtil.ApplyKeyModifiers(keyInput1, VimKeyModifiers.Control);

                Assert.Equal(keyInput1, keyInput2);
            }
Ejemplo n.º 3
0
            public void UpperCase()
            {
                var keyInput = KeyInputUtil.CharToKeyInput('A');

                Assert.Equal(keyInput, KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput('a'), VimKeyModifiers.Shift));
                Assert.Equal(keyInput, KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput('A'), VimKeyModifiers.Shift));
            }
Ejemplo n.º 4
0
            public void Less()
            {
                var left  = KeyInputUtil.CharWithControlToKeyInput('c');
                var right = KeyInputUtil.ApplyKeyModifiers(left, VimKeyModifiers.None);

                Assert.Equal(left, right);
            }
Ejemplo n.º 5
0
            public void ShiftToTab()
            {
                var keyInput = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.TabKey, VimKeyModifiers.Shift);

                Assert.Equal(VimKeyModifiers.Shift, keyInput.KeyModifiers);
                Assert.Equal(VimKey.Tab, keyInput.Key);
                Assert.Equal('\t', keyInput.Char);
            }
Ejemplo n.º 6
0
 public void CharWithControlToKeyInput_Alpha()
 {
     foreach (var cur in CharLettersLower)
     {
         var left  = KeyInputUtil.CharWithControlToKeyInput(cur);
         var right = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput(cur), VimKeyModifiers.Control);
         Assert.Equal(right, left);
     }
 }
Ejemplo n.º 7
0
            public void ShiftToSpecialChar()
            {
                var list = new[] { '<', '>', '(', '}' };

                foreach (var cur in list)
                {
                    var keyInput = KeyInputUtil.CharToKeyInput(cur);
                    keyInput = KeyInputUtil.ApplyKeyModifiers(keyInput, VimKeyModifiers.Shift);
                    Assert.Equal(VimKeyModifiers.None, keyInput.KeyModifiers);
                }
            }
Ejemplo n.º 8
0
            public void AltMirror()
            {
                const string expected = "\u00C1\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7\u00B8\u00B9";
                const string source   = "A0123456789";

                for (var i = 0; i < source.Length; i++)
                {
                    var left  = KeyInputUtil.CharToKeyInput(expected[i]);
                    var right = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput(source[i]), VimKeyModifiers.Alt);
                    Assert.Equal(left, right);
                }
            }
Ejemplo n.º 9
0
            public void AltMirror()
            {
                const string expected = "Á°±²³´µ¶·¸¹";
                const string source   = "A0123456789";

                for (var i = 0; i < source.Length; i++)
                {
                    var left  = KeyInputUtil.CharToKeyInput(expected[i]);
                    var right = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput(source[i]), VimKeyModifiers.Alt);
                    Assert.Equal(left, right);
                }
            }
Ejemplo n.º 10
0
        bool IKeyUtil.TryConvertSpecialToKeyInput(Key key, ModifierKeys modifierKeys, out KeyInput keyInput)
        {
            if (s_wpfKeyToKeyInputMap.TryGetValue(key, out keyInput))
            {
                var keyModifiers = ConvertToKeyModifiers(modifierKeys);
                keyInput = KeyInputUtil.ApplyKeyModifiers(keyInput, keyModifiers);
                return(true);
            }

            keyInput = null;
            return(false);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Last chance at custom handling of user input.  At this point we have the
        /// advantage that WPF has properly converted the user input into a char which
        /// can be effeciently mapped to a KeyInput value.
        /// </summary>
        public override void TextInput(TextCompositionEventArgs args)
        {
            VimTrace.TraceInfo("VimKeyProcessor::TextInput Text={0} ControlText={1} SystemText={2}",
                               StringUtil.GetDisplayString(args.Text),
                               StringUtil.GetDisplayString(args.ControlText),
                               StringUtil.GetDisplayString(args.SystemText));

            var handled = false;

            var text = args.Text;

            if (string.IsNullOrEmpty(text))
            {
                text = args.ControlText;
            }

            if (!string.IsNullOrEmpty(text))
            {
                // In the case of a failed dead key mapping (pressing the accent key twice for
                // example) we will recieve a multi-length string here.  One character for every
                // one of the mappings.  Make sure to handle each of them
                for (var i = 0; i < text.Length; i++)
                {
                    var keyInput = KeyInputUtil.CharToKeyInput(text[i]);
                    handled = TryProcess(keyInput);
                }
            }
            else if (!string.IsNullOrEmpty(args.SystemText))
            {
                // The system text needs to be processed differently than normal text.  When 'a'
                // is pressed with control it will come in as control text as the proper control
                // character.  When 'a' is pressed with Alt it will come in as simply 'a' and we
                // have to rely on the currently pressed key modifiers to determine the appropriate
                // character
                var keyboardDevice = args.Device as KeyboardDevice;
                var keyModifiers   = keyboardDevice != null
                    ? _keyUtil.GetKeyModifiers(keyboardDevice.Modifiers)
                    : VimKeyModifiers.Alt;

                text = args.SystemText;
                for (var i = 0; i < text.Length; i++)
                {
                    var keyInput = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.CharToKeyInput(text[i]), keyModifiers);
                    handled = TryProcess(keyInput);
                }
            }

            VimTrace.TraceInfo("VimKeyProcessor::TextInput Handled={0}", handled);
            args.Handled = handled;
            base.TextInput(args);
        }
Ejemplo n.º 12
0
            public void ControlToAlpha()
            {
                var baseCharCode = 0x1;

                for (var i = 0; i < CharLettersLower.Length; i++)
                {
                    var target   = (char)(baseCharCode + i);
                    var keyInput = KeyInputUtil.CharToKeyInput(CharLettersLower[i]);
                    var found    = KeyInputUtil.ApplyKeyModifiers(keyInput, VimKeyModifiers.Control);

                    Assert.Equal(target, found.Char);
                    Assert.Equal(VimKeyModifiers.None, found.KeyModifiers);
                }
            }
Ejemplo n.º 13
0
            public void ShiftToNonSpecialChar()
            {
                var list = new[]
                {
                    KeyInputUtil.VimKeyToKeyInput(VimKey.Back),
                    KeyInputUtil.VimKeyToKeyInput(VimKey.Escape),
                    KeyInputUtil.TabKey
                };

                foreach (var current in list)
                {
                    var keyInput = KeyInputUtil.ApplyKeyModifiers(current, VimKeyModifiers.Shift);
                    Assert.Equal(VimKeyModifiers.Shift, keyInput.KeyModifiers);
                }
            }
Ejemplo n.º 14
0
        internal static bool TryConvert(Guid commandGroup, uint commandId, IntPtr pVariableIn, VimKeyModifiers modifiers, out EditCommand command)
        {
            if (!TryConvert(commandGroup, commandId, pVariableIn, out KeyInput keyInput, out EditCommandKind kind, out bool isRawText))
            {
                command = null;
                return(false);
            }

            // When raw text is provided it already includes the active keyboard modifiers. Don't reapply them
            // here else it can incorrectly modify the provided character.
            if (!isRawText && keyInput != KeyInput.DefaultValue)
            {
                keyInput = KeyInputUtil.ApplyKeyModifiers(keyInput, modifiers);
            }

            command = new EditCommand(keyInput, kind, commandGroup, commandId);
            return(true);
        }
Ejemplo n.º 15
0
 public void BackTab()
 {
     VerifyConvert(VSConstants.VSStd2KCmdID.BACKTAB, KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.TabKey, VimKeyModifiers.Shift), EditCommandKind.UserInput);
 }
Ejemplo n.º 16
0
        private void VerifyConvertWithShift(VSConstants.VSStd2KCmdID cmd, VimKey vimKey, EditCommandKind kind)
        {
            var keyInput = KeyInputUtil.ApplyKeyModifiers(KeyInputUtil.VimKeyToKeyInput(vimKey), VimKeyModifiers.Shift);

            VerifyConvert(cmd, keyInput, kind);
        }
Ejemplo n.º 17
0
            private static KeyInput ApplyModifiers(char c, VimKeyModifiers keyModifiers)
            {
                var keyInput = KeyInputUtil.CharToKeyInput(c);

                return(KeyInputUtil.ApplyKeyModifiers(keyInput, keyModifiers));
            }
Ejemplo n.º 18
0
            public void GetKeyInput_PoundWithShift()
            {
                var keyInput = KeyInputUtil.CharToKeyInput('#');

                Assert.Equal(keyInput, KeyInputUtil.ApplyKeyModifiers(keyInput, VimKeyModifiers.Shift));
            }
Ejemplo n.º 19
0
        bool IKeyUtil.TryConvertSpecialToKeyInput(NSEvent theEvent, out KeyInput keyInput)
        {
            var key = (NSKey)theEvent.KeyCode;
            NSEventModifierMask modifierKeys = theEvent.ModifierFlags;

            if (s_CocoaKeyToKeyInputMap.TryGetValue(key, out keyInput))
            {
                var keyModifiers = ConvertToKeyModifiers(modifierKeys);
                keyInput = KeyInputUtil.ApplyKeyModifiers(keyInput, keyModifiers);
                return(true);
            }

            // Vim allows certain "lazy" control keys, such as <C-6> for <C-^>.
            if ((modifierKeys == NSEventModifierMask.ControlKeyMask ||
                 modifierKeys == (NSEventModifierMask.ControlKeyMask | NSEventModifierMask.ShiftKeyMask)) &&
                s_CocoaControlKeyToKeyInputMap.TryGetValue(key, out keyInput))
            {
                return(true);
            }

            // If the key is not a pure alt or shift key combination and doesn't
            // correspond to an ASCII control key (like <C-^>), we need to convert it here.
            // This is needed because key combinations like <C-;> won't be passed to
            // TextInput, because they can't be represented as system or control text.
            // We just have to be careful not to shadow any keys that produce text when
            // combined with the AltGr key.
            if (modifierKeys != NSEventModifierMask.AlternateKeyMask &&
                modifierKeys != NSEventModifierMask.ShiftKeyMask)
            {
                switch (key)
                {
                case NSKey.Option:
                case NSKey.RightOption:
                case NSKey.Control:
                case NSKey.RightControl:
                case NSKey.Shift:
                case NSKey.RightShift:
                case NSKey.Command:
                    // Avoid work for common cases.
                    break;

                default:
                    VimTrace.TraceInfo("AlternateKeyUtil::TryConvertSpecialKeyToKeyInput {0} {1}",
                                       key, modifierKeys);
                    if (GetKeyInputFromKey(theEvent, modifierKeys, out keyInput))
                    {
                        // Only produce a key input here if the key input we
                        // found is *not* an ASCII control character.
                        // Control characters will be handled by TextInput
                        // as control text.


                        // Commented out because we are not using TextInput
                        //if (!System.Char.IsControl(keyInput.Char))
                        {
                            return(true);
                        }
                    }
                    break;
                }
            }

            keyInput = null;
            return(false);
        }
Ejemplo n.º 20
0
        bool IKeyUtil.TryConvertSpecialToKeyInput(Key key, ModifierKeys modifierKeys, out KeyInput keyInput)
        {
            if (s_wpfKeyToKeyInputMap.TryGetValue(key, out keyInput))
            {
                var keyModifiers = ConvertToKeyModifiers(modifierKeys);
                keyInput = KeyInputUtil.ApplyKeyModifiers(keyInput, keyModifiers);
                return(true);
            }

            // Vim allows certain "lazy" control keys, such as <C-6> for <C-^>.
            if ((modifierKeys == ModifierKeys.Control ||
                 modifierKeys == (ModifierKeys.Control | ModifierKeys.Shift)) &&
                s_wpfControlKeyToKeyInputMap.TryGetValue(key, out keyInput))
            {
                return(true);
            }

            // If the key is not a pure alt or shift key combination and doesn't
            // correspond to an ASCII control key (like <C-^>), we need to convert it here.
            // This is needed because key combinations like <C-;> won't be passed to
            // TextInput, because they can't be represented as system or control text.
            // We just have to be careful not to shadow any keys that produce text when
            // combined with the AltGr key.
            if (modifierKeys != ModifierKeys.None &&
                modifierKeys != ModifierKeys.Alt &&
                modifierKeys != ModifierKeys.Shift)
            {
                switch (key)
                {
                case Key.LeftAlt:
                case Key.RightAlt:
                case Key.LeftCtrl:
                case Key.RightCtrl:
                case Key.LeftShift:
                case Key.RightShift:
                case Key.System:

                    // Avoid work for common cases.
                    break;

                default:
                    VimTrace.TraceInfo("AlternateKeyUtil::TryConvertSpecialKeyToKeyInput {0} {1}",
                                       key, modifierKeys);
                    if (GetKeyInputFromKey(key, modifierKeys, out keyInput))
                    {
                        // Only produce a key input here if the key input we
                        // found is *not* an ASCII control character.
                        // Control characters will be handled by TextInput
                        // as control text.
                        if (!System.Char.IsControl(keyInput.Char))
                        {
                            return(true);
                        }
                    }
                    break;
                }
            }

            keyInput = null;
            return(false);
        }