use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class InjectedCaret method setSelection.
@Override
public void setSelection(int startOffset, @Nullable VisualPosition endPosition, int endOffset) {
TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
myDelegate.setSelection(hostRange.getStartOffset(), endPosition, hostRange.getEndOffset());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class SelectionModelWindow method setSelection.
@Override
public void setSelection(final int startOffset, final int endOffset) {
TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset));
myHostModel.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class InjectedCaret method setSelection.
@Override
public void setSelection(int startOffset, int endOffset) {
TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
myDelegate.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class CommonMoveUtil method retargetUsages.
public static NonCodeUsageInfo[] retargetUsages(final UsageInfo[] usages, final Map<PsiElement, PsiElement> oldToNewElementsMapping) throws IncorrectOperationException {
Arrays.sort(usages, (o1, o2) -> {
final VirtualFile file1 = o1.getVirtualFile();
final VirtualFile file2 = o2.getVirtualFile();
if (Comparing.equal(file1, file2)) {
final ProperTextRange rangeInElement1 = o1.getRangeInElement();
final ProperTextRange rangeInElement2 = o2.getRangeInElement();
if (rangeInElement1 != null && rangeInElement2 != null) {
return rangeInElement2.getStartOffset() - rangeInElement1.getStartOffset();
}
return 0;
}
if (file1 == null)
return -1;
if (file2 == null)
return 1;
return Comparing.compare(file1.getPath(), file2.getPath());
});
List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for (UsageInfo usage : usages) {
if (usage instanceof NonCodeUsageInfo) {
nonCodeUsages.add((NonCodeUsageInfo) usage);
} else if (usage instanceof MoveRenameUsageInfo) {
final MoveRenameUsageInfo moveRenameUsage = (MoveRenameUsageInfo) usage;
final PsiElement oldElement = moveRenameUsage.getReferencedElement();
final PsiElement newElement = oldToNewElementsMapping.get(oldElement);
LOG.assertTrue(newElement != null, oldElement);
final PsiReference reference = moveRenameUsage.getReference();
if (reference != null) {
try {
reference.bindToElement(newElement);
} catch (IncorrectOperationException e) {
//
}
}
}
}
return nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class FindManagerTest method getParentFromUsage.
private static PsiElement getParentFromUsage(UsageInfo usage) {
ProperTextRange range = usage.getRangeInElement();
assertNotNull(range);
PsiElement element = usage.getElement();
assertNotNull(element);
PsiElement elementAt = element.findElementAt(range.getStartOffset());
assertNotNull(elementAt);
return elementAt.getParent();
}
Aggregations