protected void AssertMapping(KeyInputSet lhs, string expected, KeyRemapMode mode = null) { mode = mode ?? KeyRemapMode.Normal; var ret = _map.GetKeyMappingResult(lhs, mode); Assert.True(ret.IsMapped); Assert.Equal(KeyInputSetUtil.OfString(expected), ret.GetMappedKeyInputs()); }
public void Control_OpenBracket1() { var ki = KeyInputUtil.CharWithControlToKeyInput('['); var name = KeyInputSet.NewOneKeyInput(ki); Assert.True(_mode.CommandNames.Contains(name)); }
public void Control_OpenBracket1() { var ki = KeyInputUtil.CharWithControlToKeyInput('['); var name = new KeyInputSet(ki); Assert.Contains(name, _mode.CommandNames); }
public void Add1() { var name1 = KeyInputSet.NewOneKeyInput(KeyInputUtil.CharToKeyInput('c')); var name2 = name1.Add(KeyInputUtil.CharToKeyInput('a')); Assert.AreEqual("ca", name2.Name); }
public void Add1() { var name1 = new KeyInputSet(KeyInputUtil.CharToKeyInput('c')); var name2 = name1.Add(KeyInputUtil.CharToKeyInput('a')); Assert.Equal("ca", name2.Name); }
protected static void AssertMany(string input, KeyInputSet keyInputSet) { var opt = KeyNotationUtil.TryStringToKeyInputSet(input); Assert.True(opt.IsSome()); Assert.Equal(opt.Value, keyInputSet); }
internal void RunConflictingKeyBindingStateCheck(IVimBuffer buffer, Action <ConflictingKeyBindingState, CommandKeyBindingSnapshot> onComplete) { var needed = buffer.AllModes.Select(x => x.CommandNames).SelectMany(x => x).ToList(); needed.Add(KeyInputSet.NewOneKeyInput(buffer.LocalSettings.GlobalSettings.DisableAllCommand)); RunConflictingKeyBindingStateCheck(needed.Select(x => x.KeyInputs.First()), onComplete); }
public void RaiseKeyInputBuffered(KeyInputSet keyInputSet) { if (KeyInputBuffered != null) { KeyInputBuffered(this, new KeyInputSetEventArgs(keyInputSet)); } }
public void Compare_AlternateKeyInputShouldBeEqual() { var left = KeyInputSet.NewOneKeyInput(KeyInputUtil.EnterKey); var right = KeyInputSet.NewOneKeyInput(KeyInputUtil.AlternateEnterKey); Assert.True(0 == left.CompareTo(right)); Assert.True(0 == right.CompareTo(left)); }
protected void AssertMapping(KeyInputSet lhs, string expected, KeyRemapMode mode = null) { mode = mode ?? KeyRemapMode.Normal; var ret = _map.GetKeyMappingResult(lhs, mode); Assert.True(ret.IsMapped); Assert.Equal(KeyInputSetUtil.OfString(expected), ret.GetMappedKeyInputs()); }
internal static CommandBinding CreateLegacyBinding(string name, Func <FSharpOption <int>, Register, CommandResult> func) { var fsharpFunc = func.ToFSharpFunc(); var list = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList(); var commandName = KeyInputSet.NewManyKeyInputs(list); return(CommandBinding.NewLegacyBinding(commandName, CommandFlags.None, fsharpFunc)); }
public void EscapeLessThanLiteral() { var set = KeyInputSet.NewTwoKeyInputs( KeyInputUtil.CharToKeyInput('\\'), KeyInputUtil.VimKeyToKeyInput(VimKey.Home)); AssertMany(@"\<home>", set); }
public void HandleCommandKey() { Map("<D-k>", "gk"); var ki = new KeyInput(VimKey.RawCharacter, KeyModifiers.Command, FSharpOption.Create('k')); var kiSet = KeyInputSet.NewOneKeyInput(ki); AssertPartialMapping(kiSet, "g", "k"); }
public void Compare_AlternateKeyInputShouldBeEqual() { var left = new KeyInputSet(KeyInputUtil.EnterKey); var right = new KeyInputSet(KeyInputUtil.CharWithControlToKeyInput('m')); Assert.True(0 == left.CompareTo(right)); Assert.True(0 == right.CompareTo(left)); }
public void GetKeyMappingResultFromMultiple1() { _map.MapWithNoRemap("aa", "b", KeyRemapMode.Normal); var input = "aa".Select(KeyInputUtil.CharToKeyInput).ToFSharpList(); var res = _map.GetKeyMapping(KeyInputSet.NewManyKeyInputs(input), KeyRemapMode.Normal); Assert.Equal('b', res.AsMapped().Item.KeyInputs.Single().Char); }
public void GetKeyMappingResultFromMultiple2() { _map.MapWithNoRemap("aa", "b", KeyRemapMode.Normal); var input = "a".Select(KeyInputUtil.CharToKeyInput).ToFSharpList(); var res = _map.GetKeyMapping(KeyInputSet.NewManyKeyInputs(input), KeyRemapMode.Normal); Assert.True(res.IsNeedsMoreInput); }
internal static CommandBinding CreateNormalBinding(string name, Func <CommandData, CommandResult> func) { var fsharpFunc = func.ToFSharpFunc(); var list = name.Select(KeyInputUtil.CharToKeyInput).ToFSharpList(); var commandName = KeyInputSet.NewManyKeyInputs(list); var command = NormalCommand.NewPing(new PingData(fsharpFunc)); return(CommandBinding.NewNormalBinding(commandName, CommandFlags.None, command)); }
protected void AssertPartialMapping(KeyInputSet lhs, string expectedMapped, string expectedRemaining, KeyRemapMode mode = null) { mode = mode ?? KeyRemapMode.Normal; var ret = _map.GetKeyMappingResult(lhs, mode); Assert.True(ret.IsPartiallyMapped); var partiallyMapped = ret.AsPartiallyMapped(); Assert.Equal(KeyInputSetUtil.OfString(expectedMapped), partiallyMapped.Item1); Assert.Equal(KeyInputSetUtil.OfString(expectedRemaining), partiallyMapped.Item2); }
protected void AssertPartialMapping(KeyInputSet lhs, string expectedMapped, string expectedRemaining, KeyRemapMode mode = null) { mode = mode ?? KeyRemapMode.Normal; var ret = _map.GetKeyMappingResult(lhs, mode); Assert.True(ret.IsPartiallyMapped); var partiallyMapped = ret.AsPartiallyMapped(); Assert.Equal(KeyInputSetUtil.OfString(expectedMapped), partiallyMapped.Item1); Assert.Equal(KeyInputSetUtil.OfString(expectedRemaining), partiallyMapped.Item2); }
public void MapWithRemap_HandleCommandKey() { Assert.IsTrue(_map.MapWithRemap("<D-k>", "gk", KeyRemapMode.Normal)); var ki = new KeyInput(VimKey.LowerK, KeyModifiers.Command, FSharpOption.Create('k')); var kiSet = KeyInputSet.NewOneKeyInput(ki); var ret = _map.GetKeyMapping(kiSet, KeyRemapMode.Normal); Assert.IsTrue(ret.IsMapped); var all = ret.AsMapped().Item.KeyInputs.Select(x => x.Char).ToList(); Assert.AreEqual('g', all[0]); Assert.AreEqual('k', all[1]); }
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 Compare_AlternateKeyInputShouldBeEqualInMap() { var left = KeyInputSet.NewOneKeyInput(KeyInputUtil.EnterKey); var right = KeyInputSet.NewOneKeyInput(KeyInputUtil.AlternateEnterKey); var map = MapModule.Empty <KeyInputSet, bool>().Add(left, true); var result = MapModule.TryFind(right, map); Assert.True(result.IsSome()); map = MapModule.Empty <KeyInputSet, bool>().Add(right, true); result = MapModule.TryFind(left, map); Assert.True(result.IsSome()); }
internal void RunConflictingKeyBindingStateCheck(IVimBuffer buffer) { // Create the set of KeyInput values which are handled by VsVim var needed = buffer.AllModes.Select(x => x.CommandNames).SelectMany(x => x).ToList(); needed.Add(KeyInputSet.NewOneKeyInput(buffer.LocalSettings.GlobalSettings.DisableAllCommand)); var set = new HashSet <KeyInput>(needed.Select(x => x.KeyInputs.First())); // Take a snapshot based on the current state of the DTE commands and store it // and the conflicting state _snapshot = CreateCommandKeyBindingSnapshot(set); ConflictingKeyBindingState = _snapshot.Conflicting.Any() ? ConflictingKeyBindingState.FoundConflicts : ConflictingKeyBindingState.ConflictsIgnoredOrResolved; }
protected void AssertNoMapping(KeyInputSet lhs, KeyRemapMode mode = null) { Assert.False(_map.GetKeyMappingsForMode(mode).Any(keyMapping => keyMapping.Left == lhs)); mode = mode ?? KeyRemapMode.Normal; var result = _map.GetKeyMappingResult(lhs, mode); if (lhs.Length == 1) { Assert.True(result.IsMapped); } else { Assert.True(result.IsPartiallyMapped); Assert.Equal(lhs.FirstKeyInput.Value, result.AsPartiallyMapped().Item1.FirstKeyInput.Value); Assert.Equal(1, result.AsPartiallyMapped().Item1.Length); } Assert.Equal(lhs, result.GetMappedKeyInputs()); }
protected void AssertNoMapping(KeyInputSet lhs, KeyRemapMode mode = null) { Assert.False(_map.GetKeyMappingsForMode(mode).Any(keyMapping => keyMapping.Left == lhs)); mode = mode ?? KeyRemapMode.Normal; var result = _map.GetKeyMappingResult(lhs, mode); if (lhs.Length == 1) { Assert.True(result.IsMapped); } else { Assert.True(result.IsPartiallyMapped); Assert.Equal(lhs.FirstKeyInput.Value, result.AsPartiallyMapped().Item1.FirstKeyInput.Value); Assert.Equal(1, result.AsPartiallyMapped().Item1.Length); } Assert.Equal(lhs, result.GetMappedKeyInputs()); }
protected void AssertNoMapping(KeyInputSet lhs, KeyRemapMode mode = null) { mode = mode ?? KeyRemapMode.Normal; Assert.DoesNotContain(_map.GetKeyMappings(mode), keyMapping => keyMapping.Left == lhs); var result = _map.Map(lhs, mode); if (lhs.Length == 1) { Assert.True(result.IsMapped || result.IsUnmapped); } else { Assert.True(result.IsPartiallyMapped); Assert.Equal(lhs.FirstKeyInput.Value, result.AsPartiallyMapped().MappedKeyInputSet.FirstKeyInput.Value); Assert.Equal(1, result.AsPartiallyMapped().MappedKeyInputSet.Length); } Assert.Equal(lhs, result.GetMappedKeyInputs()); }
public void Commands1() { Create("foo"); var list = new KeyInput[] { KeyInputUtil.CharToKeyInput('h'), KeyInputUtil.CharToKeyInput('j'), KeyInputUtil.CharToKeyInput('k'), KeyInputUtil.CharToKeyInput('l'), KeyInputUtil.VimKeyToKeyInput(VimKey.Left), KeyInputUtil.VimKeyToKeyInput(VimKey.Right), KeyInputUtil.VimKeyToKeyInput(VimKey.Up), KeyInputUtil.VimKeyToKeyInput(VimKey.Down), KeyInputUtil.VimKeyToKeyInput(VimKey.Back) }; var commands = _mode.CommandNames.ToList(); foreach (var item in list) { var name = KeyInputSet.NewOneKeyInput(item); Assert.Contains(name, commands); } }
/// <summary> /// Try and map a KeyInput to a single KeyInput value. This will only succeed for KeyInput /// values which have no mapping or map to a single KeyInput value /// </summary> private bool TryGetSingleMapping(KeyRemapMode mode, KeyInput original, out KeyInput mapped) { // If we're currently in the middle of a key mapping sequence we won't provide a KeyInput if (!_buffer.BufferedRemapKeyInputs.IsEmpty) { mapped = null; return(false); } var result = _buffer.Vim.KeyMap.GetKeyMapping( KeyInputSet.NewOneKeyInput(original), mode); mapped = null; if (result.IsMappingNeedsMoreInput || result.IsRecursiveMapping) { // No single mapping return(false); } else if (result.IsMapped) { var set = ((KeyMappingResult.Mapped)result).Item; if (!set.IsOneKeyInput) { return(false); } mapped = set.FirstKeyInput.Value; return(true); } else { // No mapping. Use the original mapped = original; return(true); } }
protected static void AssertMany(string input, KeyInputSet keyInputSet) { var opt = KeyNotationUtil.TryStringToKeyInputSet(input); Assert.True(opt.IsSome()); Assert.Equal(opt.Value, keyInputSet); }
public void CommandMapSupportsAlternateKeys() { Assert.True(MapModule.TryFind(KeyInputSet.NewOneKeyInput(KeyInputUtil.EnterKey), _captureRaw.MotionBindingsMap).IsSome()); }
public void RaiseKeyInputBuffered(KeyInputSet keyInputSet) { if (KeyInputBuffered != null) { KeyInputBuffered(this, new KeyInputSetEventArgs(keyInputSet)); } }
public static IEnumerable <KeyInput> GetKeyMapping(this IKeyMap keyMap, KeyInputSet kiSet, KeyRemapMode mode) { return(keyMap.GetKeyMapping(kiSet, mode).AsMapped().Item.KeyInputs); }
public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, KeyInput ki, KeyRemapMode mode) { return(GetKeyMappingResult(keyMap, KeyInputSet.NewOneKeyInput(ki), mode)); }
public void Remove(KeyInputSet value) { throw new NotImplementedException(); }
public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, KeyInputSet set, KeyRemapMode mode) { return(keyMap.GetKeyMapping(set, mode)); }
public void RaiseKeyInputBuffered(KeyInputSet keyInputSet) { KeyInputBuffered?.Invoke(this, new KeyInputSetEventArgs(keyInputSet)); }
private CommandRunData CreateCommand( Func<FSharpOption<int>, Register, CommandResult> func = null, KeyInputSet name = null, CommandFlags? flags = null, int? count = 0, MotionRunData motionRunData = null, VisualSpan visualRunData = null) { name = name ?? KeyInputSet.NewOneKeyInput(KeyInputUtil.CharToKeyInput('c')); var flagsRaw = flags ?? CommandFlags.None; var countRaw = count.HasValue ? FSharpOption.Create(count.Value) : FSharpOption<int>.None; var funcRaw = func.ToFSharpFunc(); var cmd = Command.NewSimpleCommand( name, flagsRaw, func.ToFSharpFunc()); return new CommandRunData( cmd, new Register('c'), countRaw, motionRunData != null ? FSharpOption.Create(motionRunData) : FSharpOption<MotionRunData>.None, visualRunData != null ? FSharpOption.Create(visualRunData) : FSharpOption<VisualSpan>.None); }