Exemplo n.º 1
0
        /// <summary>
        /// This method is called to process KeyInput in any fashion by the IVimBuffer.  There are
        /// several cases where we want to defer to Visual Studio and IOleCommandTarget for processing
        /// of a command.  In particular we don't want to process any text input here
        /// </summary>
        protected override bool TryProcess(KeyInput keyInput)
        {
            if (IsDiscardedKeyInput(keyInput))
            {
                return(true);
            }

            // Don't handle input when incremental search is active.  Let Visual Studio handle it
            if (_adapter.IsIncrementalSearchActive(TextView))
            {
                return(false);
            }

            // In insert mode we don't want text input going directly to VsVim.  Text input must
            // be routed through Visual Studio and IOleCommandTarget in order to get intellisense
            // properly hooked up.  Not handling it in this KeyProcessor will eventually cause
            // it to be routed through IOleCommandTarget if it's input
            //
            // The Visual Studio KeyProcessor won't pass along control characters that are less than
            // or equal to 0x1f so we have to handle them here
            if (VimBuffer.ModeKind.IsAnyInsert() &&
                !VimBuffer.CanProcessAsCommand(keyInput) &&
                (int)keyInput.Char > 0x1f)
            {
                return(false);
            }

            return(base.TryProcess(keyInput));
        }
Exemplo n.º 2
0
 public VimBufferTest()
 {
     _textView = CreateTextView("here we go");
     _textView.MoveCaretTo(0);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap = _vimBuffer.Vim.KeyMap;
     _vimBufferRaw = (VimBuffer)_vimBuffer;
     _factory = new MockRepository(MockBehavior.Strict);
 }
Exemplo n.º 3
0
 public void Setup()
 {
     _textView = CreateTextView("here we go");
     _textView.MoveCaretTo(0);
     _vimBuffer = Vim.CreateVimBuffer(_textView);
     _vimBuffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap       = _vimBuffer.Vim.KeyMap;
     _vimBufferRaw = (VimBuffer)_vimBuffer;
     _factory      = new MockRepository(MockBehavior.Strict);
 }
Exemplo n.º 4
0
        /// <summary>
        /// This method is called to process KeyInput in any fashion by the IVimBuffer.  There are
        /// several cases where we want to defer to Visual Studio and IOleCommandTarget for processing
        /// of a command.  In particular we don't want to process any text input here
        /// </summary>
        protected override bool TryProcess(KeyInput keyInput)
        {
            // If the ITextView doesn't have aggregate focus then this event needs to be discarded.  This will
            // happen when a peek definition window is active.  The peek window is a child and if it fails to
            // process a key event it will bubble up to the parent window.  If the peek window has focus the
            // parent window shouldn't be handling the key
            if (!_vimHost.IsFocused(TextView))
            {
                return(false);
            }

            // Check to see if we should be discarding this KeyInput value.  If it is discarded and
            // made it back to us then we need to pretend that it was handled here
            if (_bufferCoordinator.IsDiscarded(keyInput))
            {
                return(true);
            }

            // Don't handle input when incremental search is active.  Let Visual Studio handle it
            if (_adapter.IsIncrementalSearchActive(TextView))
            {
                VimTrace.TraceInfo("VsKeyProcessor::TryProcess Incremental search active");
                return(false);
            }

            // In insert mode we don't want text input going directly to VsVim.  Text input must
            // be routed through Visual Studio and IOleCommandTarget in order to get intellisense
            // properly hooked up.  Not handling it in this KeyProcessor will eventually cause
            // it to be routed through IOleCommandTarget if it's input
            //
            // The Visual Studio KeyProcessor won't pass along control characters that are less than
            // or equal to 0x1f so we have to handle them here
            if (VimBuffer.ModeKind.IsAnyInsert() &&
                !VimBuffer.CanProcessAsCommand(keyInput) &&
                (int)keyInput.Char > 0x1f)
            {
                return(false);
            }

            // The report designer will process certain key strokes both through IOleCommandTarget and
            // then back through the KeyProcessor interface.  This happens because they call into IOleCommandTarget
            // from Control.PreProcessMessage and if the execution succeeds they return false.  This
            // causes it to continue to be processed as a normal message and hence leads to this
            // interface.  Don't process any of these keys twice
            if (_reportDesignerUtil.IsExpressionView(TextView) &&
                _reportDesignerUtil.IsSpecialHandled(keyInput))
            {
                return(false);
            }

            return(base.TryProcess(keyInput));
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method is called to process KeyInput in any fashion by the IVimBuffer.  There are
        /// several cases where we want to defer to Visual Studio and IOleCommandTarget for processing
        /// of a command.  In particular we don't want to process any text input here
        /// </summary>
        protected override bool TryProcess(KeyInput keyInput)
        {
            if (IsDiscardedKeyInput(keyInput))
            {
                return(true);
            }

            // Don't handle input when incremental search is active.  Let Visual Studio handle it
            if (_adapter.IsIncrementalSearchActive(TextView))
            {
                VimTrace.TraceInfo("VsKeyProcessor::TryProcess Incremental search active");
                return(false);
            }

            // In insert mode we don't want text input going directly to VsVim.  Text input must
            // be routed through Visual Studio and IOleCommandTarget in order to get intellisense
            // properly hooked up.  Not handling it in this KeyProcessor will eventually cause
            // it to be routed through IOleCommandTarget if it's input
            //
            // The Visual Studio KeyProcessor won't pass along control characters that are less than
            // or equal to 0x1f so we have to handle them here
            if (VimBuffer.ModeKind.IsAnyInsert() &&
                !VimBuffer.CanProcessAsCommand(keyInput) &&
                (int)keyInput.Char > 0x1f)
            {
                return(false);
            }

            // The report designer will process certain key strokes both through IOleCommandTarget and
            // then back through the KeyProcessor interface.  This happens because they call into IOleCommandTarget
            // from Control.PreProcessMessage and if the execution succeeds they return false.  This
            // causes it to continue to be processed as a normal message and hence leads to this
            // interface.  Don't process any of these keys twice
            if (_reportDesignerUtil.IsExpressionView(TextView) &&
                _reportDesignerUtil.IsSpecialHandled(keyInput))
            {
                return(false);
            }

            return(base.TryProcess(keyInput));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handle the case where we need to process a KeyDown but it will be swallowed by the
        /// TranslateAccelorator chain of input
        ///
        /// Must be **very** careful here because of international key board issues.  The base
        /// KeyProcessor in VimWPF has ample documentation on why this is dangerous.  In short
        /// though we must be as specific as possible when choosing keys to filter out because
        /// mapping a Key at this level to a Vim KeyInput with 100% accuracey is not possible
        /// </summary>
        public override void KeyDown(KeyEventArgs args)
        {
            base.KeyDown(args);
            if (args.Handled)
            {
                return;
            }

            // Don't attempt to handle this if we're in an incremental search
            if (_adapter.IsIncrementalSearchActive(TextView))
            {
                return;
            }

            // Don't process anything unless we're in a case where TranslateAccelorator would
            // win.  Also get rid of the problem cases from the start
            if (!_adapter.IsReadOnly(TextBuffer) ||
                !KeyUtil.IsInputKey(args.Key) ||
                KeyUtil.IsAltGr(args.KeyboardDevice.Modifiers))
            {
                return;
            }

            var      handled = false;
            KeyInput keyInput;

            if (KeyUtil.TryConvertToKeyInput(args.Key, args.KeyboardDevice.Modifiers, out keyInput))
            {
                // We only want to process input characters here.  All other input will eventually
                // be routed along a more reliable route for us to convert back to Vim KeyInput
                if (keyInput.KeyModifiers == KeyModifiers.None && KeyUtil.IsMappedByChar(keyInput.Key) && CoreCharacterSet.Contains(keyInput.Char))
                {
                    // We intentionally avoid using the TryProcess version here.  This is one case
                    // we don't want to defer to Visual Studio.  It thinks the buffer is readonly and
                    // will react as such while we want to do actual commands here
                    handled = VimBuffer.CanProcess(keyInput) && VimBuffer.Process(keyInput).IsAnyHandled;
                }
            }

            args.Handled = handled;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handle the case where we need to process a KeyDown but it will be swallowed by the
        /// TranslateAccelorator chain of input
        ///
        /// Must be **very** careful here because of international key board issues.  The base
        /// KeyProcessor in VimWPF has ample documentation on why this is dangerous.  In short
        /// though we must be as specific as possible when choosing keys to filter out because
        /// mapping a Key at this level to a Vim KeyInput with 100% accuracey is not possible
        /// </summary>
        public override void KeyDown(KeyEventArgs args)
        {
            // Don't intercept keystrokse if Visual Studio IncrementalSearch is active
            if (_adapter.IsIncrementalSearchActive(TextView))
            {
                return;
            }

            base.KeyDown(args);
            if (args.Handled)
            {
                return;
            }

            // Don't process anything unless we're in a case where TranslateAccelorator would
            // win.  Also get rid of the problem cases from the start
            if (!_adapter.IsReadOnly(TextBuffer) ||
                !KeyUtil.IsInputKey(args.Key) ||
                KeyUtil.IsAltGr(args.KeyboardDevice.Modifiers))
            {
                return;
            }

            var      handled = false;
            KeyInput ki;

            if (KeyUtil.TryConvertToKeyInput(args.Key, args.KeyboardDevice.Modifiers, out ki))
            {
                // We only want to process input characters here.  All other input will eventually
                // be routed along a more reliable route for us to convert back to Vim KeyInput
                if (ki.KeyModifiers == KeyModifiers.None && KeyUtil.IsMappedByChar(ki.Key) && CoreCharacterSet.Contains(ki.Char))
                {
                    handled = VimBuffer.CanProcess(ki) && VimBuffer.Process(ki);
                }
            }

            args.Handled = handled;
        }
Exemplo n.º 8
0
 public void Initialize()
 {
     _view = EditorUtil.CreateView("here we go");
     _markMap = new MarkMap(new TrackingLineColumnService());
     _globalSettings = MockObjectFactory.CreateGlobalSettings();
     _settings = MockObjectFactory.CreateLocalSettings(_globalSettings.Object);
     _keyMap = new Mock<IKeyMap>(MockBehavior.Strict);
     _host = new Mock<IVimHost>(MockBehavior.Strict);
     _vim = MockObjectFactory.CreateVim(map:_markMap, settings:_globalSettings.Object, keyMap:_keyMap.Object, host:_host.Object);
     _disabledMode = new Mock<IMode>(MockBehavior.Strict);
     _disabledMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Disabled);
     _normalMode = new Mock<INormalMode>(MockBehavior.Strict);
     _normalMode.Setup(x => x.OnEnter());
     _normalMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
     _normalMode.SetupGet(x => x.IsOperatorPending).Returns(false);
     _normalMode.SetupGet(x => x.IsWaitingForInput).Returns(false);
     _insertMode = new Mock<IMode>(MockBehavior.Strict);
     _insertMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
     _jumpList = new Mock<IJumpList>(MockBehavior.Strict);
     _rawBuffer = new VimBuffer(
         _vim.Object,
         _view,
         _jumpList.Object,
         _settings.Object);
     _rawBuffer.AddMode(_normalMode.Object);
     _rawBuffer.AddMode(_insertMode.Object);
     _rawBuffer.AddMode(_disabledMode.Object);
     _rawBuffer.SwitchMode(ModeKind.Normal);
     _buffer = _rawBuffer;
 }
Exemplo n.º 9
0
 public void Setup()
 {
     _textView = EditorUtil.CreateView("here we go");
     _textView.MoveCaretTo(0);
     _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView);
     _buffer.SwitchMode(ModeKind.Command, ModeArgument.None);
     _keyMap = _buffer.Vim.KeyMap;
     _bufferRaw = (VimBuffer)_buffer;
     _factory = new MockRepository(MockBehavior.Strict);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Try and process the given KeyInput with the IVimBuffer.  This is overridable by
 /// derived classes in order for them to prevent any KeyInput from reaching the
 /// IVimBuffer
 /// </summary>
 private bool TryProcess(KeyInput keyInput)
 {
     return(VimBuffer.CanProcess(keyInput) && VimBuffer.Process(keyInput).IsAnyHandled);
 }
Exemplo n.º 11
0
 public void Initialize()
 {
     _view = EditorUtil.CreateView("here we go");
     _markMap = new MarkMap(new TrackingLineColumnService());
     _factory = new MockRepository(MockBehavior.Strict);
     _globalSettings = MockObjectFactory.CreateGlobalSettings(factory:_factory);
     _settings = MockObjectFactory.CreateLocalSettings(_globalSettings.Object, factory:_factory);
     _keyMap = _factory.Create<IKeyMap>();
     _host = _factory.Create<IVimHost>(MockBehavior.Strict);
     _vim = MockObjectFactory.CreateVim(map: _markMap, settings: _globalSettings.Object, keyMap: _keyMap.Object, host: _host.Object, factory:_factory);
     _disabledMode = _factory.Create<IMode>(MockBehavior.Loose);
     _disabledMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Disabled);
     _normalMode = _factory.Create<INormalMode>(MockBehavior.Loose);
     _normalMode.SetupGet(x => x.KeyRemapMode).Returns(KeyRemapMode.Normal);
     _normalMode.Setup(x => x.OnEnter(ModeArgument.None));
     _normalMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Normal);
     _insertMode = _factory.Create<IMode>(MockBehavior.Loose);
     _insertMode.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
     _jumpList = _factory.Create<IJumpList>(MockBehavior.Strict);
     _incrementalSearch = _factory.Create<IIncrementalSearch>();
     _rawBuffer = new VimBuffer(
         _vim.Object,
         _view,
         _jumpList.Object,
         _settings.Object,
         _incrementalSearch.Object);
     _rawBuffer.AddMode(_normalMode.Object);
     _rawBuffer.AddMode(_insertMode.Object);
     _rawBuffer.AddMode(_disabledMode.Object);
     _rawBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None);
     _buffer = _rawBuffer;
 }