Skip to content

Commit cf18f05

Browse files
authored
Merge pull request #1789 from comintern/next
Check window focus before executing hotkeys. Closes #1765
2 parents 2dc7fa7 + 5b98383 commit cf18f05

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public void Detach()
188188

189189
private void hook_MessageReceived(object sender, HookEventArgs e)
190190
{
191+
var active = User32.GetForegroundWindow();
192+
if (active != _mainWindowHandle)
193+
{
194+
return;
195+
}
196+
191197
var hotkey = sender as IHotkey;
192198
if (hotkey != null)
193199
{

RetailCoder.VBE/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,13 @@ public void RemoveChildren()
8686
{
8787
foreach (var child in _items.Keys.Select(item => item as IParentMenuItem).Where(child => child != null))
8888
{
89-
Debug.WriteLine("Deleting menu item {0}.", child.Caption);
9089
child.RemoveChildren();
9190
Debug.Assert(_items[child] is CommandBarPopup);
9291
(_items[child] as CommandBarPopup).Delete();
9392
}
9493
foreach (var child in _items.Values.Select(item => item as CommandBarButton).Where(child => child != null))
9594
{
9695
child.Click -= child_Click;
97-
Debug.WriteLine("Deleting child menu item {0}.", child.Caption);
9896
child.Delete();
9997
}
10098
}

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ internal class AbsoluteCodeLine
1919
private static readonly Regex ProcedureEndRegex = new Regex(@"^End\s(Sub|Function|Property)");
2020
private static readonly Regex TypeEnumStartRegex = new Regex(@"^(Public\s|Private\s)?(Enum\s|Type\s)");
2121
private static readonly Regex TypeEnumEndRegex = new Regex(@"^End\s(Enum|Type)");
22-
private static readonly Regex InProcedureInRegex = new Regex(@"^If\s.*\sThen|^ElseIf\s.+\sThen$|^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case");
23-
private static readonly Regex InProcedureOutRegex = new Regex(@"^(Else)?If\s.*\sThen\s|^Else$|^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select");
22+
private static readonly Regex InProcedureInRegex = new Regex(@"^(Else)?If\s.*\sThen|^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case");
23+
private static readonly Regex InProcedureOutRegex = new Regex(@"^If\s.*\sThen\s|^Else$|^ElseIf\s.*\sThen|^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select");
2424
private static readonly Regex DeclarationRegex = new Regex(@"^(Dim|Const|Static|Public|Private)\s.*\sAs\s");
2525
private static readonly Regex PrecompilerInRegex = new Regex(@"^#(Else)?If\s.+Then$|^#Else$");
26-
private static readonly Regex PrecompilerOutRegex = new Regex(@"^#ElseIf\s.+Then$|^#Else$|#End\sIf$");
26+
private static readonly Regex PrecompilerOutRegex = new Regex(@"^#ElseIf\s.+Then|^#Else$|#End\sIf$");
2727
private static readonly Regex SingleLineIfRegex = new Regex(@"^If\s.*\sThen\s.*$");
2828

2929
private readonly IIndenterSettings _settings;

RubberduckTests/SmartIndenter/MiscAndCornerCaseTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ public void SingleLineIfStatementWorks()
4848
Assert.IsTrue(expected.SequenceEqual(actual));
4949
}
5050

51+
[TestMethod]
52+
[TestCategory("Indenter")]
53+
public void ElseIfStatementWorks()
54+
{
55+
var code = new[]
56+
{
57+
"Public Function Test() As Integer",
58+
"If Foo = 1 Then",
59+
"Bar = 3",
60+
"ElseIf Foo = 3 Then",
61+
"Bar = 1",
62+
"End If",
63+
"Test = Bar",
64+
"End Function"
65+
};
66+
67+
var expected = new[]
68+
{
69+
"Public Function Test() As Integer",
70+
" If Foo = 1 Then",
71+
" Bar = 3",
72+
" ElseIf Foo = 3 Then",
73+
" Bar = 1",
74+
" End If",
75+
" Test = Bar",
76+
"End Function"
77+
};
78+
79+
var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
80+
var actual = indenter.Indent(code, string.Empty);
81+
Assert.IsTrue(expected.SequenceEqual(actual));
82+
}
83+
5184
[TestMethod]
5285
[TestCategory("Indenter")]
5386
public void SingleLineElseIfStatementWorks()

0 commit comments

Comments
 (0)