inplace introduce: preserve offset corresponding to editor changes

This commit is contained in:
anna
2011-08-09 12:11:07 +04:00
parent 8d24f9e0ed
commit ce10ecce7f
4 changed files with 47 additions and 3 deletions
@@ -0,0 +1,15 @@
import java.lang.String;
class A {
A(String str) {
}
public static String getVeryLongString() {
return "";
}
void foo() {
A a = new A(getVeryLongString());
A a1 = new A(getVery<caret>LongString());
}
}
@@ -0,0 +1,18 @@
import java.lang.String;
class A {
public static final String O = getVeryLongString();
A(String str) {
}
public static String getVeryLongString() {
return "";
}
void foo() {
A a = new A(O);
A a1 = new A(O);
}
}
@@ -55,6 +55,17 @@ public class InplaceIntroduceConstantTest extends AbstractInplaceIntroduceTest {
});
}
public void testReplaceAllFromSecondOccurrence() throws Exception {
doTest(new Pass<AbstractInplaceIntroducer>() {
@Override
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
type("O");
inplaceIntroduceFieldPopup.setReplaceAllOccurrences(true);
}
});
}
public void testConflictingConstantName() throws Exception {
doTest(new Pass<AbstractInplaceIntroducer>() {
@@ -245,7 +245,7 @@ public class VariableInplaceRenamer {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final int offset = myEditor.getCaretModel().getOffset();
final RangeMarker offset = myEditor.getDocument().createRangeMarker(new TextRange(myEditor.getCaretModel().getOffset(), myEditor.getCaretModel().getOffset()));
final SelectionModel selectionModel = myEditor.getSelectionModel();
final TextRange selectedRange = preserveSelectedRange(selectionModel);
Template template = builder.buildInlineTemplate();
@@ -294,7 +294,7 @@ public class VariableInplaceRenamer {
//move to old offset
Runnable runnable = new Runnable() {
public void run() {
myEditor.getCaretModel().moveToOffset(offset);
myEditor.getCaretModel().moveToOffset(offset.getStartOffset());
if (selectedRange != null){
myEditor.getSelectionModel().setSelection(selectedRange.getStartOffset(), selectedRange.getEndOffset());
}
@@ -302,7 +302,7 @@ public class VariableInplaceRenamer {
};
final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
if (lookup != null && lookup.getLookupStart() <= offset) {
if (lookup != null && lookup.getLookupStart() <= offset.getStartOffset()) {
lookup.setFocused(false);
lookup.performGuardedChange(runnable);
} else {