Example #1
0
        /// <summary>
        /// Try and install the IVsFilterKeys adapter for the given ITextView.
        /// </summary>
        internal static bool TryInstallFilterKeysAdapter(
            IVsAdapter adapter,
            IVimBuffer buffer)
        {
            var textView = buffer.TextView;

            if (textView.Properties.ContainsProperty(s_key))
            {
                return(true);
            }

            var textLines = adapter.EditorAdapter.GetBufferAdapter(buffer.TextBuffer) as IVsTextLines;

            if (textLines == null)
            {
                return(false);
            }

            IVsCodeWindow codeWindow;

            if (!adapter.GetCodeWindow(textView).TryGetValue(out codeWindow))
            {
                return(false);
            }

            // Grab the field we need to replace.  Be wary that Venus uses a different implementation
            // and the field will not be available
            var type  = codeWindow.GetType();
            var flags = System.Reflection.BindingFlags.Instance
                        | System.Reflection.BindingFlags.NonPublic;
            var field = type.GetField(FieldName, flags);

            if (field == null)
            {
                return(false);
            }

            var oldValue = field.GetValue(codeWindow) as IVsFilterKeys;

            if (oldValue == null)
            {
                return(false);
            }

            var filterKeysAdapter = new VsFilterKeysAdapter(oldValue, codeWindow, adapter, buffer);

            field.SetValue(codeWindow, filterKeysAdapter);
            return(true);
        }
Example #2
0
        private void ConnectToOleCommandTarget(IVimBuffer vimBuffer, ITextView textView, IVsTextView vsTextView)
        {
            var broker = _displayWindowBrokerFactoryServcie.GetDisplayWindowBroker(textView);
            var vimBufferCoordinator = _bufferCoordinatorFactory.GetVimBufferCoordinator(vimBuffer);
            var result = VsCommandTarget.Create(vimBufferCoordinator, vsTextView, _textManager, _adapter, broker, _keyUtil, _vimApplicationSettings, _commandTargetFactoryList);

            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
            void install() => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, vimBuffer);

            _protectedOperations.BeginInvoke(install);
        }
Example #3
0
        /// <summary>
        /// Try and install the IVsFilterKeys adapter for the given ITextView.
        /// </summary>
        internal static bool TryInstallFilterKeysAdapter(
            IVsAdapter adapter,
            IVimBuffer buffer)
        {
            var textView = buffer.TextView;
            if (textView.Properties.ContainsProperty(s_key))
            {
                return true;
            }

            var textLines = adapter.EditorAdapter.GetBufferAdapter(buffer.TextBuffer) as IVsTextLines;
            if (textLines == null)
            {
                return false;
            }

            IVsCodeWindow codeWindow;
            if (!adapter.GetCodeWindow(textView).TryGetValue(out codeWindow))
            {
                return false;
            }

            // Grab the field we need to replace.  Be wary that Venus uses a different implementation
            // and the field will not be available 
            var type = codeWindow.GetType();
            var flags = System.Reflection.BindingFlags.Instance
                | System.Reflection.BindingFlags.NonPublic;
            var field = type.GetField(FieldName, flags);
            if (field == null)
            {
                return false;
            }

            var oldValue = field.GetValue(codeWindow) as IVsFilterKeys;
            if (oldValue == null)
            {
                return false;
            }

            var filterKeysAdapter = new VsFilterKeysAdapter(oldValue, codeWindow, adapter, buffer);
            field.SetValue(codeWindow, filterKeysAdapter);
            return true;
        }