Skip to content

Commit 11fae2d

Browse files
committed
Merge branch 'next' into AttributableContexts
2 parents 0264186 + 18a007a commit 11fae2d

39 files changed

+1930
-253
lines changed

Rubberduck.Core/AutoComplete/AutoCompleteBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Rubberduck.AutoComplete
1111
{
12+
1213
public abstract class AutoCompleteBase : IAutoComplete
1314
{
1415
protected AutoCompleteBase(string inputToken, string outputToken)
@@ -67,7 +68,7 @@ public virtual bool Execute(AutoCompleteEventArgs e, AutoCompleteSettings settin
6768
else if (input == OutputToken && nextChar == OutputToken)
6869
{
6970
// just move caret one character to the right & suppress the keypress
70-
pane.Selection = new Selection(pSelection.StartLine, pSelection.StartColumn + 2);
71+
pane.Selection = new Selection(pSelection.StartLine, GetPrettifiedCaretPosition(pSelection, original, original) + 1);
7172
e.Handled = true;
7273
return true;
7374
}

Rubberduck.Core/AutoComplete/AutoCompleteBlockBase.cs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Rubberduck.AutoComplete
1515
{
16+
1617
public abstract class AutoCompleteBlockBase : AutoCompleteBase
1718
{
1819
/// <param name="indenterSettings">Used for auto-indenting blocks as per indenter settings.</param>
@@ -24,6 +25,8 @@ protected AutoCompleteBlockBase(IConfigProvider<IndenterSettings> indenterSettin
2425
IndenterSettings = indenterSettings;
2526
}
2627

28+
public bool IsCapturing { get; set; }
29+
2730
protected virtual bool FindInputTokenAtBeginningOfCurrentLine => false;
2831
protected virtual bool SkipPreCompilerDirective => true;
2932

@@ -42,43 +45,45 @@ public override bool Execute(AutoCompleteEventArgs e, AutoCompleteSettings setti
4245
{
4346
return false;
4447
}
45-
46-
var module = e.CodeModule;
47-
using (var pane = module.CodePane)
48-
{
49-
var selection = pane.Selection;
50-
var originalCode = module.GetLines(selection);
51-
var code = originalCode.Trim().StripStringLiterals();
52-
var hasComment = code.HasComment(out int commentStart);
53-
54-
var isDeclareStatement = Regex.IsMatch(code, $"\\b{Tokens.Declare}\\b", RegexOptions.IgnoreCase);
55-
var isExitStatement = Regex.IsMatch(code, $"\\b{Tokens.Exit}\\b", RegexOptions.IgnoreCase);
56-
var isNamedArg = Regex.IsMatch(code, $"\\b{InputToken}\\:\\=", RegexOptions.IgnoreCase);
5748

58-
if ((SkipPreCompilerDirective && code.StartsWith("#"))
59-
|| isDeclareStatement || isExitStatement || isNamedArg)
49+
{
50+
var module = e.CodeModule;
51+
using (var pane = module.CodePane)
6052
{
53+
var selection = pane.Selection;
54+
var originalCode = module.GetLines(selection);
55+
var code = originalCode.Trim().StripStringLiterals();
56+
var hasComment = code.HasComment(out int commentStart);
57+
58+
var isDeclareStatement = Regex.IsMatch(code, $"\\b{Tokens.Declare}\\b", RegexOptions.IgnoreCase);
59+
var isExitStatement = Regex.IsMatch(code, $"\\b{Tokens.Exit}\\b", RegexOptions.IgnoreCase);
60+
var isNamedArg = Regex.IsMatch(code, $"\\b{InputToken}\\:\\=", RegexOptions.IgnoreCase);
61+
62+
if ((SkipPreCompilerDirective && code.StartsWith("#"))
63+
|| isDeclareStatement || isExitStatement || isNamedArg)
64+
{
65+
return false;
66+
}
67+
68+
if (IsMatch(code) && !IsBlockCompleted(module, selection))
69+
{
70+
var indent = originalCode.TakeWhile(c => char.IsWhiteSpace(c)).Count();
71+
var newCode = OutputToken.PadLeft(OutputToken.Length + indent, ' ');
72+
73+
var stdIndent = IndentBody
74+
? IndenterSettings.Create().IndentSpaces
75+
: 0;
76+
77+
module.InsertLines(selection.NextLine.StartLine, "\n" + newCode);
78+
79+
module.ReplaceLine(selection.NextLine.StartLine, new string(' ', indent + stdIndent));
80+
pane.Selection = new Selection(selection.NextLine.StartLine, indent + stdIndent + 1);
81+
82+
e.Handled = true;
83+
return true;
84+
}
6185
return false;
6286
}
63-
64-
if (IsMatch(code) && !IsBlockCompleted(module, selection))
65-
{
66-
var indent = originalCode.TakeWhile(c => char.IsWhiteSpace(c)).Count();
67-
var newCode = OutputToken.PadLeft(OutputToken.Length + indent, ' ');
68-
69-
var stdIndent = IndentBody
70-
? IndenterSettings.Create().IndentSpaces
71-
: 0;
72-
73-
module.InsertLines(selection.NextLine.StartLine, "\n" + newCode);
74-
75-
module.ReplaceLine(selection.NextLine.StartLine, new string(' ', indent + stdIndent));
76-
pane.Selection = new Selection(selection.NextLine.StartLine, indent + stdIndent + 1);
77-
78-
e.Handled = true;
79-
return true;
80-
}
81-
return false;
8287
}
8388
}
8489

@@ -104,7 +109,7 @@ public override bool IsMatch(string code)
104109
return regexOk && (!hasComment || code.IndexOf(InputToken) < commentIndex);
105110
}
106111

107-
private bool IsBlockCompleted(ICodeModule module, Selection selection)
112+
protected bool IsBlockCompleted(ICodeModule module, Selection selection)
108113
{
109114
string content;
110115
var proc = module.GetProcOfLine(selection.StartLine);

Rubberduck.Core/AutoComplete/AutoCompleteIfBlock.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
using Rubberduck.Parsing.Grammar;
2+
using Rubberduck.Parsing.VBA;
3+
using Rubberduck.Settings;
24
using Rubberduck.SettingsProvider;
35
using Rubberduck.SmartIndenter;
6+
using Rubberduck.VBEditor;
7+
using Rubberduck.VBEditor.Events;
8+
using System.Linq;
9+
using System.Text.RegularExpressions;
10+
using System.Windows.Forms;
411

512
namespace Rubberduck.AutoComplete
613
{
714
public class AutoCompleteIfBlock : AutoCompleteBlockBase
815
{
916
public AutoCompleteIfBlock(IConfigProvider<IndenterSettings> indenterSettings)
10-
: base(indenterSettings, $"{Tokens.Then}", $"{Tokens.End} {Tokens.If}") { }
17+
: base(indenterSettings, $"{Tokens.If}", $"{Tokens.End} {Tokens.If}") { }
1118

1219
// matching "If" would trigger erroneous block completion on inline if..then..else syntax.
1320
protected override bool MatchInputTokenAtEndOfLineOnly => true;

0 commit comments

Comments
 (0)