fix whole-file smart range pointers on unicode files

This commit is contained in:
peter
2017-07-20 14:26:31 +02:00
parent 72540b1b2f
commit 5c47576148
2 changed files with 13 additions and 1 deletions
@@ -1034,4 +1034,13 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase {
assertEquals(TextRange.from(3, 1), TextRange.create(pointer.getRange()));
}
public void testFileRangeWithUnicode() throws Exception {
PsiFile file = createFile("a.java", "Ы");
assertEquals(1, file.getTextLength());
SmartPsiFileRange pointer = getPointerManager().createSmartPsiFileRangePointer(file, TextRange.from(0, file.getTextLength()));
assertEquals(TextRange.from(0, 1), TextRange.create(pointer.getPsiRange()));
assertEquals(TextRange.from(0, 1), TextRange.create(pointer.getRange()));
}
}
@@ -73,7 +73,10 @@ class FileElementInfo extends SmartPointerElementInfo {
@Override
public Segment getRange() {
return myVirtualFile.isValid() ? new TextRange(0, (int)myVirtualFile.getLength()) : null;
if (!myVirtualFile.isValid()) return null;
Document document = FileDocumentManager.getInstance().getDocument(myVirtualFile);
return document == null ? null : TextRange.from(0, document.getTextLength());
}
@NotNull