/// <summary> /// Create a Visual Studio simulation with the specified set of lines /// </summary> private void CreateCore(bool simulateResharper, bool usePeekRole, params string[] lines) { if (usePeekRole) { _textBuffer = CreateTextBuffer(lines); _textView = TextEditorFactoryService.CreateTextView( _textBuffer, TextEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, VsVimConstants.TextViewRoleEmbeddedPeekTextView)); } else { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; } _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _vsSimulation = new VsSimulation( _bufferCoordinator, simulateResharper: simulateResharper, simulateStandardKeyMappings: false, editorOperationsFactoryService: EditorOperationsFactoryService, keyUtil: KeyUtil); VimHost.TryCustomProcessFunc = (textView, insertCommand) => { if (textView == _textView) { return(_vsSimulation.VsCommandTarget.TryCustomProcess(insertCommand)); } return(false); }; }
/// <summary> /// Create a Visual Studio simulation with the specified set of lines /// </summary> private void Create(bool simulateResharper, params string[] lines) { _textView = CreateTextView(lines); _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _simulation = new VsSimulation(_bufferCoordinator, simulateResharper); }
protected void Create(params string[] lines) { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _globalSettings = Vim.GlobalSettings; }
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; }; }
public void TryConvert_TextInputToOleCommandData() { var textView = CreateTextView(""); var buffer = Vim.CreateVimBuffer(textView); buffer.SwitchMode(ModeKind.Insert, ModeArgument.None); foreach (var cur in KeyInputUtil.VimKeyInputList) { if (!buffer.InsertMode.IsDirectInsert(cur)) { continue; } var oleCommandData = OleCommandData.Empty; try { Assert.True(OleCommandUtil.TryConvert(cur, out oleCommandData)); // We lose fidelity on these keys because they both get written out as numbers // at this point if (VimKeyUtil.IsKeypadKey(cur.Key)) { continue; } Assert.True(OleCommandUtil.TryConvert(oleCommandData, out KeyInput converted)); Assert.Equal(converted, cur); } finally { oleCommandData.Dispose(); } } }
public void CreateVimBuffer2() { var view = CreateTextView("foo bar"); var vimBuffer = Vim.CreateVimBuffer(view); Assert.Throws <ArgumentException>(() => Vim.CreateVimBuffer(view)); }
protected IVimBuffer CreateVimBufferWithName(string fileName, params string[] lines) { var textView = CreateTextView(lines); textView.TextBuffer.Properties[MockVimHost.FileNameKey] = fileName; return(Vim.CreateVimBuffer(textView)); }
public void CreateVimBuffer1() { var view = CreateTextView("foo bar"); var vimBuffer = Vim.CreateVimBuffer(view); Assert.True(Vim.TryGetVimBuffer(view, out IVimBuffer found)); Assert.Same(view, found.TextView); }
protected void Create(params string[] lines) { _textView = CreateTextView(lines); _vimBuffer = Vim.CreateVimBuffer(_textView); _vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None); _globalSettings = _vimBuffer.LocalSettings.GlobalSettings; VimHost.FocusedTextView = _textView; }
public void RemoveBuffer2() { var view = CreateTextView("foo bar"); var vimBuffer = Vim.CreateVimBuffer(view); Assert.True(Vim.RemoveVimBuffer(view)); Assert.False(Vim.TryGetVimBuffer(view, out vimBuffer)); }
public void GetOrCreateVimBufferForHost_AlreadyCreated() { VimHost.ShouldCreateVimBufferImpl = false; var textView = CreateTextView(""); Vim.CreateVimBuffer(textView); Assert.True(Vim.TryGetOrCreateVimBufferForHost(textView, out IVimBuffer vimBuffer)); Assert.NotNull(vimBuffer); }
protected void Create(ModeArgument argument, params string[] lines) { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _vimBuffer.SwitchMode(ModeKind.Insert, argument); _register = Vim.RegisterMap.GetRegister('c'); _globalSettings = Vim.GlobalSettings; _localSettings = _vimBuffer.LocalSettings; }
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); }
/// <summary> /// Create the IVimBuffer with the given set of lines. Note that we intentionally don't /// set the mode to Insert here because the given commands should work irrespective of the /// mode /// </summary> /// <param name="lines"></param> private void Create(params string[] lines) { _textView = CreateTextView(lines); _buffer = Vim.CreateVimBuffer(_textView); _globalSettings = _buffer.GlobalSettings; _localSettings = _buffer.LocalSettings; var operations = CommonOperationsFactory.GetCommonOperations(_buffer.VimBufferData); _insertUtilRaw = new InsertUtil(_buffer.VimBufferData, operations); _insertUtil = _insertUtilRaw; }
/// <summary> /// Create a Visual Studio simulation with the specified set of lines /// </summary> private void Create(bool simulateResharper, params string[] lines) { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _simulation = new VsSimulation( _bufferCoordinator, simulateResharper: simulateResharper, simulateStandardKeyMappings: false, editorOperationsFactoryService: EditorOperationsFactoryService); }
/// <summary> /// Create the IVimBuffer with the given set of lines. Note that we intentionally don't /// set the mode to Insert here because the given commands should work irrespective of the /// mode. There are a few tests that rely on behavior from SelectionChangeTracker so they set /// the mode to Insert. /// </summary> /// <param name="lines"></param> protected virtual void Create(params string[] lines) { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _globalSettings = _vimBuffer.GlobalSettings; _localSettings = _vimBuffer.LocalSettings; var operations = CommonOperationsFactory.GetCommonOperations(_vimBuffer.VimBufferData); var motionUtil = new MotionUtil(_vimBuffer.VimBufferData, operations); _insertUtilRaw = new InsertUtil(_vimBuffer.VimBufferData, motionUtil, operations); _insertUtil = _insertUtilRaw; }
private IVimBuffer CreateVimBufferForMindScape(params string[] lines) { var contentType = ContentTypeRegistryService.GetContentType("scss"); if (contentType == null) { contentType = ContentTypeRegistryService.AddContentType("scss", new[] { "text " }); } var textBuffer = CreateTextBuffer(contentType, lines); var textView = TextEditorFactoryService.CreateTextView(textBuffer); return(Vim.CreateVimBuffer(textView)); }
protected VsCommandTargetTest(bool isReSharperInstalled) { _textView = CreateTextView(""); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _vim = _vimBuffer.Vim; _factory = new MockRepository(MockBehavior.Strict); _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict); _vsAdapter = _factory.Create <IVsAdapter>(); _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice); _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false); _vsAdapter.Setup(x => x.InDebugMode).Returns(false); _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false); _broker = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose); _textManager = _factory.Create <ITextManager>(); _commonOperations = _factory.Create <ICommonOperations>(); _vimApplicationSettings = _factory.Create <IVimApplicationSettings>(); var commandTargets = new List <ICommandTarget>(); if (isReSharperInstalled) { commandTargets.Add(ReSharperKeyUtil.GetOrCreate(_bufferCoordinator)); } commandTargets.Add(new StandardCommandTarget( _bufferCoordinator, _textManager.Object, _commonOperations.Object, _broker.Object, _nextTarget.Object)); var oldCommandFilter = _nextTarget.Object; _targetRaw = new VsCommandTarget( _bufferCoordinator, _textManager.Object, _vsAdapter.Object, _broker.Object, KeyUtil, _vimApplicationSettings.Object, _nextTarget.Object, commandTargets.ToReadOnlyCollectionShallow()); _target = _targetRaw; }
public void CloseBufferDuringRecord() { VimHost.CloseFunc = textView => textView.Close(); var textView2 = CreateTextView("another buffer"); var vimBuffer2 = Vim.CreateVimBuffer(textView2); vimBuffer2.SwitchMode(ModeKind.Normal, ModeArgument.None); Create("hello world"); _vimBuffer.Process("qaZQ"); Assert.True(_vimBuffer.IsClosed); VimHost.FocusedTextView = textView2; vimBuffer2.Process("q"); Assert.Equal("ZQ", _vimBuffer.GetRegister('a').StringValue); }
public void Create(bool hasTextLines, bool hasTagger, params string[] lines) { _factory = new MockRepository(MockBehavior.Loose); _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; _buffer = Vim.CreateVimBuffer(_textView); _vimApplicationSettings = _factory.Create <IVimApplicationSettings>(); _vimApplicationSettings.SetupGet(x => x.EnableExternalEditMonitoring).Returns(true); // Have adatper ignore by default _adapter = _factory.Create <IExternalEditAdapter>(MockBehavior.Strict); _adapter.Setup(x => x.IsExternalEditTag(It.IsAny <ITag>())).Returns(false); _adapter.Setup(x => x.IsExternalEditMarker(It.IsAny <IVsTextLineMarker>())).Returns(false); var adapterList = new List <IExternalEditAdapter> { _adapter.Object }; Result <IVsTextLines> textLines = Result.Error; if (hasTextLines) { _vsTextLines = _factory.Create <IVsTextLines>(MockBehavior.Strict); _vsTextLines.SetupNoEnumMarkers(); textLines = Result.CreateSuccess(_vsTextLines.Object); } var taggerList = new List <ITagger <ITag> >(); if (hasTagger) { _tagger = _factory.Create <ITagger <ITag> >(MockBehavior.Loose); _tagger.Setup(x => x.GetTags(It.IsAny <NormalizedSnapshotSpanCollection>())).Returns(new List <ITagSpan <ITag> >()); taggerList.Add(_tagger.Object); } _monitor = new ExternalEditMonitor( _vimApplicationSettings.Object, _buffer, ProtectedOperations, textLines, taggerList.ToReadOnlyCollectionShallow(), adapterList.ToReadOnlyCollectionShallow()); }
public void CloseBufferDuringRecord() { var textView2 = CreateTextView("another buffer"); var vimBuffer2 = Vim.CreateVimBuffer(textView2); vimBuffer2.SwitchMode(ModeKind.Normal, ModeArgument.None); Create("hello world"); // Stand-in for HostFactory which calls IVimBuffer.Close in response to the associated ITextView.Closed. // The root cause of the referenced issue was that MacroRecorder disposed its buffer event handlers on IVimBuffer.Close. // Since IVimBuffer.Close is raised before the final IVimBuffer.KeyInputEnd is raised, the last keystroke failed to record. _textView.Closed += (s, e) => _vimBuffer.Close(); _vimBuffer.Process("qaZQ"); Assert.True(_vimBuffer.IsClosed); VimHost.FocusedTextView = textView2; vimBuffer2.Process("q"); Assert.Equal("ZQ", _vimBuffer.GetRegister('a').StringValue); }
protected VsCommandTargetTest() { _textView = CreateTextView(""); _textBuffer = _textView.TextBuffer; _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _vim = _vimBuffer.Vim; _factory = new MockRepository(MockBehavior.Strict); // By default Resharper isn't loaded _resharperUtil = _factory.Create <IReSharperUtil>(); _resharperUtil.SetupGet(x => x.IsInstalled).Returns(false); _nextTarget = _factory.Create <IOleCommandTarget>(MockBehavior.Strict); _vsAdapter = _factory.Create <IVsAdapter>(); _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice); _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false); _vsAdapter.Setup(x => x.InDebugMode).Returns(false); _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny <ITextView>())).Returns(false); _broker = _factory.Create <IDisplayWindowBroker>(MockBehavior.Loose); _textManager = _factory.Create <ITextManager>(); var oldCommandFilter = _nextTarget.Object; var vsTextView = _factory.Create <IVsTextView>(MockBehavior.Loose); vsTextView.Setup(x => x.AddCommandFilter(It.IsAny <IOleCommandTarget>(), out oldCommandFilter)).Returns(0); var result = VsCommandTarget.Create( _bufferCoordinator, vsTextView.Object, _textManager.Object, _vsAdapter.Object, _broker.Object, _resharperUtil.Object, KeyUtil); Assert.True(result.IsSuccess); _targetRaw = result.Value; _target = _targetRaw; }
/// <summary> /// Create a Visual Studio simulation with the specified set of lines /// </summary> private void CreateCore(bool simulateResharper, bool usePeekRole, params string[] lines) { if (usePeekRole) { _textBuffer = CreateTextBuffer(lines); _textView = TextEditorFactoryService.CreateTextView( _textBuffer, TextEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Document, PredefinedTextViewRoles.Editable, Constants.TextViewRoleEmbeddedPeekTextView)); } else { _textView = CreateTextView(lines); _textBuffer = _textView.TextBuffer; } _vimBuffer = Vim.CreateVimBuffer(_textView); _bufferCoordinator = new VimBufferCoordinator(_vimBuffer); _vsSimulation = new VsSimulation( _bufferCoordinator, simulateResharper: simulateResharper, simulateStandardKeyMappings: false, editorOperationsFactoryService: EditorOperationsFactoryService, keyUtil: KeyUtil); }
/// <summary> /// Create an IVimBuffer instance with the given lines /// </summary> protected IVimBuffer CreateVimBuffer(params string[] lines) { var textView = CreateTextView(lines); return(Vim.CreateVimBuffer(textView)); }
private void CreateBuffer(params string[] lines) { _textView = CreateTextView(lines); _buffer = Vim.CreateVimBuffer(_textView); }