From ff169ee692475dc0ecc33bdb6961c52318e8744c Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 9 Apr 2013 09:43:30 +0200 Subject: [PATCH] inplace refactorings: check reference at caret according to editor offset --- .../refactoring/rename/inplace/InplaceRefactoring.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java index 95fa2d577083..ede44ce5cf29 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/InplaceRefactoring.java @@ -270,7 +270,7 @@ public abstract class InplaceRefactoring { boolean subrefOnPrimaryElement = false; for (PsiReference ref : refs) { - if (isReferenceAtCaret(selectedElement, ref)) { + if (isReferenceAtCaret(nameIdentifier, ref, offset)) { builder.replaceElement(ref, PRIMARY_VARIABLE_NAME, createLookupExpression(), true); subrefOnPrimaryElement = true; continue; @@ -327,8 +327,12 @@ public abstract class InplaceRefactoring { return true; } - protected boolean isReferenceAtCaret(PsiElement nameIdentifier, PsiReference ref) { - return nameIdentifier != null && ref.getElement() == nameIdentifier.getParent(); + protected boolean isReferenceAtCaret(PsiElement nameIdentifier, PsiReference ref, int offset) { + if (nameIdentifier != null && ref.getElement() == nameIdentifier.getParent()) { + final TextRange textRange = nameIdentifier.getTextRange(); + return textRange != null && contains(textRange, offset); + } + return false; } protected void beforeTemplateStart() {