private int SetMode(IntPtr variantIn, IntPtr variantOut, uint commandExecOpt) { if (IsQueryParameterList(variantIn, variantOut, commandExecOpt)) { Marshal.GetNativeVariantForObject("mode", variantOut); return(VSConstants.S_OK); } var name = GetStringArgument(variantIn) ?? ""; if (!Enum.TryParse(name, out ModeKind mode)) { PrintToCommandWindow($"Invalid mode name: {name}"); var all = string.Join(", ", Enum.GetNames(typeof(ModeKind))); PrintToCommandWindow($"Valid names: {all}"); return(VSConstants.E_INVALIDARG); } if (!_vsAdapter.TryGetActiveTextView(out IWpfTextView activeTextView)) { PrintToCommandWindow("Could not detect an active vim buffer"); return(VSConstants.E_FAIL); } if (!_vim.TryGetVimBuffer(activeTextView, out IVimBuffer vimBuffer)) { PrintToCommandWindow("Active view isn't a vim buffer"); return(VSConstants.E_FAIL); } vimBuffer.SwitchMode(mode, ModeArgument.None); return(VSConstants.S_OK); }
/// <summary> /// Raised when an IVsTextView is created. When this occurs it means a previously created /// ITextView was associated with an IVsTextView shim. This means the ITextView will be /// hooked into the Visual Studio command system and a host of other items. Setup all of /// our plumbing here /// </summary> void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView) { // Get the ITextView created. Shouldn't ever be null unless a non-standard Visual Studio // component is calling this function var textView = _adaptersFactory.GetWpfTextViewNoThrow(vsView); if (textView == null) { return; } if (!_vim.TryGetVimBuffer(textView, out IVimBuffer vimBuffer)) { return; } // At this point Visual Studio has fully applied it's settings. Begin the synchronization process BeginSettingSynchronization(vimBuffer); var contentType = textView.TextBuffer.ContentType; if (contentType.IsJavaScript() || contentType.IsResJSON() || contentType.IsHTMLXProjection()) { ConnectToOleCommandTargetDelayed(vimBuffer, textView, vsView); } else { ConnectToOleCommandTarget(vimBuffer, textView, vsView); } }
private void OnGotFocus(object sender, EventArgs e) { if (sender is IWpfTextView textView) { if (_vim.TryGetVimBuffer(textView, out IVimBuffer vimBuffer)) { OnInputModeRelatedEvent(vimBuffer); } } }
internal void ClearSelection(ITextView textView) { // Move the caret to the beginning of the selection. var startPoint = textView.Selection.Start; textView.Selection.Clear(); textView.Caret.MoveTo(startPoint); if (_vim.TryGetVimBuffer(textView, out var vimBuffer)) { vimBuffer.SwitchMode(ModeKind.Normal, ModeArgument.None); } }
/// <summary> /// Raised when an IVsTextView is created. When this occurs it means a previously created /// ITextView was associated with an IVsTextView shim. This means the ITextView will be /// hooked into the Visual Studio command system and a host of other items. Setup all of /// our plumbing here /// </summary> void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView) { // Get the ITextView created. Shouldn't ever be null unless a non-standard Visual Studio // component is calling this function var textView = _adaptersFactory.GetWpfTextViewNoThrow(vsView); if (textView == null) { return; } IVimBuffer vimBuffer; if (!_vim.TryGetVimBuffer(textView, out vimBuffer)) { return; } // At this point Visual Studio has fully applied it's settings. Begin the synchronization process BeginSettingSynchronization(vimBuffer); var broker = _displayWindowBrokerFactoryServcie.CreateDisplayWindowBroker(textView); var bufferCoordinator = _bufferCoordinatorFactory.GetVimBufferCoordinator(vimBuffer); var result = VsCommandTarget.Create(bufferCoordinator, vsView, _textManager, _adapter, broker, _resharperUtil, _keyUtil); if (result.IsSuccess) { // Store the value for debugging _vimBufferToCommandTargetMap[vimBuffer] = result.Value; } // Try and install the IVsFilterKeys adapter. This cannot be done synchronously here // because Venus projects are not fully initialized at this state. Merely querying // for properties cause them to corrupt internal state and prevents rendering of the // view. Occurs for aspx and .js pages Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, vimBuffer); _protectedOperations.BeginInvoke(install); }