Skip to content

Commit 4789589

Browse files
committed
Replace modules\selections in one operation in the indenter to allow one-step VBE undo.
1 parent 572fcc7 commit 4789589

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Rubberduck.SmartIndenter/Indenter.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Configuration;
45
using Rubberduck.VBEditor;
56
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
67
using Rubberduck.VBEditor.SafeComWrappers.VBA;
@@ -71,13 +72,8 @@ public void Indent(IVBComponent component)
7172
var codeLines = module.GetLines(1, lineCount).Replace("\r", string.Empty).Split('\n');
7273
var indented = Indent(codeLines, component.Name).ToArray();
7374

74-
for (var i = 0; i < lineCount; i++)
75-
{
76-
if (module.GetLines(i + 1, 1) != indented[i])
77-
{
78-
component.CodeModule.ReplaceLine(i + 1, indented[i]);
79-
}
80-
}
75+
module.DeleteLines(1, lineCount);
76+
module.InsertLines(1, string.Join("\r\n", indented));
8177
}
8278

8379
public void Indent(IVBComponent component, string procedureName, Selection selection)
@@ -93,13 +89,8 @@ public void Indent(IVBComponent component, string procedureName, Selection selec
9389

9490
var indented = Indent(codeLines, procedureName).ToArray();
9591

96-
for (var i = 0; i < selection.EndLine - selection.StartLine; i++)
97-
{
98-
if (module.GetLines(selection.StartLine + i, 1) != indented[i])
99-
{
100-
component.CodeModule.ReplaceLine(selection.StartLine + i, indented[i]);
101-
}
102-
}
92+
module.DeleteLines(selection.StartLine, selection.LineCount);
93+
module.InsertLines(selection.StartLine, string.Join("\r\n", indented));
10394
}
10495

10596
private IEnumerable<LogicalCodeLine> BuildLogicalCodeLines(IEnumerable<string> lines)

0 commit comments

Comments
 (0)