Ejemplo n.º 1
0
        private void Create(KeyRemapMode countKeyRemapMode, params string[] lines)
        {
            _textView = CreateTextView(lines);
            _vimTextBuffer = Vim.CreateVimTextBuffer(_textView.TextBuffer);
            _registerMap = Vim.RegisterMap;
            var vimBufferData = CreateVimBufferData(
                _vimTextBuffer,
                _textView);
            _commandUtil = CreateCommandUtil(vimBufferData);
            var incrementalSearch = new IncrementalSearch(
                vimBufferData,
                CommonOperationsFactory.GetCommonOperations(vimBufferData));
            var motionCapture = new MotionCapture(vimBufferData, incrementalSearch);

            _runnerRaw = new CommandRunner(
                _textView,
                _registerMap,
                motionCapture,
                vimBufferData.LocalSettings,
                _commandUtil,
                new StatusUtil(),
                VisualKind.Character,
                countKeyRemapMode);
            _runner = _runnerRaw;
        }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
0
        private KeyInput MapSingle(string lhs, KeyRemapMode mode = null)
        {
            mode = mode ?? KeyRemapMode.Normal;
            var result = _map.Map(KeyNotationUtil.StringToKeyInputSet(lhs), mode);

            return(result.AsMapped().KeyInputSet.KeyInputs.Single());
        }
Ejemplo n.º 4
0
        private void Create(KeyRemapMode countKeyRemapMode, params string[] lines)
        {
            _textView      = CreateTextView(lines);
            _vimTextBuffer = Vim.CreateVimTextBuffer(_textView.TextBuffer);
            _registerMap   = Vim.RegisterMap;
            var vimBufferData = CreateVimBufferData(
                _vimTextBuffer,
                _textView);

            _commandUtil = CreateCommandUtil(vimBufferData);
            var incrementalSearch = new IncrementalSearch(
                vimBufferData,
                CommonOperationsFactory.GetCommonOperations(vimBufferData));
            var motionCapture = new MotionCapture(vimBufferData, incrementalSearch);

            _runnerRaw = new CommandRunner(
                _textView,
                _registerMap,
                motionCapture,
                vimBufferData.LocalSettings,
                _commandUtil,
                new StatusUtil(),
                VisualKind.Character,
                countKeyRemapMode);
            _runner = _runnerRaw;
        }
Ejemplo n.º 5
0
        internal static CommandBinding CreateComplexNormalBinding(
            string name,
            Func <KeyInput, bool> predicate,
            KeyRemapMode remapMode = null,
            CommandFlags flags     = CommandFlags.None)
        {
            var remapModeOption = FSharpOption.CreateForReference(remapMode);
            Func <KeyInput, BindResult <NormalCommand> > func = null;

            func = keyInput =>
            {
                if (predicate(keyInput))
                {
                    var data = new BindData <NormalCommand>(
                        remapModeOption,
                        func.ToFSharpFunc());
                    return(BindResult <NormalCommand> .NewNeedMoreInput(data));
                }

                return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false)));
            };

            var bindData = new BindData <NormalCommand>(
                remapModeOption,
                func.ToFSharpFunc());
            var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData);

            return(CommandBinding.NewComplexNormalBinding(
                       KeyNotationUtil.StringToKeyInputSet(name),
                       flags,
                       bindDataStorage));
        }
Ejemplo n.º 6
0
            public void DefaultWithBang()
            {
                var modes = new KeyRemapMode[] { KeyRemapMode.Insert, KeyRemapMode.Command };

                AssertMap("noremap! l h", "l", "h", modes);
                AssertMap("nore! l h", "l", "h", modes);
                AssertMap("no! l h", "l", "h", modes);
            }
Ejemplo n.º 7
0
            public void Default()
            {
                var modes = new KeyRemapMode[] { KeyRemapMode.Normal, KeyRemapMode.Visual, KeyRemapMode.Select, KeyRemapMode.OperatorPending };

                AssertMap("noremap l h", "l", "h", modes);
                AssertMap("nore l h", "l", "h", modes);
                AssertMap("no l h", "l", "h", modes);
            }
Ejemplo n.º 8
0
        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());
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
0
        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());
        }
Ejemplo n.º 13
0
        /// <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);
            }
        }
Ejemplo n.º 14
0
 protected void AssertNoMapping(string lhs, KeyRemapMode mode = null)
 {
     AssertNoMapping(KeyNotationUtil.StringToKeyInputSet(lhs), mode);
 }
Ejemplo n.º 15
0
 public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, string str, KeyRemapMode mode)
 {
     return(keyMap.GetKeyMapping(KeyNotationUtil.StringToKeyInputSet(str), mode));
 }
Ejemplo n.º 16
0
 public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, char c, KeyRemapMode mode)
 {
     return(GetKeyMappingResult(keyMap, KeyInputUtil.CharToKeyInput(c), mode));
 }
Ejemplo n.º 17
0
 public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, KeyInputSet set, KeyRemapMode mode)
 {
     return(keyMap.GetKeyMapping(set, mode));
 }
Ejemplo n.º 18
0
 public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, KeyInput ki, KeyRemapMode mode)
 {
     return(GetKeyMappingResult(keyMap, KeyInputSet.NewOneKeyInput(ki), mode));
 }
Ejemplo n.º 19
0
 public static IEnumerable <KeyInput> GetKeyMapping(this IKeyMap keyMap, KeyInputSet kiSet, KeyRemapMode mode)
 {
     return(keyMap.GetKeyMapping(kiSet, mode).AsMapped().Item.KeyInputs);
 }
Ejemplo n.º 20
0
 public static IEnumerable <KeyInput> GetKeyMapping(this IKeyMap keyMap, KeyInput ki, KeyRemapMode mode)
 {
     return(GetKeyMapping(keyMap, KeyInputSet.NewOneKeyInput(ki), mode));
 }
Ejemplo n.º 21
0
 protected void AssertPartialMapping(string lhs, string expectedMapped, string expectedRemaining, KeyRemapMode mode = null)
 {
     AssertPartialMapping(KeyInputSetUtil.OfString(lhs), expectedMapped, expectedRemaining, mode);
 }
Ejemplo n.º 22
0
 public static IEnumerable<KeyInput> GetKeyMapping(this IKeyMap keyMap, KeyInput ki, KeyRemapMode mode)
 {
     var set = KeyInputSet.NewOneKeyInput(ki);
     return keyMap.GetKeyMapping(set, mode).AsMapped().Item.KeyInputs;
 }
Ejemplo n.º 23
0
 public void Remap_noremap()
 {
     Create("");
     var modes = new KeyRemapMode[] { KeyRemapMode.Normal, KeyRemapMode.Visual, KeyRemapMode.Select, KeyRemapMode.OperatorPending };
     TestNoRemap("noremap l h", "l", "h", modes);
     TestNoRemap("nore l h", "l", "h", modes);
     TestNoRemap("no l h", "l", "h", modes);
 }
Ejemplo n.º 24
0
 protected void AssertPartialMapping(string lhs, string expectedMapped, string expectedRemaining, KeyRemapMode mode = null)
 {
     AssertPartialMapping(KeyInputSetUtil.OfString(lhs), expectedMapped, expectedRemaining, mode);
 }
Ejemplo n.º 25
0
 protected void AssertMapping(string lhs, string expected, KeyRemapMode mode = null)
 {
     AssertMapping(KeyNotationUtil.StringToKeyInputSet(lhs), expected, mode);
 }
Ejemplo n.º 26
0
        /// <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)
        {
            var result = _buffer.GetKeyInputMapping(original);
            if (result.IsNeedsMoreInput || result.IsRecursive)
            {
                // No single mapping
                mapped = null;
                return false;
            }

            if (result.IsMapped)
            {
                var set = ((KeyMappingResult.Mapped)result).Item;
                if (!set.IsOneKeyInput)
                {
                    mapped = null;
                    return false;
                }

                mapped = set.FirstKeyInput.Value;
                return true;
            }

            if (result.IsNoMapping)
            {
                // No mapping.  Use the original
                mapped = original;
                return true;
            }

            // Shouldn't get here because all cases of KeyMappingResult should be
            // handled abvoe
            Contract.Assert(false);
            mapped = null;
            return false;
        }
Ejemplo n.º 27
0
 internal static BindData <T> CreateBindData <T>(Func <KeyInput, BindResult <T> > func = null, KeyRemapMode remapMode = null)
 {
     func = func ?? (x => BindResult <T> .Cancelled);
     return(new BindData <T>(FSharpOption.CreateForReference(remapMode), func.ToFSharpFunc()));
 }
Ejemplo n.º 28
0
 public void Default()
 {
     var modes = new KeyRemapMode[] { KeyRemapMode.Normal, KeyRemapMode.Visual, KeyRemapMode.Select, KeyRemapMode.OperatorPending };
     AssertMap("noremap l h", "l", "h", modes);
     AssertMap("nore l h", "l", "h", modes);
     AssertMap("no l h", "l", "h", modes);
 }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
 public void DefaultWithBang()
 {
     var modes = new KeyRemapMode[] { KeyRemapMode.Insert, KeyRemapMode.Command };
     AssertMap("noremap! l h", "l", "h", modes);
     AssertMap("nore! l h", "l", "h", modes);
     AssertMap("no! l h", "l", "h", modes);
 }
Ejemplo n.º 31
0
 public void Remap_noremap2()
 {
     Create("");
     var modes = new KeyRemapMode[] { KeyRemapMode.Insert, KeyRemapMode.Command };
     TestNoRemap("noremap! l h", "l", "h", modes);
     TestNoRemap("nore! l h", "l", "h", modes);
     TestNoRemap("no! l h", "l", "h", modes);
 }
Ejemplo n.º 32
0
 public static IEnumerable <KeyInput> GetKeyMapping(this IKeyMap keyMap, char c, KeyRemapMode mode)
 {
     return(GetKeyMapping(keyMap, KeyInputUtil.CharToKeyInput(c), mode));
 }
Ejemplo n.º 33
0
 public static KeyMappingResult GetKeyMappingResult(this IKeyMap keyMap, KeyInput ki, KeyRemapMode mode)
 {
     var set = KeyInputSet.NewOneKeyInput(ki);
     return keyMap.GetKeyMapping(set, mode);
 }
Ejemplo n.º 34
0
 public static IEnumerable <KeyInput> GetKeyMapping(this IKeyMap keyMap, string str, KeyRemapMode mode)
 {
     return(GetKeyMapping(keyMap, KeyNotationUtil.StringToKeyInputSet(str), mode));
 }
Ejemplo n.º 35
0
        /// <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;
            }
        }
Ejemplo n.º 36
0
        internal static BindData <T> CreateBindData <T>(Func <KeyInput, BindResult <T> > func = null, KeyRemapMode remapMode = null)
        {
            func      = func ?? (x => BindResult <T> .Cancelled);
            remapMode = remapMode ?? KeyRemapMode.None;

            return(new BindData <T>(remapMode, func.ToFSharpFunc()));
        }