use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class EventLog method formatForLog.
public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
DocumentImpl logDoc = new DocumentImpl("", true);
AtomicBoolean showMore = new AtomicBoolean(false);
Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
List<RangeMarker> lineSeparators = new ArrayList<>();
String title = notification.getTitle();
String subtitle = notification.getSubtitle();
if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
title += " (" + subtitle + ")";
}
title = truncateLongString(showMore, title);
String content = truncateLongString(showMore, notification.getContent());
RangeMarker afterTitle = null;
boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
if (StringUtil.isNotEmpty(title)) {
if (StringUtil.isNotEmpty(content)) {
appendText(logDoc, ": ");
afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
}
}
int titleLength = logDoc.getTextLength();
hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
List<AnAction> actions = notification.getActions();
if (!actions.isEmpty()) {
String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {
private int index;
@Override
public String fun(AnAction action) {
return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
}
}, isLongLine(actions) ? "<br>" : " ") + "</p>";
Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
}
});
if (title.length() > 0 || content.length() > 0) {
lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
}
hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
}
String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
for (RangeMarker marker : links.keySet()) {
if (!marker.isValid()) {
showMore.set(true);
continue;
}
list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
}
if (showMore.get()) {
String sb = "show balloon";
if (!logDoc.getText().endsWith(" ")) {
appendText(logDoc, " ");
}
appendText(logDoc, "(" + sb + ")");
list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
}
return new LogEntry(logDoc.getText(), status, list, titleLength);
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class DocumentWindowImpl method createRangeMarker.
@Override
@NotNull
public RangeMarker createRangeMarker(final int startOffset, final int endOffset, final boolean surviveOnExternalChange) {
if (!surviveOnExternalChange) {
return createRangeMarker(startOffset, endOffset);
}
ProperTextRange hostRange = injectedToHost(new ProperTextRange(startOffset, endOffset));
//todo persistent?
RangeMarker hostMarker = myDelegate.createRangeMarker(hostRange.getStartOffset(), hostRange.getEndOffset(), surviveOnExternalChange);
int startShift = Math.max(0, hostToInjected(hostRange.getStartOffset()) - startOffset);
int endShift = Math.max(0, endOffset - hostToInjected(hostRange.getEndOffset()) - startShift);
return new RangeMarkerWindow(this, (RangeMarkerEx) hostMarker, startShift, endShift);
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class DocumentWindowImpl method createRangeMarker.
@Override
@NotNull
public RangeMarker createRangeMarker(final int startOffset, final int endOffset) {
ProperTextRange hostRange = injectedToHost(new ProperTextRange(startOffset, endOffset));
RangeMarker hostMarker = myDelegate.createRangeMarker(hostRange);
int startShift = Math.max(0, hostToInjected(hostRange.getStartOffset()) - startOffset);
int endShift = Math.max(0, endOffset - hostToInjected(hostRange.getEndOffset()) - startShift);
return new RangeMarkerWindow(this, (RangeMarkerEx) hostMarker, startShift, endShift);
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class SliceTestUtil method extract.
private static void extract(final Document document, final Map<String, RangeMarker> sliceUsageName2Offset, final String name) {
WriteCommandAction.runWriteCommandAction(null, () -> {
for (int i = 1; i < 9; i++) {
String newName = name + i;
String s = "<flown" + newName + ">";
if (!document.getText().contains(s))
break;
int off = document.getText().indexOf(s);
document.deleteString(off, off + s.length());
RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off));
assertNull(prev);
extract(document, sliceUsageName2Offset, newName);
}
});
}
use of com.intellij.openapi.editor.RangeMarker in project intellij-community by JetBrains.
the class ExpectedHighlightingData method refreshLineMarkers.
private void refreshLineMarkers() {
for (Map.Entry<RangeMarker, LineMarkerInfo> entry : myLineMarkerInfos.entrySet()) {
RangeMarker rangeMarker = entry.getKey();
int startOffset = rangeMarker.getStartOffset();
int endOffset = rangeMarker.getEndOffset();
LineMarkerInfo value = entry.getValue();
PsiElement element = value.getElement();
assert element != null : value;
TextRange range = new TextRange(startOffset, endOffset);
final String tooltip = value.getLineMarkerTooltip();
LineMarkerInfo markerInfo = new LineMarkerInfo<>(element, range, null, value.updatePass, e -> tooltip, null, GutterIconRenderer.Alignment.RIGHT);
entry.setValue(markerInfo);
}
}
Aggregations