mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
IDEA-144655 Smart PSI pointers should retain old offsets after inserting text after them
This commit is contained in:
+19
@@ -24,6 +24,7 @@ import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.editor.event.EditorEventMulticaster;
|
||||
@@ -754,6 +755,24 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
assertEquals(TextRange.create(2, 3), pointer.getRange());
|
||||
}
|
||||
|
||||
public void testUpdateAfterInsertingIdenticalText() {
|
||||
PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, "class Foo {\n" +
|
||||
" void m() {\n" +
|
||||
" }\n" +
|
||||
"<caret>}\n");
|
||||
PsiMethod method = file.getClasses()[0].getMethods()[0];
|
||||
TextRange originalRange = method.getTextRange();
|
||||
SmartPsiElementPointer pointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(method);
|
||||
|
||||
EditorModificationUtil.insertStringAtCaret(myEditor, " void m() {\n" +
|
||||
" }\n");
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
|
||||
PsiElement element = pointer.getElement();
|
||||
assertNotNull(element);
|
||||
TextRange newRange = element.getTextRange();
|
||||
assertEquals(originalRange, newRange);
|
||||
}
|
||||
|
||||
public void testAnchorInfoSurvivesPsiChange() {
|
||||
PsiJavaFile file = (PsiJavaFile)configureByText(JavaFileType.INSTANCE, "class C1{}\nclass C2 {}");
|
||||
|
||||
Reference in New Issue
Block a user