Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed the bug where VsVim interferred with user automation functions

  • Loading branch information...
commit df0b6e6c1c95ff53acc14cbd5ad3cf5ccca05cd0 1 parent 444d735
Jared Parsons authored
2  VsVim/HostFactory.cs
View
@@ -100,7 +100,7 @@ void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
}
var buffer = opt.Value;
- var filter = new VsCommandFilter(buffer, vsView);
+ var filter = new VsCommandFilter(buffer, vsView, _serviceProvider);
_filterMap.Add(buffer, filter);
}
}
16 VsVim/VsCommandFilter.cs
View
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
-using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Text.Editor;
@@ -9,6 +8,9 @@
using System.Windows.Input;
using Microsoft.FSharp.Core;
using Vim;
+using Microsoft.VisualStudio.OLE.Interop;
+using IServiceProvider = System.IServiceProvider;
+using Microsoft.VisualStudio.Shell;
namespace VsVim
{
@@ -22,17 +24,27 @@ internal sealed class VsCommandFilter : IOleCommandTarget
private readonly IVimBuffer _buffer;
private readonly IVsTextView _textView;
private readonly IOleCommandTarget _nextTarget;
+ private readonly IServiceProvider _serviceProvider;
- internal VsCommandFilter(IVimBuffer buffer, IVsTextView view)
+ internal VsCommandFilter(IVimBuffer buffer, IVsTextView view, IServiceProvider provider)
{
_buffer = buffer;
_textView = view;
+ _serviceProvider = provider;
var hr = view.AddCommandFilter(this, out _nextTarget);
}
internal bool TryConvert(Guid commandGroup, uint commandId, IntPtr pvaIn, out KeyInput kiOutput)
{
kiOutput = null;
+
+ // Don't ever process a command when we are in an automation function. Doing so will cause VsVim to
+ // intercept items like running Macros and certain wizard functionality
+ if (VsShellUtilities.IsInAutomationFunction(_serviceProvider))
+ {
+ return false;
+ }
+
EditCommand command;
if (!CommandUtil.TryConvert(commandGroup, commandId, pvaIn, out command))
{
72 VsVimTest/VsCommandFilterTest.cs
View
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Vim;
+using Moq;
+using Microsoft.VisualStudio.TextManager.Interop;
+using Microsoft.VisualStudio;
+using VsVim;
+using EnvDTE;
+
+namespace VsVimTest
+{
+ [TestFixture]
+ public class VsCommandFilterTest
+ {
+ private Mock<IVimBuffer> _buffer;
+ private Mock<IVsTextView> _textView;
+ private Mock<IServiceProvider> _serviceProvider;
+ private Mock<IVsExtensibility> _vsExt;
+ private VsCommandFilter _filter;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _buffer = new Mock<IVimBuffer>();
+ _textView = new Mock<IVsTextView>();
+ _vsExt = new Mock<IVsExtensibility>(MockBehavior.Strict);
+ _vsExt.Setup(x => x.IsInAutomationFunction()).Returns(0);
+ _serviceProvider = MockObjectFactory.CreateServiceProvider(Tuple.Create(typeof(IVsExtensibility), (object)_vsExt.Object));
+ _filter = new VsCommandFilter(_buffer.Object, _textView.Object, _serviceProvider.Object);
+ }
+
+ private void AssertCannotConvert2K(VSConstants.VSStd2KCmdID id)
+ {
+ KeyInput ki;
+ Assert.IsFalse(_filter.TryConvert(VSConstants.VSStd2K, (uint)id, IntPtr.Zero, out ki));
+ }
+
+ private void AssertCanConvert2K(VSConstants.VSStd2KCmdID id, KeyInput expected)
+ {
+ KeyInput ki;
+ Assert.IsTrue(_filter.TryConvert(VSConstants.VSStd2K, (uint)id, IntPtr.Zero, out ki));
+ Assert.AreEqual(expected,ki);
+ }
+
+ [Test]
+ public void TryConvert1()
+ {
+ _buffer.Setup(x => x.CanProcessInput(It.IsAny<KeyInput>())).Returns(true);
+ AssertCanConvert2K(VSConstants.VSStd2KCmdID.TAB, InputUtil.VimKeyToKeyInput(VimKey.TabKey));
+ }
+
+ [Test]
+ public void TryConvert2()
+ {
+ _buffer.Setup(x => x.CanProcessInput(It.IsAny<KeyInput>())).Returns(false);
+ AssertCannotConvert2K(VSConstants.VSStd2KCmdID.TAB);
+ }
+
+ [Test, Description("Don't convert keys when in automation")]
+ public void TryConvert3()
+ {
+ _vsExt.Setup(x => x.IsInAutomationFunction()).Returns(1);
+ _buffer.Setup(x => x.CanProcessInput(It.IsAny<KeyInput>())).Returns(true);
+ AssertCannotConvert2K(VSConstants.VSStd2KCmdID.TAB);
+ }
+
+
+ }
+}
1  VsVimTest/VsVimTest.csproj
View
@@ -143,6 +143,7 @@
<DependentUpon>TestResources.resx</DependentUpon>
</Compile>
<Compile Include="Utils\CharPointer.cs" />
+ <Compile Include="VsCommandFilterTest.cs" />
<Compile Include="VsVimHostTest.cs" />
</ItemGroup>
<ItemGroup>
Please sign in to comment.
Something went wrong with that request. Please try again.