public void Input5() { _mode.Process('c'); _mode.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Back)); _mode.Process(KeyInputUtil.VimKeyToKeyInput(VimKey.Back)); Assert.Equal(String.Empty, _modeRaw.Command); }
public void ChangeKeyModifiers_WontChangeChar() { var ki = KeyInputUtil.VimKeyToKeyInput(VimKey.OpenBracket); var ki2 = KeyInputUtil.ChangeKeyModifiers(ki, KeyModifiers.Shift); Assert.AreEqual(ki.Char, ki2.Char); }
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)); }
/// <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; } }
/// <summary> /// Run the specified VimKey against the buffer /// </summary> internal void Run(params VimKey[] keys) { foreach (var key in keys) { Run(KeyInputUtil.VimKeyToKeyInput(key)); } }
public void ShouldSkip_ArrowKeys() { var binding = CreateCommandKeyBinding(KeyInputUtil.VimKeyToKeyInput(VimKey.Left)); Create(); Assert.True(_serviceRaw.ShouldSkip(binding)); }
public void ShouldSkip_FunctionKeys() { var binding = CreateCommandKeyBinding(KeyInputUtil.VimKeyToKeyInput(VimKey.F2)); Create(); Assert.False(_serviceRaw.ShouldSkip(binding)); }
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))); }
public void Keypad1() { var left = KeyInputUtil.CharToKeyInput('+'); var right = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadPlus); Assert.NotEqual(left, right); }
public void Keypad2() { var left = KeyInputUtil.CharToKeyInput('-'); var right = KeyInputUtil.VimKeyToKeyInput(VimKey.KeypadMinus); Assert.AreNotEqual(left, right); }
/// <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); }
/// <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; } }
/// <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); }
public void EscapeLessThanLiteral() { var set = KeyInputSet.NewTwoKeyInputs( KeyInputUtil.CharToKeyInput('\\'), KeyInputUtil.VimKeyToKeyInput(VimKey.Home)); AssertMany(@"\<home>", set); }
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); }
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); }
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); }
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)); }
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()); } }
/// <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); }
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); }
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)); } }
/// <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); }
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); } }
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(); }
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); }
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); } }
internal bool TryProcess(VimKey vimKey) { var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey); if (_vimBuffer.CanProcess(keyInput)) { return(_vimBuffer.Process(keyInput).IsAnyHandled); } return(false); }
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(); }
static AlternateKeyUtil() { VimKeyToWpfKeyMap = BuildVimKeyToWpfKeyMap(); WpfKeyToKeyInputMap = new Dictionary <Key, KeyInput>(); foreach (var pair in VimKeyToWpfKeyMap) { var keyInput = KeyInputUtil.VimKeyToKeyInput(pair.Key); WpfKeyToKeyInputMap[pair.Value] = keyInput; } }