Exemple #1
0
 public static void Process(this IVimBuffer buf, string input, bool enter = false)
 {
     foreach (var c in input)
     {
         var i = KeyInputUtil.CharToKeyInput(c);
         buf.Process(i);
     }
     if (enter)
     {
         buf.Process(KeyInputUtil.EnterKey);
     }
 }
Exemple #2
0
            public void StringToKeyInput8()
            {
                var ki = KeyInputUtil.CharToKeyInput(' ');

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

                foreach (var cur in all)
                {
                    Assert.Equal(ki, KeyNotationUtil.StringToKeyInput(cur));
                }
            }
Exemple #3
0
            public void DontHandleIfIncrementalSearchActive()
            {
                var all = new [] { KeyInputUtil.EnterKey, KeyInputUtil.CharToKeyInput('a') };

                foreach (var keyInput in all)
                {
                    _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false);
                    VerifyHandle(keyInput.Char.ToString());
                    _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(true);
                    VerifyNotHandle(keyInput.Char.ToString());
                }
            }
Exemple #4
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);
                }
            }
        /// <summary>
        /// Get the BindResult created from playing this text to the function
        /// </summary>
        public Tuple <FSharpOption <int>, KeyInput> GetComplete(string text)
        {
            var first  = KeyInputUtil.CharToKeyInput(text[0]);
            var result = CountCapture.GetCount(KeyRemapMode.None, first);

            if (text.Length > 1)
            {
                return(result.Run(text.Substring(1)).AsComplete().Item);
            }

            return(result.AsComplete().Item);
        }
Exemple #6
0
            public void GetKeyMappingResult4()
            {
                Assert.True(_map.AddKeyMapping("a", "bc", allowRemap: false, KeyRemapMode.Normal));
                var res = _map.Map(KeyInputUtil.CharToKeyInput('a'), KeyRemapMode.Normal);

                Assert.True(res.IsMapped);
                var list = res.AsMapped().KeyInputSet.KeyInputs.ToList();

                Assert.Equal(2, list.Count);
                Assert.Equal('b', list[0].Char);
                Assert.Equal('c', list[1].Char);
            }
Exemple #7
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);
        }
Exemple #8
0
        private static Dictionary <Key, KeyInput> BuildWpfControlKeyToKeyInputMap()
        {
            var map = new Dictionary <Key, KeyInput>
            {
                [Key.D2]          = KeyInputUtil.VimKeyToKeyInput(VimKey.Null), // <C-@>
                [Key.D6]          = KeyInputUtil.CharToKeyInput((char)0x1E),    // <C-^>
                [Key.OemMinus]    = KeyInputUtil.CharToKeyInput((char)0x1F),    // <C-_>
                [Key.OemQuestion] = KeyInputUtil.CharToKeyInput((char)0x7F),    // <C-?>
            };

            return(map);
        }
Exemple #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.ApplyModifiers(KeyInputUtil.CharToKeyInput(source[i]), KeyModifiers.Alt);
                    Assert.Equal(left, right);
                }
            }
Exemple #10
0
            public void GetKeyMappingResult4()
            {
                Assert.True(_map.MapWithNoRemap("a", "bc", KeyRemapMode.Normal));
                var res = _map.GetKeyMappingResult(KeyInputUtil.CharToKeyInput('a'), KeyRemapMode.Normal);

                Assert.True(res.IsMapped);
                var list = res.AsMapped().Item.KeyInputs.ToList();

                Assert.Equal(2, list.Count);
                Assert.Equal('b', list[0].Char);
                Assert.Equal('c', list[1].Char);
            }
            public void SimpleSystemText()
            {
                var keyInput = KeyInputUtil.CharToKeyInput('Á');

                _mockVimBuffer.Setup(x => x.CanProcess(keyInput)).Returns(false);

                var args = CreateTextComposition("Á");

                Assert.Equal("Á", args.SystemText);
                _processor.TextInput(args);
                Assert.False(args.Handled);
                _mockVimBuffer.Verify();
            }
Exemple #12
0
        internal static void Process(this IVimBuffer vimBuffer, string input, bool enter = false)
        {
            foreach (var c in input)
            {
                var keyInput = KeyInputUtil.CharToKeyInput(c);
                vimBuffer.Process(keyInput);
            }

            if (enter)
            {
                vimBuffer.Process(KeyInputUtil.EnterKey);
            }
        }
Exemple #13
0
 public void Equality()
 {
     EqualityUtil.RunAll(
         (left, right) => left == right,
         (left, right) => left != right,
         false,
         true,
         EqualityUnit.Create(CreateOne('a')).WithEqualValues(CreateOne('a')),
         EqualityUnit.Create(CreateOne('a')).WithNotEqualValues(CreateOne('b')),
         EqualityUnit.Create(CreateOne('a')).WithEqualValues(CreateMany('a')),
         EqualityUnit.Create(CreateOne('D')).WithEqualValues(KeyNotationUtil.StringToKeyInputSet("D")),
         EqualityUnit.Create(KeyInputSet.NewOneKeyInput(KeyInputUtil.CharToKeyInput('D'))).WithEqualValues(KeyNotationUtil.StringToKeyInputSet("D")));
 }
            public void Equals1()
            {
                var stroke1 = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('c'),
                    VimKeyModifiers.Shift | VimKeyModifiers.Control);
                var stroke2 = new KeyStroke(
                    KeyInputUtil.CharToKeyInput('c'),
                    VimKeyModifiers.Shift | VimKeyModifiers.Control);

                Assert.Equal(stroke1, stroke2);
                Assert.True(stroke1 == stroke2);
                Assert.False(stroke1 != stroke2);
            }
Exemple #15
0
            public void TabKey()
            {
                void verify(KeyInput keyInput)
                {
                    Assert.Equal(VimKey.Tab, keyInput.Key);
                    Assert.Equal(VimKeyModifiers.None, keyInput.KeyModifiers);
                    Assert.Equal('\t', keyInput.Char);
                }

                verify(KeyInputUtil.TabKey);
                verify(KeyInputUtil.CharToKeyInput('\t'));
                verify(KeyInputUtil.VimKeyToKeyInput(VimKey.Tab));
            }
Exemple #16
0
        public void Equals3()
        {
            var value = EqualityUnit
                        .Create(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.None))
                        .WithEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.None))
                        .WithNotEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('d'), KeyModifiers.None))
                        .WithNotEqualValues(new KeyStroke(KeyInputUtil.CharToKeyInput('c'), KeyModifiers.Shift));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: value);
        }
Exemple #17
0
        public void Equals2()
        {
            var stroke1 = new KeyStroke(
                KeyInputUtil.CharToKeyInput('d'),
                KeyModifiers.Shift | KeyModifiers.Control);
            var stroke2 = new KeyStroke(
                KeyInputUtil.CharToKeyInput('c'),
                KeyModifiers.Shift | KeyModifiers.Control);

            Assert.AreNotEqual(stroke1, stroke2);
            Assert.IsFalse(stroke1 == stroke2);
            Assert.IsTrue(stroke1 != stroke2);
        }
Exemple #18
0
            public void ErrorMessage4()
            {
                var mode = new Mock <IMode>();

                mode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
                var ki = KeyInputUtil.CharToKeyInput('c');

                _vimBuffer.RaiseKeyInputStart(ki);
                _vimBuffer.RaiseErrorMessage("foo");
                _vimBuffer.RaiseSwitchedMode(mode.Object);
                _vimBuffer.RaiseKeyInputEnd(ki);
                Assert.Equal("foo", _marginControl.CommandLineTextBox.Text);
            }
        private static KeyInput GetBaseKeyInput(KeyInput keyInput)
        {
            var keyChar = keyInput.Char;

            if (keyChar != KeyInput.DefaultValue.Char)
            {
                return(KeyInputUtil.CharToKeyInput(Char.ToUpper(keyChar)));
            }
            else
            {
                return(KeyInputUtil.VimKeyToKeyInput(keyInput.Key));
            }
        }
Exemple #20
0
        public void PreventInput1()
        {
            Create(lines: "foo");
            var input = KeyInputUtil.CharToKeyInput('@');

            _operations.Setup(x => x.Beep()).Verifiable();
            Assert.False(_mode.CommandNames.Any(x => x.KeyInputs.First().Char == input.Char));
            Assert.True(_mode.CanProcess(input));
            var ret = _mode.Process(input);

            Assert.True(ret.IsHandledNoSwitch());
            _operations.Verify();
        }
Exemple #21
0
        public void StatusMessageLong4()
        {
            var mode = new Mock <IMode>();

            mode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
            var ki = KeyInputUtil.CharToKeyInput('c');

            _buffer.RaiseKeyInputStart(ki);
            _buffer.RaiseStatusMessageLong("foo", "bar");
            _buffer.RaiseSwitchedMode(mode.Object);
            _buffer.RaiseKeyInputEnd(ki);
            Assert.AreEqual("foo" + Environment.NewLine + "bar", _marginControl.StatusLine);
        }
Exemple #22
0
        public void CharToKeyInput_UpperLetters()
        {
            foreach (var cur in CharsLettersUpper)
            {
                var ki = KeyInputUtil.CharToKeyInput(cur);
                Assert.AreEqual(cur, ki.Char);
                Assert.AreEqual(KeyModifiers.None, ki.KeyModifiers);

                var offset = ((int)cur) - ((int)'A');
                var key    = (VimKey)((int)VimKey.UpperA + offset);
                Assert.AreEqual(key, ki.Key);
            }
        }
Exemple #23
0
        public void Equality5()
        {
            var values = EqualityUnit
                         .Create(KeyInputUtil.CharToKeyInput('c'))
                         .WithEqualValues(KeyInputUtil.CharToKeyInput('c'))
                         .WithNotEqualValues(KeyInputUtil.CharToKeyInput('d'))
                         .WithNotEqualValues(KeyInputUtil.CharWithControlToKeyInput('c'));

            EqualityUtil.RunAll(
                (x, y) => x == y,
                (x, y) => x != y,
                values: values);
        }
Exemple #24
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);
        }
Exemple #25
0
            public void SwitchMode4()
            {
                var mode = new Mock <IMode>();

                mode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
                var ki = KeyInputUtil.CharToKeyInput('c');

                _marginControl.CommandLineTextBox.Text = string.Empty;
                _vimBuffer.RaiseKeyInputStart(ki);
                _vimBuffer.RaiseSwitchedMode(new SwitchModeEventArgs(_vimBuffer.NormalMode, mode.Object));
                Assert.Equal(string.Empty, _marginControl.CommandLineTextBox.Text);
                _vimBuffer.RaiseKeyInputEnd(ki);
                Assert.Equal(Resources.InsertBanner, _marginControl.CommandLineTextBox.Text);
            }
Exemple #26
0
        public void SwitchMode4()
        {
            var mode = new Mock <IMode>();

            mode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
            var ki = KeyInputUtil.CharToKeyInput('c');

            _marginControl.StatusLine = String.Empty;
            _buffer.RaiseKeyInputStart(ki);
            _buffer.RaiseSwitchedMode(new SwitchModeEventArgs(FSharpOption <IMode> .None, mode.Object));
            Assert.AreEqual(String.Empty, _marginControl.StatusLine);
            _buffer.RaiseKeyInputEnd(ki);
            Assert.AreEqual(Resources.InsertBanner, _marginControl.StatusLine);
        }
Exemple #27
0
        public void SimulateProcessed_RaiseEvent()
        {
            var ranStart     = false;
            var ranProcessed = false;
            var ranEnd       = false;

            _vimBuffer.KeyInputStart     += delegate { ranStart = true; };
            _vimBuffer.KeyInputProcessed += delegate { ranProcessed = true; };
            _vimBuffer.KeyInputEnd       += delegate { ranEnd = true; };
            _vimBuffer.SimulateProcessed(KeyInputUtil.CharToKeyInput('c'));
            Assert.IsTrue(ranStart);
            Assert.IsTrue(ranEnd);
            Assert.IsTrue(ranProcessed);
        }
Exemple #28
0
            public void TabKey()
            {
                Action <KeyInput> verify =
                    keyInput =>
                {
                    Assert.Equal(VimKey.Tab, keyInput.Key);
                    Assert.Equal(VimKeyModifiers.None, keyInput.KeyModifiers);
                    Assert.Equal('\t', keyInput.Char);
                };

                verify(KeyInputUtil.TabKey);
                verify(KeyInputUtil.CharToKeyInput('\t'));
                verify(KeyInputUtil.VimKeyToKeyInput(VimKey.Tab));
            }
Exemple #29
0
            public void CharToKeyInput_AllCoreCharsMapToThemselves()
            {
                foreach (var cur in KeyInputUtil.VimKeyCharList)
                {
                    var ki = KeyInputUtil.CharToKeyInput(cur);
                    Assert.True(ki.RawChar.IsSome());
                    Assert.Equal(cur, ki.Char);

                    if (CharAll.Contains(cur))
                    {
                        Assert.Equal(VimKeyModifiers.None, ki.KeyModifiers);
                    }
                }
            }
Exemple #30
0
            public void ControlAlphaSpecial()
            {
                var list = new[] { 'j', 'l', 'm', 'i' };

                foreach (var current in list)
                {
                    var c        = (char)(0x1 + (current - 'a'));
                    var keyInput = KeyInputUtil.CharToKeyInput(c);
                    Assert.NotEqual(VimKey.RawCharacter, keyInput.Key);

                    keyInput = KeyInputUtil.CharWithControlToKeyInput(current);
                    Assert.NotEqual(VimKey.RawCharacter, keyInput.Key);
                }
            }