use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class SelectInEditorManagerImpl method selectInEditor.
@Override
public void selectInEditor(VirtualFile file, final int startOffset, final int endOffset, final boolean toSelectLine, final boolean toUseNormalSelection) {
releaseAll();
final TextRange textRange;
if (file instanceof VirtualFileWindow) {
DocumentWindow documentWindow = ((VirtualFileWindow) file).getDocumentWindow();
textRange = documentWindow.injectedToHost(new TextRange(startOffset, endOffset));
file = ((VirtualFileWindow) file).getDelegate();
} else {
textRange = new ProperTextRange(startOffset, endOffset);
}
openEditor(file, endOffset);
final Editor editor = openEditor(file, textRange.getStartOffset());
SwingUtilities.invokeLater(() -> {
if (editor != null && !editor.isDisposed()) {
doSelect(toUseNormalSelection, editor, toSelectLine, textRange);
}
});
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class UsageInfo2UsageAdapter method getDescriptor.
private OpenFileDescriptor getDescriptor() {
VirtualFile file = getFile();
if (file == null)
return null;
Segment range = getNavigationRange();
if (range != null && file instanceof VirtualFileWindow && range.getStartOffset() >= 0) {
// have to use injectedToHost(TextRange) to calculate right offset in case of multiple shreds
range = ((VirtualFileWindow) file).getDocumentWindow().injectedToHost(TextRange.create(range));
file = ((VirtualFileWindow) file).getDelegate();
}
return new OpenFileDescriptor(getProject(), file, range == null ? getNavigationOffset() : range.getStartOffset());
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class FileManagerImpl method getFromInjected.
@Nullable
private FileViewProvider getFromInjected(@NotNull VirtualFile file) {
if (file instanceof VirtualFileWindow) {
DocumentWindow document = ((VirtualFileWindow) file).getDocumentWindow();
PsiFile psiFile = PsiDocumentManager.getInstance(myManager.getProject()).getCachedPsiFile(document);
if (psiFile == null)
return null;
return psiFile.getViewProvider();
}
return null;
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class InjectedSelfElementInfo method hostToInjected.
@Nullable
private static ProperTextRange hostToInjected(boolean psi, Segment hostRange, @Nullable PsiFile injectedFile, @Nullable AffixOffsets affixOffsets) {
VirtualFile virtualFile = injectedFile == null ? null : injectedFile.getVirtualFile();
if (virtualFile instanceof VirtualFileWindow) {
Project project = injectedFile.getProject();
DocumentWindow documentWindow = ((VirtualFileWindow) virtualFile).getDocumentWindow();
if (psi) {
documentWindow = (DocumentWindow) ((PsiDocumentManagerBase) PsiDocumentManager.getInstance(project)).getLastCommittedDocument(documentWindow);
}
int start = documentWindow.hostToInjected(hostRange.getStartOffset());
int end = documentWindow.hostToInjected(hostRange.getEndOffset());
if (affixOffsets != null) {
return affixOffsets.expandRangeToAffixes(start, end, InjectedLanguageManager.getInstance(project).getNonEditableFragments(documentWindow));
}
return ProperTextRange.create(start, end);
}
return null;
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class InspectionResultsView method getSelectedNavigatable.
@Nullable
private Navigatable getSelectedNavigatable(final CommonProblemDescriptor descriptor, final PsiElement psiElement) {
if (descriptor instanceof ProblemDescriptorBase) {
Navigatable navigatable = ((ProblemDescriptorBase) descriptor).getNavigatable();
if (navigatable != null) {
return navigatable;
}
}
if (psiElement == null || !psiElement.isValid())
return null;
PsiFile containingFile = psiElement.getContainingFile();
VirtualFile virtualFile = containingFile == null ? null : containingFile.getVirtualFile();
if (virtualFile != null) {
int startOffset = psiElement.getTextOffset();
if (descriptor instanceof ProblemDescriptorBase) {
final TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRangeForNavigation();
if (textRange != null) {
if (virtualFile instanceof VirtualFileWindow) {
virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
}
startOffset = textRange.getStartOffset();
}
}
return new OpenFileDescriptor(myProject, virtualFile, startOffset);
}
return null;
}
Aggregations