public void NumberedList() { Create("1. Heading"); _vimBuffer.Process("qaYp"); _vimBuffer.Process(KeyNotationUtil.StringToKeyInput("<C-a>")); _vimBuffer.Process("q3@a"); for (var i = 0; i < 5; i++) { var line = $"{i + 1}. Heading"; Assert.Equal(line, _textView.GetLine(i).GetText()); } }
public void RunMacro_NumberedList() { Create("1. Heading"); _vimBuffer.Process("qaYp"); _vimBuffer.Process(KeyNotationUtil.StringToKeyInput("<C-a>")); _vimBuffer.Process("q3@a"); for (var i = 0; i < 5; i++) { var line = String.Format("{0}. Heading", i + 1); Assert.AreEqual(line, _textView.GetLine(i).GetText()); } }
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)); } }
public void Letters() { var baseCase = (int)'a'; for (var i = 0; i < 26; i++) { var msg = string.Format("<Char-{0}>", baseCase + i); var keyInput = KeyNotationUtil.StringToKeyInput(msg); var target = (char)(baseCase + i); Assert.Equal(target, keyInput.Char); } }
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 NamedKeys() { Action <VimKey, string> func = (vimKey, name) => { var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey); Assert.Equal(name, KeyNotationUtil.GetDisplayName(keyInput)); }; func(VimKey.Enter, "<CR>"); func(VimKey.Escape, "<Esc>"); func(VimKey.Delete, "<Del>"); }
public void MacroSave() { _vim.RegisterMap.GetRegister('h').UpdateValue( KeyNotationUtil.StringToKeyInputSet("<Right><Left><Esc>").KeyInputs.ToArray()); _vim.RegisterMap.GetRegister('i').UpdateValue( KeyNotationUtil.StringToKeyInputSet("abc<CR>").KeyInputs.ToArray()); _vim.SaveSessionData(); _vim.RegisterMap.Clear(); _stream.Position = 0; _vim.LoadSessionData(); AssertMacroRegister('h', "<Right><Left><Esc>"); AssertMacroRegister('i', "abc<CR>"); }
public void AlternateShiftAndControlWithNonPrintable() { Action <string, VimKey> assert = (name, vimKey) => { var notation = string.Format("<CS-{0}>", name); var keyInput = KeyNotationUtil.StringToKeyInput(notation); Assert.Equal(vimKey, keyInput.Key); Assert.Equal(VimKeyModifiers.Shift | VimKeyModifiers.Control, keyInput.KeyModifiers); }; assert("Enter", VimKey.Enter); assert("F2", VimKey.F2); }
public void AlternateShiftAndControlWithNonPrintable() { void assert(string name, VimKey vimKey) { var notation = $"<CS-{name}>"; var keyInput = KeyNotationUtil.StringToKeyInput(notation); Assert.Equal(vimKey, keyInput.Key); Assert.Equal(VimKeyModifiers.Shift | VimKeyModifiers.Control, keyInput.KeyModifiers); } assert("Enter", VimKey.Enter); assert("F2", VimKey.F2); }
/// <summary> /// Process the full notation as a series of KeyInput values /// </summary> public static void ProcessNotation(this IVimBuffer vimBuffer, string notation, bool enter = false) { var keyInputSet = KeyNotationUtil.StringToKeyInputSet(notation); foreach (var keyInput in keyInputSet.KeyInputs) { vimBuffer.Process(keyInput); } if (enter) { vimBuffer.Process(KeyInputUtil.EnterKey); } }
protected static void AssertSingle(string input, KeyInput expected = null) { var opt = KeyNotationUtil.TryStringToKeyInput(input); if (expected != null) { Assert.True(opt.IsSome()); Assert.Equal(expected, opt.Value); Assert.Equal(expected, KeyNotationUtil.StringToKeyInput(input)); } else { Assert.True(opt.IsNone()); } }
public void Keypad() { Action <VimKey, string> func = (vimKey, name) => { var keyInput = KeyNotationUtil.StringToKeyInput(name); Assert.Equal(vimKey, keyInput.Key); }; func(VimKey.KeypadEnter, "<kEnter>"); func(VimKey.KeypadDecimal, "<kPoint>"); func(VimKey.KeypadDivide, "<kDivide>"); func(VimKey.KeypadMinus, "<kMinus>"); func(VimKey.KeypadMultiply, "<kMultiply>"); func(VimKey.KeypadPlus, "<kPlus>"); }
public void KeypadKeys() { Action <VimKey, string> func = (vimKey, name) => { var keyInput = KeyInputUtil.VimKeyToKeyInput(vimKey); Assert.Equal(name, KeyNotationUtil.GetDisplayName(keyInput)); }; func(VimKey.KeypadEnter, "<kEnter>"); func(VimKey.KeypadDecimal, "<kPoint>"); func(VimKey.KeypadPlus, "<kPlus>"); func(VimKey.KeypadMultiply, "<kMultiply>"); func(VimKey.KeypadMinus, "<kMinus>"); func(VimKey.KeypadDivide, "<kDivide>"); }
public void AlphaAndControl() { foreach (var c in KeyInputUtilTest.CharLettersUpper) { var keyInput = KeyInputUtil.CharWithControlToKeyInput(c); // Certain combinations like CTRL-J have a primary key which gets displayed over // them. Don't test them here if (keyInput.Key != VimKey.None) { continue; } Assert.Equal($"<C-{c}>", KeyNotationUtil.GetDisplayName(keyInput)); } }
/// <summary> /// This will process the provided string as key notation. This method is different than /// IVimBuffer::ProcessNotation because it will attempt to take into account the focus /// of the CommandMarginControl instance. It will route the provided key into a WPF key /// event when it has focus and give it directly to that control /// </summary> private void ProcessNotation(string notation) { var keyInputList = KeyNotationUtil.StringToKeyInputSet(notation).KeyInputs.ToList(); for (var i = 0; i < keyInputList.Count; i++) { var keyInput = keyInputList[i]; if (_marginControl.IsEditEnabled) { _keyboardDevice.SendKeyStroke(_marginControl.CommandLineTextBox, keyInput); } else { _vimBuffer.Process(keyInput); } } }
public void Mouse() { Action <VimKey, string> func = (vimKey, name) => { var keyInput = KeyNotationUtil.StringToKeyInput(name); Assert.Equal(vimKey, keyInput.Key); }; func(VimKey.LeftMouse, "<LeftMouse>"); func(VimKey.LeftDrag, "<LeftDrag>"); func(VimKey.LeftRelease, "<LeftRelease>"); func(VimKey.MiddleMouse, "<MiddleMouse>"); func(VimKey.MiddleDrag, "<MiddleDrag>"); func(VimKey.MiddleRelease, "<MiddleRelease>"); func(VimKey.RightMouse, "<RightMouse>"); func(VimKey.RightDrag, "<RightDrag>"); func(VimKey.RightRelease, "<RightRelease>"); }
private void AssertPrintMap(string input, string output) { var keyInputSet = KeyNotationUtil.StringToKeyInputSet(input); _keyMap .Setup(x => x.GetKeyMappingsForMode(KeyRemapMode.Normal)) .Returns(new[] { Tuple.Create(keyInputSet, keyInputSet) }) .Verifiable(); var expected = String.Format("n {0} {0}", output); _statusUtil .Setup(x => x.OnStatusLong(It.IsAny <IEnumerable <string> >())) .Callback <IEnumerable <string> >(x => Assert.AreEqual(expected, x.Single())) .Verifiable(); _operations.PrintKeyMap((new[] { KeyRemapMode.Normal }).ToFSharpList()); _factory.Verify(); }
public void AllAlternatesShouldEqualTheirTarget() { foreach (var current in AlternateArray) { var all = current.Split('&'); var left = KeyNotationUtil.StringToKeyInput(all[0]); var right = KeyNotationUtil.StringToKeyInput(all[1]); Assert.Equal(left, right); if (!String.IsNullOrEmpty(all[2])) { var number = Int32.Parse(all[2]); var c = (char)number; var third = KeyInputUtil.CharToKeyInput(c); Assert.Equal(left, third); Assert.Equal(right, third); } } }
public void ControlAlpha() { var baseCharacter = (int)'a'; var baseKey = (int)Key.A; foreach (var i in Enumerable.Range(0, 26)) { var letter = (char)(baseCharacter + i); var expected = KeyInputUtil.CharWithControlToKeyInput(letter); var key = (Key)(baseKey + i); var found = GetKeyInput(key, ModifierKeys.Control); Assert.Equal(expected, found); var notation = String.Format("<C-{0}>", letter); var mapped = KeyNotationUtil.StringToKeyInput(notation); Assert.Equal(expected, mapped); } }
internal BindResult <Motion> Process(string input, bool enter = false) { var keyInputSet = KeyNotationUtil.StringToKeyInputSet(input); var res = _capture.GetMotionAndCount(keyInputSet.FirstKeyInput.Value); foreach (var keyInput in keyInputSet.Rest.KeyInputs) { Assert.True(res.IsNeedMoreInput); var needMore = res.AsNeedMoreInput(); res = needMore.BindData.BindFunction.Invoke(keyInput); } if (enter) { var needMore = res.AsNeedMoreInput(); res = needMore.BindData.BindFunction.Invoke(KeyInputUtil.EnterKey); } return(res.Convert(x => x.Item1)); }
internal static CommandBinding CreateComplexNormalBinding( string name, Action <KeyInput> action, CommandFlags flags = CommandFlags.None) { Func <KeyInput, BindResult <NormalCommand> > func = keyInput => { action(keyInput); return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false))); }; var bindData = new BindData <NormalCommand>( FSharpOption <KeyRemapMode> .None, func.ToFSharpFunc()); var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData); return(CommandBinding.NewComplexNormalBinding( KeyNotationUtil.StringToKeyInputSet(name), flags, bindDataStorage)); }
public void Remove2() { Create(string.Empty); _runner.Remove(KeyNotationUtil.StringToKeyInputSet("foo")); Assert.Empty(_runner.Commands); }
public void TryStringToKeyInput_BadModifier() { Assert.True(KeyNotationUtil.TryStringToKeyInput("<b-j>").IsNone()); }
public void HexidecimalValue() { var keyInut = KeyNotationUtil.StringToKeyInput("<Char-0x61>"); Assert.Equal('a', keyInut.Char); }
public void OctalValue() { var keyInut = KeyNotationUtil.StringToKeyInput("<Char-0141>"); Assert.Equal('a', keyInut.Char); }
public void SimpleDifferentCase() { var keyInut = KeyNotationUtil.StringToKeyInput("<cHAR-97>"); Assert.Equal('a', keyInut.Char); }
public void Simple() { var keyInut = KeyNotationUtil.StringToKeyInput("<Char-97>"); Assert.Equal('a', keyInut.Char); }
public void SplitIntoKeyNotationEntries_InvalidModifierTreatesLessThanLiterally() { CollectionAssert.AreEquivalent( new[] { "<", "b", "-", "j", ">" }, KeyNotationUtil.SplitIntoKeyNotationEntries("<b-j>")); }
public void OneTimeCommand() { var res = _mode.Process(KeyNotationUtil.StringToKeyInput("<C-o>")); Assert.True(res.IsSwitchModeOneTimeCommand()); }
public void AlternateShiftandControlWithAlpha() { var keyInput = KeyNotationUtil.StringToKeyInput("<CS-A>"); Assert.Equal(KeyInputUtil.CharWithControlToKeyInput('a'), keyInput); }