@@ -247,7 +247,7 @@ private void RenameControl()
247247 var module = handler . Project . VBComponents . Item ( handler . ComponentName ) . CodeModule ;
248248
249249 var content = module . Lines [ handler . Selection . StartLine , 1 ] ;
250- var newContent = GetReplacementLine ( content , handler . IdentifierName , newMemberName ) ;
250+ var newContent = GetReplacementLine ( content , handler . IdentifierName , newMemberName , handler . Selection ) ;
251251 module . ReplaceLine ( handler . Selection . StartLine , newContent ) ;
252252 }
253253
@@ -279,7 +279,7 @@ private void RenameUsages(Declaration target, string interfaceName = null)
279279 var module = member . Project . VBComponents . Item ( member . ComponentName ) . CodeModule ;
280280
281281 var content = module . Lines [ member . Selection . StartLine , 1 ] ;
282- var newContent = GetReplacementLine ( content , member . IdentifierName , newMemberName ) ;
282+ var newContent = GetReplacementLine ( content , member . IdentifierName , newMemberName , member . Selection ) ;
283283 module . ReplaceLine ( member . Selection . StartLine , newContent ) ;
284284 RenameUsages ( member , target . ComponentName ) ;
285285 }
@@ -298,19 +298,25 @@ private void RenameUsages(Declaration target, string interfaceName = null)
298298 var module = grouping . Key . Component . CodeModule ;
299299 foreach ( var line in grouping . GroupBy ( reference => reference . Selection . StartLine ) )
300300 {
301- var content = module . Lines [ line . Key , 1 ] ;
302- string newContent ;
303-
304- if ( interfaceName == null )
305- {
306- newContent = GetReplacementLine ( content , target . IdentifierName , _view . NewName ) ;
307- }
308- else
301+ foreach ( var reference in line )
309302 {
310- newContent = GetReplacementLine ( content , target . IdentifierName , interfaceName + "_" + _view . NewName ) ;
311- }
303+ var content = module . Lines [ line . Key , 1 ] ;
304+ string newContent ;
305+
306+ if ( interfaceName == null )
307+ {
308+ newContent = GetReplacementLine ( content , target . IdentifierName , _view . NewName ,
309+ reference . Selection ) ;
310+ }
311+ else
312+ {
313+ newContent = GetReplacementLine ( content , target . IdentifierName ,
314+ interfaceName + "_" + _view . NewName ,
315+ reference . Selection ) ;
316+ }
312317
313- module . ReplaceLine ( line . Key , newContent ) ;
318+ module . ReplaceLine ( line . Key , newContent ) ;
319+ }
314320 }
315321
316322 // renaming interface
@@ -328,17 +334,21 @@ private void RenameUsages(Declaration target, string interfaceName = null)
328334 }
329335
330336 var content = module . Lines [ method . Selection . StartLine , 1 ] ;
331- var newContent = GetReplacementLine ( content , oldMemberName , newMemberName ) ;
337+ var newContent = GetReplacementLine ( content , oldMemberName , newMemberName , member . Selection ) ;
332338 module . ReplaceLine ( method . Selection . StartLine , newContent ) ;
333339 }
334340 }
335341 }
336342 }
337343
338- private string GetReplacementLine ( string content , string target , string newName )
344+ private string GetReplacementLine ( string content , string target , string newName , Selection selection )
339345 {
340346 // until we figure out how to replace actual tokens,
341347 // this is going to have to be done the ugly way...
348+
349+ // todo: come back after the identifier references are fixed
350+ //var contentWithoutOldName = content.Remove(selection.StartColumn - 1, selection.EndColumn - selection.StartColumn);
351+ //return contentWithoutOldName.Insert(selection.StartColumn - 1, newName);
342352 return Regex . Replace ( content , "\\ b" + target + "\\ b" , newName ) ;
343353 }
344354
@@ -420,7 +430,7 @@ private string GetReplacementLine(CodeModule module, Declaration target, string
420430
421431 return rewriter . GetText ( new Interval ( firstTokenIndex , lastTokenIndex ) ) ;
422432 }
423- return GetReplacementLine ( content , target . IdentifierName , newName ) ;
433+ return GetReplacementLine ( content , target . IdentifierName , newName , target . Selection ) ;
424434 }
425435
426436 private static readonly DeclarationType [ ] ProcedureDeclarationTypes =
0 commit comments