use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class ProblemPreviewEditorPresentation method appendFoldings.
private void appendFoldings(CommonProblemDescriptor[] descriptors) {
List<UsageInfo> usages = Arrays.stream(descriptors).filter(ProblemDescriptorBase.class::isInstance).map(ProblemDescriptorBase.class::cast).map(d -> {
final PsiElement psi = d.getPsiElement();
if (psi == null) {
return null;
}
final TextRange range = d.getTextRangeInElement();
return range == null ? new UsageInfo(psi) : new UsageInfo(psi, range.getStartOffset(), range.getEndOffset());
}).collect(Collectors.toList());
boolean isUpdated = false;
for (UsageInfo usage : usages) {
if (usage == null) {
return;
}
isUpdated |= appendFoldings(usage.getSegment());
}
if (isUpdated) {
updateFoldings();
}
List<UsageInfo> validUsages = usages.stream().filter(Objects::nonNull).collect(Collectors.toList());
PsiDocumentManager.getInstance(myView.getProject()).performLaterWhenAllCommitted(() -> {
if (!myEditor.isDisposed()) {
myView.invalidate();
myView.validate();
UsagePreviewPanel.highlight(validUsages, myEditor, myView.getProject(), false, HighlighterLayer.SELECTION);
if (validUsages.size() == 1) {
final PsiElement element = validUsages.get(0).getElement();
if (element != null) {
final DocumentEx document = myEditor.getDocument();
final int offset = Math.min(element.getTextRange().getEndOffset() + VIEW_ADDITIONAL_OFFSET, document.getLineEndOffset(document.getLineNumber(element.getTextRange().getEndOffset())));
myEditor.getScrollingModel().scrollTo(myEditor.offsetToLogicalPosition(offset), ScrollType.CENTER);
return;
}
}
myEditor.getScrollingModel().scrollTo(myEditor.offsetToLogicalPosition(0), ScrollType.CENTER_UP);
}
});
}
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 MultiHostRegistrarImpl method getModificationCount.
// for CachedValue
@Override
public long getModificationCount() {
List<PsiLanguageInjectionHost.Shred> shredList = shreds;
if (shredList != null) {
for (PsiLanguageInjectionHost.Shred shred : shredList) {
if (!shred.isValid())
return -1;
}
}
DocumentEx hostDocument = myHostDocument;
return hostDocument == null ? -1 : hostDocument.getModificationStamp();
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class UndoableGroup method doUndoOrRedo.
private void doUndoOrRedo(final boolean isUndo) {
final boolean wrapInBulkUpdate = myActions.size() > 50;
// perform undo action by action, setting bulk update flag if possible
// if multiple consecutive actions share a document, then set the bulk flag only once
final UnexpectedUndoException[] exception = { null };
ApplicationManager.getApplication().runWriteAction(() -> {
final Set<DocumentEx> bulkDocuments = new THashSet<>();
try {
for (final UndoableAction action : isUndo ? ContainerUtil.iterateBackward(myActions) : myActions) {
if (wrapInBulkUpdate) {
DocumentEx newDocument = getDocumentToSetBulkMode(action);
if (newDocument == null) {
for (DocumentEx document : bulkDocuments) {
document.setInBulkUpdate(false);
}
bulkDocuments.clear();
} else if (bulkDocuments.add(newDocument)) {
newDocument.setInBulkUpdate(true);
}
}
if (isUndo) {
action.undo();
} else {
action.redo();
}
}
} catch (UnexpectedUndoException e) {
exception[0] = e;
} finally {
for (DocumentEx bulkDocument : bulkDocuments) {
bulkDocument.setInBulkUpdate(false);
}
}
});
if (exception[0] != null)
reportUndoProblem(exception[0], isUndo);
commitAllDocuments();
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class MergeList method finishBulkUpdate.
public void finishBulkUpdate() {
Document document1 = myBaseToLeftChangeList.getDocument(BRANCH_SIDE);
Document document2 = myBaseToRightChangeList.getDocument(BRANCH_SIDE);
Document document3 = myBaseToLeftChangeList.getDocument(BASE_SIDE);
assert document3 == myBaseToRightChangeList.getDocument(BASE_SIDE);
((DocumentEx) document1).setInBulkUpdate(false);
((DocumentEx) document2).setInBulkUpdate(false);
((DocumentEx) document3).setInBulkUpdate(false);
}
Aggregations