Skip to content

Commit 7e5b4cb

Browse files
committed
removed redundant ctor param, fixed inline-if behavior
1 parent a91098d commit 7e5b4cb

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Rubberduck.Core/AutoComplete/AutoCompleteBlockBase.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,21 @@ public abstract class AutoCompleteBlockBase : AutoCompleteBase
1212
/// <param name="indenterSettings">Used for auto-indenting blocks as per indenter settings.</param>
1313
/// <param name="inputToken">The token that starts the block, i.e. what to detect.</param>
1414
/// <param name="outputToken">The token that closes the block, i.e. what to insert.</param>
15-
/// <param name="committedOnly">Indicates whether line of code was committed, i.e. selection is on the line underneath the code string.</param>
16-
protected AutoCompleteBlockBase(IVBETypeLibsAPI api, IIndenterSettings indenterSettings, string inputToken, string outputToken, bool committedOnly = true)
15+
protected AutoCompleteBlockBase(IVBETypeLibsAPI api, IIndenterSettings indenterSettings, string inputToken, string outputToken)
1716
:base(inputToken, outputToken)
1817
{
1918
_api = api;
2019
_indenterSettings = indenterSettings;
21-
_committedOnly = committedOnly;
2220
}
2321

2422
protected virtual bool FindInputTokenAtBeginningOfCurrentLine => false;
2523

2624
private readonly IVBETypeLibsAPI _api;
2725
private readonly IIndenterSettings _indenterSettings;
28-
private readonly bool _committedOnly;
2926

3027
protected virtual bool ExecuteOnCommittedInputOnly => true;
3128
protected virtual bool MatchInputTokenAtEndOfLineOnly => false;
3229

33-
private string _pattern => MatchInputTokenAtEndOfLineOnly
34-
? $"\\b{InputToken}\\r\\n$"
35-
: $"\\b{InputToken}\\b";
36-
3730
private bool _executing;
3831
public override bool Execute(AutoCompleteEventArgs e)
3932
{
@@ -45,7 +38,11 @@ public override bool Execute(AutoCompleteEventArgs e)
4538
var selection = e.CodePane.Selection;
4639
var stdIndent = _indenterSettings.IndentSpaces;
4740

48-
if ((!_committedOnly || e.IsCommitted) && Regex.IsMatch(e.OldCode.Trim(), _pattern))
41+
var isMatch = MatchInputTokenAtEndOfLineOnly
42+
? e.OldCode.EndsWith(InputToken)
43+
: Regex.IsMatch(e.OldCode.Trim(), $"\\b{InputToken}\\b");
44+
45+
if (isMatch && (!ExecuteOnCommittedInputOnly || e.IsCommitted))
4946
{
5047
var indent = e.OldCode.TakeWhile(c => char.IsWhiteSpace(c)).Count();
5148
using (var module = e.CodePane.CodeModule)
@@ -54,6 +51,7 @@ public override bool Execute(AutoCompleteEventArgs e)
5451
var code = OutputToken.PadLeft(OutputToken.Length + indent, ' ');
5552
if (module.GetLines(selection.NextLine) == code)
5653
{
54+
_executing = false;
5755
return false;
5856
}
5957

Rubberduck.Core/AutoComplete/AutoCompleteIfBlock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Rubberduck.Parsing.Grammar;
22
using Rubberduck.SmartIndenter;
33
using Rubberduck.VBEditor.ComManagement.TypeLibsAPI;
4+
using Rubberduck.VBEditor.Events;
45

56
namespace Rubberduck.AutoComplete
67
{

Rubberduck.Core/AutoComplete/AutoCompleteOnErrorResumeNextBlock.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Rubberduck.AutoComplete
77
public class AutoCompleteOnErrorResumeNextBlock : AutoCompleteBlockBase
88
{
99
public AutoCompleteOnErrorResumeNextBlock(IVBETypeLibsAPI api, IIndenterSettings indenterSettings)
10-
: base(api, indenterSettings, $"{Tokens.On} {Tokens.Error} {Tokens.Resume} {Tokens.Next}", $"{Tokens.On} {Tokens.Error} {Tokens.GoTo} 0", false) { }
10+
: base(api, indenterSettings, $"{Tokens.On} {Tokens.Error} {Tokens.Resume} {Tokens.Next}", $"{Tokens.On} {Tokens.Error} {Tokens.GoTo} 0") { }
11+
12+
protected override bool ExecuteOnCommittedInputOnly => false;
1113
}
1214
}

0 commit comments

Comments
 (0)