diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java b/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java index 5fa3924895d0..43dba460aa10 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java @@ -66,6 +66,4 @@ public abstract class Template { public abstract boolean isToShortenLongNames(); public abstract void setToShortenLongNames(boolean toShortenLongNames); - - public abstract void setSubSelection(RangeMarker selection); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImpl.java index 3d06dcf57232..ce7303c93d7d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImpl.java @@ -42,7 +42,6 @@ public class TemplateImpl extends Template implements SchemeElement { private ArrayList mySegments = null; private String myTemplateText = null; private String myId; - private RangeMarker mySubSelection; public boolean equals(Object o) { if (this == o) return true; @@ -452,14 +451,6 @@ public class TemplateImpl extends Template implements SchemeElement { return myVariables.get(i).skipOnStart(); } - public RangeMarker getSubSelection() { - return mySubSelection; - } - - public void setSubSelection(RangeMarker selection) { - mySubSelection = selection; - } - private static class Segment { public String name; public int offset; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java index 50df33f95cc0..7457d7e91936 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java @@ -459,12 +459,8 @@ public class TemplateState implements Disposable { myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); myEditor.getSelectionModel().removeSelection(); - final RangeMarker selection = myTemplate.getSubSelection(); - if (selection != null && selection.getStartOffset() >= start && selection.getEndOffset() <= end) { - myEditor.getSelectionModel().setSelection(selection.getStartOffset(), selection.getEndOffset()); - } else { - myEditor.getSelectionModel().setSelection(start, end); - } + + myEditor.getSelectionModel().setSelection(start, end); Expression expressionNode = myTemplate.getExpressionAt(myCurrentVariableNumber); final ExpressionContext context = createExpressionContext(start); diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index bdae42635a79..6607caac4fcb 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -185,13 +185,6 @@ public class VariableInplaceRenamer { PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, offset); if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myElementToRename)) return true; - final RangeMarker selection; - final SelectionModel selectionModel = myEditor.getSelectionModel(); - if (selectionModel.hasSelection()) { - selection = myEditor.getDocument().createRangeMarker(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); - } else { - selection = null; - } if (nameIdentifier != null) addVariable(nameIdentifier, selectedElement, builder, nameSuggestions); for (PsiReference ref : refs) { addVariable(ref, selectedElement, builder, offset, nameSuggestions); @@ -205,9 +198,16 @@ public class VariableInplaceRenamer { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { final int offset = myEditor.getCaretModel().getOffset(); + final SelectionModel selectionModel = myEditor.getSelectionModel(); + final TextRange selectedRange; + if (selectionModel.hasSelection()) { + selectedRange = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); + } + else { + selectedRange = null; + } Template template = builder.buildInlineTemplate(); template.setToShortenLongNames(false); - template.setSubSelection(selection); TextRange range = scope1.getTextRange(); assert range != null; myHighlighters = new ArrayList(); @@ -240,17 +240,11 @@ public class VariableInplaceRenamer { performAutomaticRename(myNewName, PsiTreeUtil.getParentOfType(containingFile.findElementAt(renameOffset), PsiNameIdentifierOwner.class)); } moveOffsetAfter(true); - if (selection != null) { - selection.dispose(); - } } public void templateCancelled(Template template) { finish(); moveOffsetAfter(false); - if (selection != null) { - selection.dispose(); - } } }); @@ -258,6 +252,9 @@ public class VariableInplaceRenamer { Runnable runnable = new Runnable() { public void run() { myEditor.getCaretModel().moveToOffset(offset); + if (selectedRange != null){ + myEditor.getSelectionModel().setSelection(selectedRange.getStartOffset(), selectedRange.getEndOffset()); + } } };