use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class FoldingModelSupport method addFolding.
@Nullable
public static FoldRegion addFolding(@NotNull EditorEx editor, int start, int end, boolean expanded) {
DocumentEx document = editor.getDocument();
final int startOffset = document.getLineStartOffset(start);
final int endOffset = document.getLineEndOffset(end - 1);
FoldRegion value = editor.getFoldingModel().addFoldRegion(startOffset, endOffset, PLACEHOLDER);
if (value != null)
value.setExpanded(expanded);
return value;
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method updateHighlightersByTyping.
static void updateHighlightersByTyping(@NotNull Project project, @NotNull DocumentEvent e) {
ApplicationManager.getApplication().assertIsDispatchThread();
final Document document = e.getDocument();
if (document instanceof DocumentEx && ((DocumentEx) document).isInBulkUpdate())
return;
final MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
assertMarkupConsistent(markup, project);
final int start = e.getOffset() - 1;
final int end = start + e.getOldLength();
final List<HighlightInfo> toRemove = new ArrayList<>();
DaemonCodeAnalyzerEx.processHighlights(document, project, null, start, end, info -> {
if (!info.needUpdateOnTyping())
return true;
RangeHighlighter highlighter = info.getHighlighter();
int highlighterStart = highlighter.getStartOffset();
int highlighterEnd = highlighter.getEndOffset();
if (info.isAfterEndOfLine()) {
if (highlighterStart < document.getTextLength()) {
highlighterStart += 1;
}
if (highlighterEnd < document.getTextLength()) {
highlighterEnd += 1;
}
}
if (!highlighter.isValid() || start < highlighterEnd && highlighterStart <= end) {
toRemove.add(info);
}
return true;
});
for (HighlightInfo info : toRemove) {
if (!info.getHighlighter().isValid() || info.type.equals(HighlightInfoType.WRONG_REF)) {
info.getHighlighter().dispose();
}
}
assertMarkupConsistent(markup, project);
if (!toRemove.isEmpty()) {
disableWhiteSpaceOptimization(document);
}
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class PrintManager method doInitTextPainter.
private static TextPainter doInitTextPainter(final PsiFile psiFile) {
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null)
return null;
DocumentEx doc = (DocumentEx) PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
if (doc == null)
return null;
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(psiFile.getProject(), virtualFile);
highlighter.setText(doc.getCharsSequence());
return new TextPainter(doc, highlighter, virtualFile.getPresentableUrl(), virtualFile.getPresentableName(), psiFile, psiFile.getFileType());
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class DocumentUtil method executeInBulk.
/**
* Ensures that given task is executed when given document is at the given 'in bulk' mode.
*
* @param document target document
* @param executeInBulk {@code true} to force given document to be in bulk mode when given task is executed;
* {@code false} to force given document to be <b>not</b> in bulk mode when given task is executed
* @param task task to execute
*/
public static void executeInBulk(@NotNull Document document, final boolean executeInBulk, @NotNull Runnable task) {
if (!(document instanceof DocumentEx)) {
task.run();
return;
}
DocumentEx documentEx = (DocumentEx) document;
if (executeInBulk == documentEx.isInBulkUpdate()) {
task.run();
return;
}
documentEx.setInBulkUpdate(executeInBulk);
try {
task.run();
} finally {
documentEx.setInBulkUpdate(!executeInBulk);
}
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class ConsoleViewImpl method highlightHyperlinksAndFoldings.
private void highlightHyperlinksAndFoldings(int startLine) {
ApplicationManager.getApplication().assertIsDispatchThread();
boolean canHighlightHyperlinks = !myFilters.isEmpty();
if (!canHighlightHyperlinks && myUpdateFoldingsEnabled) {
return;
}
DocumentEx document = myEditor.getDocument();
if (document.getTextLength() == 0)
return;
int endLine = Math.max(0, document.getLineCount() - 1);
if (canHighlightHyperlinks) {
myHyperlinks.highlightHyperlinks(myFilters, startLine, endLine);
}
if (myAllowHeavyFilters && myFilters.isAnyHeavy() && myFilters.shouldRunHeavy()) {
runHeavyFilters(startLine, endLine);
}
if (myUpdateFoldingsEnabled) {
updateFoldings(startLine, endLine);
}
}
Aggregations