Skip to content

Commit

Permalink
Merge pull request #4569 from retailcoder/bugfix
Browse files Browse the repository at this point in the history
SCP Fix
  • Loading branch information
retailcoder committed Nov 30, 2018
2 parents 0bda237 + b524fb7 commit d5b900d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions Rubberduck.Core/AppMenu.cs
Expand Up @@ -38,6 +38,7 @@ public void Initialize()
{
menu.Initialize();
}
EvaluateCanExecute(_parser.State);
}

public void OnSelectedDeclarationChange(object sender, DeclarationChangedEventArgs e)
Expand Down
25 changes: 16 additions & 9 deletions Rubberduck.Core/AutoComplete/Service/SelfClosingPairHandler.cs
Expand Up @@ -66,11 +66,11 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
break;
}
}
}

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

var snippetPosition = new Selection(result.SnippetPosition.StartLine, 1, result.SnippetPosition.EndLine, 1);
Expand Down Expand Up @@ -109,21 +109,28 @@ private bool HandleInternal(AutoCompleteEventArgs e, CodeString original, SelfCl
return false;
}

result = CodePaneHandler.Prettify(e.Module, result);
var reprettified = CodePaneHandler.Prettify(e.Module, result);
if (pair.OpeningChar == '(' && e.Character == pair.OpeningChar && !reprettified.Equals(result))
{
// VBE eats it. bail out but don't swallow the keypress.
e.Handled = false;
result = null;
return false;
}

var currentLine = result.Lines[result.CaretPosition.StartLine];
var currentLine = reprettified.Lines[reprettified.CaretPosition.StartLine];
if (!string.IsNullOrWhiteSpace(currentLine) &&
currentLine.EndsWith(" ") &&
result.CaretPosition.StartColumn == currentLine.Length)
reprettified.CaretPosition.StartColumn == currentLine.Length)
{
result = result.ReplaceLine(result.CaretPosition.StartLine, currentLine.TrimEnd());
result = reprettified.ReplaceLine(reprettified.CaretPosition.StartLine, currentLine.TrimEnd());
}

if (pair.OpeningChar == '(' &&
e.Character == pair.OpeningChar &&
!result.CaretLine.EndsWith($"{pair.OpeningChar}{pair.ClosingChar}"))
{
// VBE eats it. bail out but still swallow the keypress, since we've already re-prettified.
// VBE eats it. bail out but still swallow the keypress.
e.Handled = true;
result = null;
return false;
Expand Down
11 changes: 11 additions & 0 deletions RubberduckTests/AutoComplete/SelfClosingPairHandlerTests.cs
Expand Up @@ -103,6 +103,17 @@ public void GivenOpeningParenthesisOnOtherwiseNonEmptyLine_ReturnsFalseAndSwallo
Assert.IsTrue(info.Args.Handled);
}

[Test]
public void GivenOpeningParenthesisOnCallStatement_ReturnsFalseAndLetsKeypressThrough()
{
var input = '(';
var original = "Call DoSomething|".ToCodeString();
var rePrettified = "Call DoSomething|".ToCodeString();
var info = new SelfClosingPairTestInfo(original, input, rePrettified);

Assert.IsFalse(Run(info));
Assert.IsFalse(info.Args.Handled);
}
[Test]
public void GivenBackspaceOnMatchedPair_DeletesMatchingTokens()
{
Expand Down

0 comments on commit d5b900d

Please sign in to comment.