mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inplace introduce: preserve offset corresponding to editor changes
This commit is contained in:
+15
@@ -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());
|
||||
}
|
||||
}
|
||||
+18
@@ -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>() {
|
||||
|
||||
+3
-3
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user