@@ -30,6 +30,8 @@ public void IndentCurrentProcedure()
30
30
return ;
31
31
}
32
32
33
+ var initialSelection = GetSelection ( pane ) . Collapse ( ) ;
34
+
33
35
using ( var module = pane . CodeModule )
34
36
{
35
37
var selection = GetSelection ( pane ) ;
@@ -49,8 +51,9 @@ public void IndentCurrentProcedure()
49
51
using ( var component = module . Parent )
50
52
{
51
53
Indent ( component , selection , true ) ;
52
- }
54
+ }
53
55
}
56
+ ResetSelection ( pane , initialSelection ) ;
54
57
}
55
58
}
56
59
@@ -66,13 +69,17 @@ public void IndentCurrentModule()
66
69
return ;
67
70
}
68
71
72
+ var initialSelection = GetSelection ( pane ) . Collapse ( ) ;
73
+
69
74
using ( var module = pane . CodeModule )
70
75
{
71
76
using ( var component = module . Parent )
72
77
{
73
78
Indent ( component ) ;
74
- }
75
- }
79
+ }
80
+ }
81
+
82
+ ResetSelection ( pane , initialSelection ) ;
76
83
}
77
84
}
78
85
@@ -81,14 +88,47 @@ public void IndentCurrentModule()
81
88
/// </summary>
82
89
public void IndentCurrentProject ( )
83
90
{
84
- var project = _vbe . ActiveVBProject ;
85
- if ( project . Protection == ProjectProtection . Locked )
91
+ using ( var pane = _vbe . ActiveCodePane )
92
+ {
93
+ var initialSelection = pane == null || pane . IsWrappingNullReference ? default : GetSelection ( pane ) . Collapse ( ) ;
94
+
95
+ var project = _vbe . ActiveVBProject ;
96
+ if ( project . Protection == ProjectProtection . Locked )
97
+ {
98
+ return ;
99
+ }
100
+
101
+ foreach ( var component in project . VBComponents )
102
+ {
103
+ Indent ( component ) ;
104
+ }
105
+
106
+ ResetSelection ( pane , initialSelection ) ;
107
+ }
108
+ }
109
+
110
+ private void ResetSelection ( ICodePane codePane , Selection initialSelection )
111
+ {
112
+ using ( var window = _vbe . ActiveWindow )
86
113
{
87
- return ;
114
+ if ( initialSelection == default || codePane == null || window == null ||
115
+ window . IsWrappingNullReference || window . Type != WindowKind . CodeWindow ||
116
+ codePane . IsWrappingNullReference )
117
+ {
118
+ return ;
119
+ }
88
120
}
89
- foreach ( var component in project . VBComponents )
121
+
122
+ using ( var module = codePane . CodeModule )
90
123
{
91
- Indent ( component ) ;
124
+ // This will only "ballpark it" for now - it sets the absolute line in the module, not necessarily
125
+ // the specific LoC. That will be a TODO when the parse tree is used to indent. For the time being,
126
+ // maintaining that is ridiculously difficult vis-a-vis the payoff if the vertical spacing is
127
+ // changed.
128
+ var lines = module . CountOfLines ;
129
+ codePane . Selection = lines < initialSelection . StartLine
130
+ ? new Selection ( lines , initialSelection . StartColumn , lines , initialSelection . StartColumn )
131
+ : initialSelection ;
92
132
}
93
133
}
94
134
0 commit comments