13
13
14
14
namespace Rubberduck . AutoComplete
15
15
{
16
+
16
17
public abstract class AutoCompleteBlockBase : AutoCompleteBase
17
18
{
18
19
/// <param name="indenterSettings">Used for auto-indenting blocks as per indenter settings.</param>
@@ -24,6 +25,8 @@ protected AutoCompleteBlockBase(IConfigProvider<IndenterSettings> indenterSettin
24
25
IndenterSettings = indenterSettings ;
25
26
}
26
27
28
+ public bool IsCapturing { get ; set ; }
29
+
27
30
protected virtual bool FindInputTokenAtBeginningOfCurrentLine => false ;
28
31
protected virtual bool SkipPreCompilerDirective => true ;
29
32
@@ -42,43 +45,45 @@ public override bool Execute(AutoCompleteEventArgs e, AutoCompleteSettings setti
42
45
{
43
46
return false ;
44
47
}
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 ) ;
57
48
58
- if ( ( SkipPreCompilerDirective && code . StartsWith ( "#" ) )
59
- || isDeclareStatement || isExitStatement || isNamedArg )
49
+ {
50
+ var module = e . CodeModule ;
51
+ using ( var pane = module . CodePane )
60
52
{
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
+ }
61
85
return false ;
62
86
}
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 ;
82
87
}
83
88
}
84
89
@@ -104,7 +109,7 @@ public override bool IsMatch(string code)
104
109
return regexOk && ( ! hasComment || code . IndexOf ( InputToken ) < commentIndex ) ;
105
110
}
106
111
107
- private bool IsBlockCompleted ( ICodeModule module , Selection selection )
112
+ protected bool IsBlockCompleted ( ICodeModule module , Selection selection )
108
113
{
109
114
string content ;
110
115
var proc = module . GetProcOfLine ( selection . StartLine ) ;
0 commit comments