protected void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView             = CreateTextView(lines);
            _textBuffer           = _textView.TextBuffer;
            _vim               = _factory.Create <IVim>(MockBehavior.Loose);
            _editorOptions     = _factory.Create <IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create <ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
            _undoRedoOperations = new UndoRedoOperations(VimHost, new StatusUtil(), FSharpOption <ITextUndoHistory> .None, null);
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer      = Vim.CreateVimBuffer(_textView);
            _globalSettings = _vimBuffer.GlobalSettings;
            var vimTextBuffer = Vim.GetOrCreateVimTextBuffer(_textView.TextBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);

            _operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _broker     = _factory.Create <IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _broker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);
            _insertUtil  = _factory.Create <IInsertUtil>();
            _motionUtil  = _factory.Create <IMotionUtil>();
            _commandUtil = _factory.Create <ICommandUtil>();
            _capture     = _factory.Create <IMotionCapture>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create <IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create <IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsArrowKeyDown).Returns(false);

            _modeRaw = new global::Vim.Modes.Insert.InsertMode(
                _vimBuffer,
                _operations,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations,
                _textChangeTracker.Object,
                _insertUtil.Object,
                _motionUtil.Object,
                _commandUtil.Object,
                _capture.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                WordUtil,
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e.CommandRunData; };
        }
Example #2
0
        /// <summary>
        /// Determine if the IInsertMode value should process the given KeyInput
        /// </summary>
        private bool CanProcessDirectly(IInsertMode mode, KeyInput keyInput)
        {
            // Don't let the mode directly process anything it considers text input.  We need this to go
            // through IOleCommandTarget in order to get InsertMode values.
            if (mode.IsTextInput(keyInput))
            {
                return(false);
            }

            var isAnyArrow =
                keyInput.Key == VimKey.Up ||
                keyInput.Key == VimKey.Down ||
                keyInput.Key == VimKey.Left ||
                keyInput.Key == VimKey.Right;

            // If this is any of the arrow keys and one of the help windows is active then don't
            // let insert mode process the input.  We want the KeyInput to be routed to the windows
            // like Intellisense so navigation can occur
            if (isAnyArrow && (_broker.IsCompletionActive || _broker.IsQuickInfoActive || _broker.IsSignatureHelpActive || _broker.IsSmartTagSessionActive))
            {
                return(false);
            }

            // Unfortunately there is no way to detect if the R# completion windows are active.  We have
            // to take the pessimistic view that they are not and just not handle the input
            if (isAnyArrow && _externalEditManager.IsResharperLoaded)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
 public void SetUp(bool insertMode)
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _factory.DefaultValue = DefaultValue.Mock;
     _textView             = EditorUtil.CreateView();
     _vim            = _factory.Create <IVim>(MockBehavior.Loose);
     _editorOptions  = _factory.Create <IEditorOptions>(MockBehavior.Loose);
     _globalSettings = _factory.Create <IVimGlobalSettings>();
     _localSettings  = _factory.Create <IVimLocalSettings>();
     _localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
     _textChangeTracker = _factory.Create <ITextChangeTracker>();
     _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
     _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
     _data = MockObjectFactory.CreateVimBuffer(
         _textView,
         settings: _localSettings.Object,
         vim: _vim.Object,
         factory: _factory);
     _operations = _factory.Create <ICommonOperations>();
     _operations.SetupGet(x => x.EditorOperations).Returns(_factory.Create <IEditorOperations>().Object);
     _broker = _factory.Create <IDisplayWindowBroker>();
     _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
     _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
     _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
     _modeRaw = new Vim.Modes.Insert.InsertMode(
         _data.Object,
         _operations.Object,
         _broker.Object,
         _editorOptions.Object,
         _undoRedoOperations.Object,
         _textChangeTracker.Object,
         _isReplace: !insertMode);
     _mode = _modeRaw;
 }
Example #4
0
        private void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView             = CreateTextView(lines);
            _textBuffer           = _textView.TextBuffer;
            _vim               = _factory.Create <IVim>(MockBehavior.Loose);
            _editorOptions     = _factory.Create <IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create <ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption <TextChange> .None);
            _undoRedoOperations = _factory.Create <IUndoRedoOperations>();
            _wordCompletionSessionFactoryService = _factory.Create <IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);

            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                _textView,
                localSettings: localSettings,
                vim: _vim.Object,
                factory: _factory);
            _vimBuffer.SetupGet(x => x.ModeKind).Returns(ModeKind.Insert);
            _operations = _factory.Create <ICommonOperations>();
            _operations.SetupGet(x => x.EditorOperations).Returns(EditorUtil.FactoryService.EditorOperationsFactory.GetEditorOperations(_textView));
            _broker = _factory.Create <IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _insertUtil = _factory.Create <IInsertUtil>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create <IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create <IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsKeyDown(It.IsAny <VimKey>())).Returns(false);

            _modeRaw = new Vim.Modes.Insert.InsertMode(
                _vimBuffer.Object,
                _operations.Object,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations.Object,
                _textChangeTracker.Object,
                _insertUtil.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                EditorUtil.FactoryService.WordUtilFactory.GetWordUtil(_textView.TextBuffer),
                _wordCompletionSessionFactoryService.Object);
            _mode             = _modeRaw;
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e; };
        }
Example #5
0
        /// <summary>
        /// Determine if the IInsertMode value should process the given KeyInput
        /// </summary>
        private bool ShouldProcessWithCommandTargetOverInsertMode(IInsertMode mode, KeyInput keyInput)
        {
            // In the middle of a word completion session let insert mode handle the input.  It's
            // displaying the intellisense itself and this method is meant to let custom intellisense
            // operate normally
            if (mode.ActiveWordCompletionSession.IsSome())
            {
                return(false);
            }

            // Don't let the mode directly process anything it considers direct input.  We need this to go
            // through IOleCommandTarget in order for features like intellisense to work properly
            if (mode.IsDirectInsert(keyInput))
            {
                return(true);
            }

            // Don't handle Enter or Tab in general as they are often very much special cased by the
            // language service
            if (keyInput == KeyInputUtil.EnterKey || keyInput.Key == VimKey.Tab)
            {
                return(true);
            }

            // Is this a key known to impact IntelliSense
            var isIntelliSenseKey =
                keyInput.Key == VimKey.Up ||
                keyInput.Key == VimKey.Down ||
                keyInput.Key == VimKey.Left ||
                keyInput.Key == VimKey.Right ||
                keyInput.Key == VimKey.Tab ||
                keyInput.Key == VimKey.Back ||
                keyInput == KeyInputUtil.EnterKey;

            // If this is any of the arrow keys and one of the help windows is active then don't
            // let insert mode process the input.  We want the KeyInput to be routed to the windows
            // like Intellisense so navigation can occur
            if (isIntelliSenseKey && (_broker.IsCompletionActive || _broker.IsQuickInfoActive || _broker.IsSignatureHelpActive || _broker.IsSmartTagSessionActive))
            {
                return(true);
            }

            // Unfortunately there is no way to detect if the R# completion windows are active.  We have
            // to take the pessimistic view that they are and just not handle the input
            if (isIntelliSenseKey && _externalEditManager.IsResharperInstalled)
            {
                return(true);
            }

            return(false);
        }
Example #6
0
        /// <summary>
        /// Determine if the IInsertMode value should process the given KeyInput
        /// </summary>
        private bool CanProcessDirectly(IInsertMode mode, KeyInput keyInput)
        {
            // Don't let the mode directly process anything it considers text input.  We need this to go
            // through IOleCommandTarget in order to get InsertMode values.
            if (mode.IsTextInput(keyInput))
            {
                return false;
            }

            var isAnyArrow =
                keyInput.Key == VimKey.Up ||
                keyInput.Key == VimKey.Down ||
                keyInput.Key == VimKey.Left ||
                keyInput.Key == VimKey.Right;

            // If this is any of the arrow keys and one of the help windows is active then don't
            // let insert mode process the input.  We want the KeyInput to be routed to the windows
            // like Intellisense so navigation can occur
            if (isAnyArrow && (_broker.IsCompletionActive || _broker.IsQuickInfoActive || _broker.IsSignatureHelpActive || _broker.IsSmartTagSessionActive))
            {
                return false;
            }

            // Unfortunately there is no way to detect if the R# completion windows are active.  We have
            // to take the pessimistic view that they are not and just not handle the input
            if (isAnyArrow && _externalEditManager.IsResharperLoaded)
            {
                return false;
            }

            return true;
        }
Example #7
0
        protected void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView = CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vim = _factory.Create<IVim>(MockBehavior.Loose);
            _editorOptions = _factory.Create<IEditorOptions>(MockBehavior.Loose);
            _textChangeTracker = _factory.Create<ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption<TextChange>.None);
            _undoRedoOperations = CreateUndoRedoOperations();
            _wordCompletionSessionFactoryService = _factory.Create<IWordCompletionSessionFactoryService>();

            var localSettings = new LocalSettings(Vim.GlobalSettings);
            _vimBuffer = Vim.CreateVimBuffer(_textView);
            _globalSettings = _vimBuffer.GlobalSettings;
            var vimTextBuffer = Vim.GetOrCreateVimTextBuffer(_textView.TextBuffer);
            var vimBufferData = CreateVimBufferData(vimTextBuffer, _textView);
            _operations = CommonOperationsFactory.GetCommonOperations(vimBufferData);
            _broker = _factory.Create<IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _broker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);
            _insertUtil = _factory.Create<IInsertUtil>();
            _motionUtil = _factory.Create<IMotionUtil>();
            _commandUtil = _factory.Create<ICommandUtil>();
            _capture = _factory.Create<IMotionCapture>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create<IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create<IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsArrowKeyDown).Returns(false);

            _modeRaw = new global::Vim.Modes.Insert.InsertMode(
                _vimBuffer,
                _operations,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations,
                _textChangeTracker.Object,
                _insertUtil.Object,
                _motionUtil.Object,
                _commandUtil.Object,
                _capture.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                WordUtil,
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.OnEnter(ModeArgument.None);
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e.CommandRunData; };
        }
Example #8
0
        /// <summary>
        /// Try and process the given KeyInput for insert mode in the middle of an Exec.  This is 
        /// called for commands which can't be processed directly like edits.  We'd prefer these 
        /// go through Visual Studio's command system so items like Intellisense work properly.
        /// </summary>
        private bool TryProcessWithExec(Guid commandGroup, OleCommandData oleCommandData, IInsertMode insertMode, KeyInput originalKeyInput, KeyInput mappedKeyInput)
        {
            Func<bool> customProcess =
                () =>
                {
                    var versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                    int? hr = null;
                    Guid mappedCommandGroup;
                    OleCommandData mappedOleCommandData;
                    if (originalKeyInput == mappedKeyInput)
                    {
                        // No changes so just use the original OleCommandData
                        hr = _nextTarget.Exec(
                            ref commandGroup,
                            oleCommandData.CommandId,
                            oleCommandData.CommandExecOpt,
                            oleCommandData.VariantIn,
                            oleCommandData.VariantOut);
                    }
                    else if (OleCommandUtil.TryConvert(mappedKeyInput, out mappedCommandGroup, out mappedOleCommandData))
                    {
                        hr = _nextTarget.Exec(
                            ref mappedCommandGroup,
                            mappedOleCommandData.CommandId,
                            mappedOleCommandData.CommandExecOpt,
                            mappedOleCommandData.VariantIn,
                            mappedOleCommandData.VariantOut);
                        OleCommandData.Release(ref mappedOleCommandData);
                    }

                    if (hr.HasValue)
                    {
                        // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                        // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into
                        // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                        // consider cases where the character successfully resulted in no action as a success
                        return ErrorHandler.Succeeded(hr.Value) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber;
                    }

                    // Couldn't map to a Visual Studio command so it didn't succeed
                    return false;
                };

            return insertMode.CustomProcess(mappedKeyInput, customProcess.ToFSharpFunc());
        }
Example #9
0
        /// <summary>
        /// Determine if the IInsertMode value should process the given KeyInput
        /// </summary>
        private bool ShouldProcessWithCommandTargetOverInsertMode(IInsertMode mode, KeyInput keyInput)
        {
            // In the middle of a word completion session let insert mode handle the input.  It's
            // displaying the intellisense itself and this method is meant to let custom intellisense
            // operate normally
            if (mode.ActiveWordCompletionSession.IsSome())
            {
                return false;
            }

            // Don't let the mode directly process anything it considers direct input.  We need this to go
            // through IOleCommandTarget in order for features like intellisense to work properly
            if (mode.IsDirectInsert(keyInput))
            {
                return true;
            }

            // Don't handle Enter or Tab in general as they are often very much special cased by the
            // language service
            if (keyInput == KeyInputUtil.EnterKey || keyInput.Key == VimKey.Tab)
            {
                return true;
            }

            // Is this a key known to impact IntelliSense
            var isIntelliSenseKey =
                keyInput.Key == VimKey.Up ||
                keyInput.Key == VimKey.Down ||
                keyInput.Key == VimKey.Left ||
                keyInput.Key == VimKey.Right ||
                keyInput.Key == VimKey.Tab ||
                keyInput.Key == VimKey.Back ||
                keyInput == KeyInputUtil.EnterKey;

            // If this is any of the arrow keys and one of the help windows is active then don't
            // let insert mode process the input.  We want the KeyInput to be routed to the windows
            // like Intellisense so navigation can occur
            if (isIntelliSenseKey && (_broker.IsCompletionActive || _broker.IsQuickInfoActive || _broker.IsSignatureHelpActive || _broker.IsSmartTagSessionActive))
            {
                return true;
            }

            // Unfortunately there is no way to detect if the R# completion windows are active.  We have
            // to take the pessimistic view that they are and just not handle the input
            if (isIntelliSenseKey && _externalEditManager.IsResharperInstalled)
            {
                return true;
            }

            return false;
        }
Example #10
0
        /// <summary>
        /// Try and process the given KeyInput for insert mode in the middle of an Exec.  This is
        /// called for commands which can't be processed directly like edits.  We'd prefer these
        /// go through Visual Studio's command system so items like Intellisense work properly.
        /// </summary>
        private bool TryProcessWithExec(Guid commandGroup, OleCommandData oleCommandData, IInsertMode insertMode, KeyInput originalKeyInput, KeyInput mappedKeyInput)
        {
            Func <bool> customProcess =
                () =>
            {
                var            versionNumber = _textBuffer.CurrentSnapshot.Version.VersionNumber;
                int?           hr            = null;
                Guid           mappedCommandGroup;
                OleCommandData mappedOleCommandData;
                if (originalKeyInput == mappedKeyInput)
                {
                    // No changes so just use the original OleCommandData
                    hr = _nextTarget.Exec(
                        ref commandGroup,
                        oleCommandData.CommandId,
                        oleCommandData.CommandExecOpt,
                        oleCommandData.VariantIn,
                        oleCommandData.VariantOut);
                }
                else if (OleCommandUtil.TryConvert(mappedKeyInput, out mappedCommandGroup, out mappedOleCommandData))
                {
                    hr = _nextTarget.Exec(
                        ref mappedCommandGroup,
                        mappedOleCommandData.CommandId,
                        mappedOleCommandData.CommandExecOpt,
                        mappedOleCommandData.VariantIn,
                        mappedOleCommandData.VariantOut);
                    OleCommandData.Release(ref mappedOleCommandData);
                }

                if (hr.HasValue)
                {
                    // Whether or not an Exec succeeded is a bit of a heuristic.  IOleCommandTarget implementations like
                    // C++ will return E_ABORT if Intellisense failed but the character was actually inserted into
                    // the ITextBuffer.  VsVim really only cares about the character insert.  However we must also
                    // consider cases where the character successfully resulted in no action as a success
                    return(ErrorHandler.Succeeded(hr.Value) || versionNumber < _textBuffer.CurrentSnapshot.Version.VersionNumber);
                }

                // Couldn't map to a Visual Studio command so it didn't succeed
                return(false);
            };

            return(insertMode.CustomProcess(mappedKeyInput, customProcess.ToFSharpFunc()));
        }
Example #11
0
 public void SetUp(bool insertMode)
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _factory.DefaultValue = DefaultValue.Mock;
     _textView = EditorUtil.CreateView();
     _vim = _factory.Create<IVim>(MockBehavior.Loose);
     _editorOptions = _factory.Create<IEditorOptions>(MockBehavior.Loose);
     _globalSettings = _factory.Create<IVimGlobalSettings>();
     _localSettings = _factory.Create<IVimLocalSettings>();
     _localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
     _textChangeTracker = _factory.Create<ITextChangeTracker>();
     _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption<TextChange>.None);
     _undoRedoOperations = _factory.Create<IUndoRedoOperations>();
     _data = MockObjectFactory.CreateVimBuffer(
         _textView,
         settings: _localSettings.Object,
         vim: _vim.Object,
         factory: _factory);
     _operations = _factory.Create<ICommonOperations>();
     _operations.SetupGet(x => x.EditorOperations).Returns(_factory.Create<IEditorOperations>().Object);
     _broker = _factory.Create<IDisplayWindowBroker>();
     _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
     _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
     _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
     _modeRaw = new Vim.Modes.Insert.InsertMode(
         _data.Object,
         _operations.Object,
         _broker.Object,
         _editorOptions.Object,
         _undoRedoOperations.Object,
         _textChangeTracker.Object,
         _isReplace: !insertMode);
     _mode = _modeRaw;
 }
Example #12
0
        private void Create(bool insertMode, params string[] lines)
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _factory.DefaultValue = DefaultValue.Mock;
            _textView = EditorUtil.CreateTextView(lines);
            _textBuffer = _textView.TextBuffer;
            _vim = _factory.Create<IVim>(MockBehavior.Loose);
            _editorOptions = _factory.Create<IEditorOptions>(MockBehavior.Loose);
            _globalSettings = _factory.Create<IVimGlobalSettings>();
            _globalSettings.SetupGet(x => x.IgnoreCase).Returns(true);
            _localSettings = _factory.Create<IVimLocalSettings>();
            _localSettings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object);
            _textChangeTracker = _factory.Create<ITextChangeTracker>(MockBehavior.Loose);
            _textChangeTracker.SetupGet(x => x.CurrentChange).Returns(FSharpOption<TextChange>.None);
            _undoRedoOperations = _factory.Create<IUndoRedoOperations>();
            _wordCompletionSessionFactoryService = _factory.Create<IWordCompletionSessionFactoryService>();

            _vimBuffer = MockObjectFactory.CreateVimBuffer(
                _textView,
                localSettings: _localSettings.Object,
                vim: _vim.Object,
                factory: _factory);
            _operations = _factory.Create<ICommonOperations>();
            _operations.SetupGet(x => x.EditorOperations).Returns(EditorUtil.FactoryService.EditorOperationsFactory.GetEditorOperations(_textView));
            _broker = _factory.Create<IDisplayWindowBroker>();
            _broker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _broker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _broker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _insertUtil = _factory.Create<IInsertUtil>();

            // Setup the mouse.  By default we say it has no buttons down as that's the normal state
            _mouseDevice = _factory.Create<IMouseDevice>();
            _mouseDevice.SetupGet(x => x.IsLeftButtonPressed).Returns(false);

            // Setup the keyboard.  By default we don't say that any button is pressed.  Insert mode is usually
            // only concerned with arrow keys and we will set those up as appropriate for the typing tests
            _keyboardDevice = _factory.Create<IKeyboardDevice>();
            _keyboardDevice.Setup(x => x.IsKeyDown(It.IsAny<VimKey>())).Returns(false);

            _modeRaw = new Vim.Modes.Insert.InsertMode(
                _vimBuffer.Object,
                _operations.Object,
                _broker.Object,
                _editorOptions.Object,
                _undoRedoOperations.Object,
                _textChangeTracker.Object,
                _insertUtil.Object,
                !insertMode,
                _keyboardDevice.Object,
                _mouseDevice.Object,
                EditorUtil.FactoryService.WordUtilFactory.GetWordUtil(_textView.TextBuffer),
                _wordCompletionSessionFactoryService.Object);
            _mode = _modeRaw;
            _mode.CommandRan += (sender, e) => { _lastCommandRan = e; };
        }