diff options
Diffstat (limited to 'python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java')
-rw-r--r-- | python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java index 29fc44105857..00448c8b69bd 100644 --- a/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java +++ b/python/src/com/jetbrains/python/refactoring/introduce/IntroduceHandler.java @@ -69,6 +69,11 @@ import static com.jetbrains.python.inspections.PyStringFormatParser.*; abstract public class IntroduceHandler implements RefactoringActionHandler { protected static PsiElement findAnchor(List<PsiElement> occurrences) { PsiElement anchor = occurrences.get(0); + final Pair<PsiElement, TextRange> data = anchor.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE); + // Search anchor in the origin file, not in dummy.py, if selection breaks statement and thus element was generated + if (data != null && occurrences.size() == 1) { + return PsiTreeUtil.getParentOfType(data.getFirst(), PyStatement.class); + } next: do { final PyStatement statement = PsiTreeUtil.getParentOfType(anchor, PyStatement.class); @@ -192,7 +197,7 @@ abstract public class IntroduceHandler implements RefactoringActionHandler { String text = expression.getText(); final Pair<PsiElement, TextRange> selection = expression.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE); if (selection != null) { - text = selection.getSecond().substring(text); + text = selection.getSecond().substring(selection.getFirst().getText()); } if (expression instanceof PyCallExpression) { final PyExpression callee = ((PyCallExpression)expression).getCallee(); |