Skip to content

Commit a2b52c8

Browse files
committed
replaced regex-rename with selection-based surgical replacements.
1 parent ee10f36 commit a2b52c8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

RetailCoder.VBE/Refactorings/Rename/RenamePresenter.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private void RenameControl()
276276
var module = handler.Project.VBComponents.Item(handler.ComponentName).CodeModule;
277277

278278
var content = module.Lines[handler.Selection.StartLine, 1];
279-
var newContent = GetReplacementLine(content, handler.IdentifierName, newMemberName, handler.Selection);
279+
var newContent = GetReplacementLine(content, newMemberName, handler.Selection);
280280
module.ReplaceLine(handler.Selection.StartLine, newContent);
281281
}
282282

@@ -308,7 +308,7 @@ private void RenameUsages(Declaration target, string interfaceName = null)
308308
var module = member.Project.VBComponents.Item(member.ComponentName).CodeModule;
309309

310310
var content = module.Lines[member.Selection.StartLine, 1];
311-
var newContent = GetReplacementLine(content, member.IdentifierName, newMemberName, member.Selection);
311+
var newContent = GetReplacementLine(content, newMemberName, member.Selection);
312312
module.ReplaceLine(member.Selection.StartLine, newContent);
313313
RenameUsages(member, target.ComponentName);
314314
}
@@ -334,12 +334,12 @@ private void RenameUsages(Declaration target, string interfaceName = null)
334334

335335
if (interfaceName == null)
336336
{
337-
newContent = GetReplacementLine(content, target.IdentifierName, _view.NewName,
337+
newContent = GetReplacementLine(content, _view.NewName,
338338
reference.Selection);
339339
}
340340
else
341341
{
342-
newContent = GetReplacementLine(content, target.IdentifierName,
342+
newContent = GetReplacementLine(content,
343343
interfaceName + "_" + _view.NewName,
344344
reference.Selection);
345345
}
@@ -363,22 +363,17 @@ private void RenameUsages(Declaration target, string interfaceName = null)
363363
}
364364

365365
var content = module.Lines[method.Selection.StartLine, 1];
366-
var newContent = GetReplacementLine(content, oldMemberName, newMemberName, member.Selection);
366+
var newContent = GetReplacementLine(content, newMemberName, member.Selection);
367367
module.ReplaceLine(method.Selection.StartLine, newContent);
368368
}
369369
}
370370
}
371371
}
372372

373-
private string GetReplacementLine(string content, string target, string newName, Selection selection)
373+
private string GetReplacementLine(string content, string newName, Selection selection)
374374
{
375-
// until we figure out how to replace actual tokens,
376-
// this is going to have to be done the ugly way...
377-
378-
// todo: come back after the identifier references are fixed
379-
//var contentWithoutOldName = content.Remove(selection.StartColumn - 1, selection.EndColumn - selection.StartColumn);
380-
//return contentWithoutOldName.Insert(selection.StartColumn - 1, newName);
381-
return Regex.Replace(content, "\\b" + target + "\\b", newName);
375+
var contentWithoutOldName = content.Remove(selection.StartColumn - 1, selection.EndColumn - selection.StartColumn);
376+
return contentWithoutOldName.Insert(selection.StartColumn - 1, newName);
382377
}
383378

384379
private string GetReplacementLine(CodeModule module, Declaration target, string newName)
@@ -459,7 +454,7 @@ private string GetReplacementLine(CodeModule module, Declaration target, string
459454

460455
return rewriter.GetText(new Interval(firstTokenIndex, lastTokenIndex));
461456
}
462-
return GetReplacementLine(content, target.IdentifierName, newName, target.Selection);
457+
return GetReplacementLine(content, newName, target.Selection);
463458
}
464459

465460
private static readonly DeclarationType[] ProcedureDeclarationTypes =

0 commit comments

Comments
 (0)