use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class ConsoleViewImpl method runHeavyFilters.
private void runHeavyFilters(int line1, int endLine) {
final int startLine = Math.max(0, line1);
final Document document = myEditor.getDocument();
final int startOffset = document.getLineStartOffset(startLine);
String text = document.getText(new TextRange(startOffset, document.getLineEndOffset(endLine)));
final Document documentCopy = new DocumentImpl(text, true);
documentCopy.setReadOnly(true);
myJLayeredPane.startUpdating();
final int currentValue = myHeavyUpdateTicket;
myHeavyAlarm.addRequest(() -> {
if (!myFilters.shouldRunHeavy())
return;
try {
myFilters.applyHeavyFilter(documentCopy, startOffset, startLine, additionalHighlight -> addFlushRequest(new FlushRunnable() {
@Override
public void doRun() {
if (myHeavyUpdateTicket != currentValue)
return;
TextAttributes additionalAttributes = additionalHighlight.getTextAttributes(null);
if (additionalAttributes != null) {
ResultItem item = additionalHighlight.getResultItems().get(0);
myHyperlinks.addHighlighter(item.getHighlightStartOffset(), item.getHighlightEndOffset(), additionalAttributes);
} else {
myHyperlinks.highlightHyperlinks(additionalHighlight, 0);
}
}
@Override
public boolean equals(Object o) {
return this == o;
}
}, 0));
} finally {
if (myHeavyAlarm.getActiveRequestCount() <= 1) {
// only the current request
UIUtil.invokeLaterIfNeeded(() -> myJLayeredPane.finishUpdating());
}
}
}, 0);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project kotlin by JetBrains.
the class KotlinFormattingModelBuilder method createModel.
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(KotlinLanguage.INSTANCE);
KotlinBlock block = new KotlinBlock(containingFile.getNode(), NodeAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings, KotlinSpacingRulesKt.createSpacingBuilder(settings, KotlinSpacingBuilderUtilImpl.INSTANCE));
// it's needed until IDEA's issue with this document being created with wrong threading policy is fixed
if (!element.isPhysical()) {
FormattingDocumentModelImpl formattingDocumentModel = new FormattingDocumentModelImpl(new DocumentImpl(containingFile.getViewProvider().getContents(), true), containingFile);
return new PsiBasedFormattingModel(containingFile, block, formattingDocumentModel);
}
return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class StudyUtils method deleteGuardedBlocks.
public static void deleteGuardedBlocks(@NotNull final Document document) {
if (document instanceof DocumentImpl) {
final DocumentImpl documentImpl = (DocumentImpl) document;
List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
for (final RangeMarker block : blocks) {
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> document.removeGuardedBlock(block)));
}
}
}
Aggregations