private void OnSearchStarted(string searchText) { // Cautiously record which buffers have pre-existing selections. _selected = _textManager .GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty) .Select(x => new WeakReference <ITextView>(x)) .ToList(); _inSearch = true; VimTrace.TraceInfo("NavigateTo Start: {0}", searchText); }
private void OnSearchStopped() { if (_inSearch) { // Once the search is stopped clear out all of the selections in active buffers. Leaving the // selection puts us into Visual Mode. Don't force any document loads here. If the document // isn't loaded then it can't have a selection which will interfere with this _inSearch = false; _textManager.GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty) .ForEach(x => x.Selection.Clear()); } }
public override bool GoToDefinition() { var selected = _textManager .GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty).ToList(); if (!GoToDefinitionCore(_textManager.ActiveTextViewOptional, null)) { return(false); } // Certain language services, VB.Net for example, will select the word after // the go to definition is implemented. Need to clear that out to prevent the // go to definition from switching us to Visual Mode // // This selection often occurs in another document but that document won't be // active when we get back here. Instead just clear all of the new selections _textManager .GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty && !selected.Contains(x)) .ForEach(x => x.Selection.Clear()); return(true); }
internal bool Exec(EditCommand editCommand, out Action action) { action = null; // If the KeyInput was already handled then pretend we handled it here if (editCommand.HasKeyInput && _vimBufferCoordinator.IsDiscarded(editCommand.KeyInput)) { return(true); } switch (editCommand.EditCommandKind) { case EditCommandKind.Undo: // The user hit the undo button. Don't attempt to map anything here and instead just // run a single Vim undo operation _vimBuffer.UndoRedoOperations.Undo(1); return(true); case EditCommandKind.Redo: // The user hit the redo button. Don't attempt to map anything here and instead just // run a single Vim redo operation _vimBuffer.UndoRedoOperations.Redo(1); return(true); case EditCommandKind.Paste: return(Paste()); case EditCommandKind.GoToDefinition: // The GoToDefinition command will often cause a selection to occur in the // buffer. We don't want that to cause us to enter Visual Mode so clear it // out. This command can cause the active document to switch if the target // of the goto def is in another file. This file won't be registered as the // active file yet so just clear out the active selections action = () => { _textManager.GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty) .ForEach(x => x.Selection.Clear()); }; return(false); case EditCommandKind.Comment: case EditCommandKind.Uncomment: // The comment / uncomment command will often induce a selection on the // editor even if there was no selection before the command was run (single line // case). if (_textView.Selection.IsEmpty) { action = () => { _textView.Selection.Clear(); }; } return(false); case EditCommandKind.UserInput: case EditCommandKind.VisualStudioCommand: if (editCommand.HasKeyInput) { var keyInput = editCommand.KeyInput; // Discard the input if it's been flagged by a previous QueryStatus if (_vimBufferCoordinator.IsDiscarded(keyInput)) { return(true); } // Try and process the command with the IVimBuffer if (TryProcessWithBuffer(keyInput)) { return(true); } } return(false); default: Debug.Assert(false); return(false); } }
internal bool Exec(EditCommand editCommand, out Action preAction, out Action postAction) { preAction = null; postAction = null; // If the KeyInput was already handled then pretend we handled it here if (editCommand.HasKeyInput && _vimBufferCoordinator.IsDiscarded(editCommand.KeyInput)) { return(true); } switch (editCommand.EditCommandKind) { case EditCommandKind.Undo: // The user hit the undo button. Don't attempt to map anything here and instead just // run a single Vim undo operation _vimBuffer.UndoRedoOperations.Undo(1); return(true); case EditCommandKind.Redo: // The user hit the redo button. Don't attempt to map anything here and instead just // run a single Vim redo operation _vimBuffer.UndoRedoOperations.Redo(1); return(true); case EditCommandKind.Paste: return(Paste()); case EditCommandKind.GoToDefinition: // The GoToDefinition command will often cause a selection to occur in the // buffer. We don't want that to cause us to enter Visual Mode so clear it // out. This command can cause the active document to switch if the target // of the goto def is in another file. This file won't be registered as the // active file yet so just clear out the active selections List <ITextView> selected = null; preAction = () => { // Record which buffers have pre-existing selections. selected = _textManager .GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty) .ToList(); }; postAction = () => { // Clear any new selections. _textManager.GetDocumentTextViews(DocumentLoad.RespectLazy) .Where(x => !x.Selection.IsEmpty && !selected.Contains(x)) .ForEach(x => { // Move the caret to the beginning of the selection. var startPoint = x.Selection.Start; x.Selection.Clear(); x.Caret.MoveTo(startPoint); }); }; return(false); case EditCommandKind.Comment: case EditCommandKind.Uncomment: // The comment / uncomment command will often induce a selection on the // editor even if there was no selection before the command was run (single line // case). if (_textView.Selection.IsEmpty) { postAction = () => { _textView.Selection.Clear(); }; } return(false); case EditCommandKind.UserInput: case EditCommandKind.VisualStudioCommand: if (editCommand.HasKeyInput) { var keyInput = editCommand.KeyInput; // Discard the input if it's been flagged by a previous QueryStatus if (_vimBufferCoordinator.IsDiscarded(keyInput)) { return(true); } // Try and process the command with the IVimBuffer if (TryProcessWithBuffer(keyInput)) { return(true); } // Discard any other unprocessed printable input in // non-input modes. Without this, Visual Studio will // see the command as unhandled and will try to handle // it itself by inserting the character into the // buffer. if (editCommand.EditCommandKind == EditCommandKind.UserInput && CharUtil.IsPrintable(keyInput.Char) && (_vimBuffer.ModeKind == ModeKind.Normal || _vimBuffer.ModeKind.IsAnyVisual())) { _commonOperations.Beep(); return(true); } } return(false); default: Debug.Assert(false); return(false); } }