use of com.intellij.injected.editor.DocumentWindowImpl in project intellij-community by JetBrains.
the class InjectedFileViewProvider method rootChanged.
@Override
public void rootChanged(@NotNull PsiFile psiFile) {
super.rootChanged(psiFile);
// injected PSI change happened inside reparse; ignore
if (!isPhysical())
return;
if (myPatchingLeaves)
return;
DocumentWindowImpl documentWindow = myDocumentWindow;
List<PsiLanguageInjectionHost.Shred> shreds = documentWindow.getShreds();
assert documentWindow.getHostRanges().length == shreds.size();
String[] changes = documentWindow.calculateMinEditSequence(psiFile.getNode().getText());
assert changes.length == shreds.size();
for (int i = 0; i < changes.length; i++) {
String change = changes[i];
if (change != null) {
PsiLanguageInjectionHost.Shred shred = shreds.get(i);
PsiLanguageInjectionHost host = shred.getHost();
TextRange rangeInsideHost = shred.getRangeInsideHost();
String newHostText = StringUtil.replaceSubstring(host.getText(), rangeInsideHost, change);
//shred.host =
host.updateText(newHostText);
}
}
}
use of com.intellij.injected.editor.DocumentWindowImpl in project intellij-community by JetBrains.
the class InjectedLanguageManagerImpl method injectedToHost.
@Override
public int injectedToHost(@NotNull PsiElement element, int offset) {
PsiFile file = element.getContainingFile();
if (file == null)
return offset;
Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
if (!(document instanceof DocumentWindowImpl))
return offset;
DocumentWindowImpl documentWindow = (DocumentWindowImpl) document;
return documentWindow.injectedToHost(offset);
}
use of com.intellij.injected.editor.DocumentWindowImpl in project intellij-community by JetBrains.
the class InjectedLanguageManagerImpl method getNonEditableFragments.
@NotNull
@Override
public List<TextRange> getNonEditableFragments(@NotNull DocumentWindow window) {
List<TextRange> result = ContainerUtil.newArrayList();
int offset = 0;
for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl) window).getShreds()) {
Segment hostRange = shred.getHostRangeMarker();
if (hostRange == null)
continue;
offset = appendRange(result, offset, shred.getPrefix().length());
offset += hostRange.getEndOffset() - hostRange.getStartOffset();
offset = appendRange(result, offset, shred.getSuffix().length());
}
return result;
}
use of com.intellij.injected.editor.DocumentWindowImpl in project intellij-community by JetBrains.
the class InjectedLanguageManagerImpl method injectedToHost.
@Override
@NotNull
public TextRange injectedToHost(@NotNull PsiElement injectedContext, @NotNull TextRange injectedTextRange) {
PsiFile file = injectedContext.getContainingFile();
if (file == null)
return injectedTextRange;
Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
if (!(document instanceof DocumentWindowImpl))
return injectedTextRange;
DocumentWindowImpl documentWindow = (DocumentWindowImpl) document;
return documentWindow.injectedToHost(injectedTextRange);
}
Aggregations