use of com.intellij.application.options.colors.highlighting.HighlightData in project intellij-community by JetBrains.
the class SimpleEditorPreview method setupRainbowHighlighting.
@NotNull
private List<HighlightData> setupRainbowHighlighting(@NotNull final RainbowColorSettingsPage page, @NotNull final List<HighlightData> initialMarkup, @NotNull final TextAttributesKey[] rainbowTempKeys, boolean isRainbowOn) {
int colorCount = rainbowTempKeys.length;
if (colorCount == 0) {
return initialMarkup;
}
List<HighlightData> rainbowMarkup = new ArrayList<>();
int tempKeyIndex = 0;
boolean repeatAnchor = true;
for (HighlightData d : initialMarkup) {
final TextAttributesKey highlightKey = d.getHighlightKey();
final boolean rainbowType = page.isRainbowType(highlightKey);
final boolean rainbowDemoType = highlightKey == RainbowHighlighter.RAINBOW_GRADIENT_DEMO;
if (rainbowType || rainbowDemoType) {
final HighlightData rainbowAnchor = new HighlightData(d.getStartOffset(), d.getEndOffset(), RainbowHighlighter.RAINBOW_ANCHOR);
if (isRainbowOn) {
// rainbow on
HighlightData rainbowTemp;
if (rainbowType) {
rainbowTemp = getRainbowTemp(rainbowTempKeys, d.getStartOffset(), d.getEndOffset());
} else {
rainbowTemp = new HighlightData(d.getStartOffset(), d.getEndOffset(), rainbowTempKeys[tempKeyIndex % colorCount]);
if (repeatAnchor && tempKeyIndex == colorCount / 2) {
// anchor [Color#3] colored twice: it the end and in the beginning of rainbow-demo string
repeatAnchor = false;
} else {
++tempKeyIndex;
}
}
// TODO: <remove the hack>
// At some point highlighting data is applied in reversed order. To ensure rainbow highlighting is always on top, we add it twice.
rainbowMarkup.add(rainbowTemp);
rainbowMarkup.add(rainbowAnchor);
rainbowMarkup.add(d);
rainbowMarkup.add(rainbowAnchor);
rainbowMarkup.add(rainbowTemp);
} else {
// rainbow off
if (rainbowType) {
// TODO: <remove the hack>
// See above
rainbowMarkup.add(d);
rainbowMarkup.add(rainbowAnchor);
rainbowMarkup.add(d);
} else {
rainbowMarkup.add(rainbowAnchor);
}
}
} else if (!(RainbowHighlighter.isRainbowTempKey(highlightKey) || highlightKey == RainbowHighlighter.RAINBOW_ANCHOR)) {
// filter rainbow RAINBOW_TEMP and RAINBOW_ANCHOR
rainbowMarkup.add(d);
}
}
return rainbowMarkup;
}
use of com.intellij.application.options.colors.highlighting.HighlightData in project intellij-community by JetBrains.
the class SimpleEditorPreview method updateHighlighters.
private void updateHighlighters() {
UIUtil.invokeLaterIfNeeded(() -> {
if (myEditor.isDisposed())
return;
removeDecorations(myEditor);
final Map<TextAttributesKey, String> displayText = ColorSettingsUtil.keyToDisplayTextMap(myPage);
for (final HighlightData data : myHighlightData) {
data.addHighlToView(myEditor, myOptions.getSelectedScheme(), displayText);
}
});
}
use of com.intellij.application.options.colors.highlighting.HighlightData in project intellij-community by JetBrains.
the class SimpleEditorPreview method scrollHighlightInView.
void scrollHighlightInView(@Nullable final List<HighlightData> highlightDatas) {
if (highlightDatas == null)
return;
boolean needScroll = true;
int minOffset = Integer.MAX_VALUE;
for (HighlightData data : highlightDatas) {
if (isOffsetVisible(data.getStartOffset())) {
needScroll = false;
break;
}
minOffset = Math.min(minOffset, data.getStartOffset());
}
if (needScroll && minOffset != Integer.MAX_VALUE) {
LogicalPosition pos = myEditor.offsetToLogicalPosition(minOffset);
myEditor.getScrollingModel().scrollTo(pos, ScrollType.MAKE_VISIBLE);
}
}
use of com.intellij.application.options.colors.highlighting.HighlightData in project intellij-community by JetBrains.
the class SimpleEditorPreview method startBlinkingHighlights.
private List<HighlightData> startBlinkingHighlights(final EditorEx editor, final String attrKey, final SyntaxHighlighter highlighter, final boolean show, final Alarm alarm, final int count, final ColorSettingsPage page) {
if (show && count <= 0)
return Collections.emptyList();
removeDecorations(editor);
boolean found = false;
List<HighlightData> highlights = new ArrayList<>();
List<HighlightData> matchingHighlights = new ArrayList<>();
for (HighlightData highlightData : myHighlightData) {
boolean highlight = show && highlightData.getHighlightType().equals(attrKey);
highlightData.addToCollection(highlights, highlight);
if (highlight) {
matchingHighlights.add(highlightData);
found = true;
}
}
if (!found && highlighter != null) {
HighlighterIterator iterator = editor.getHighlighter().createIterator(0);
do {
IElementType tokenType = iterator.getTokenType();
TextAttributesKey[] tokenHighlights = highlighter.getTokenHighlights(tokenType);
for (final TextAttributesKey tokenHighlight : tokenHighlights) {
String type = tokenHighlight.getExternalName();
if (show && type != null && type.equals(attrKey)) {
HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(), BLINKING_HIGHLIGHTS_ATTRIBUTES);
highlights.add(highlightData);
matchingHighlights.add(highlightData);
}
}
iterator.advance();
} while (!iterator.atEnd());
}
final Map<TextAttributesKey, String> displayText = ColorSettingsUtil.keyToDisplayTextMap(page);
// sort highlights to avoid overlappings
Collections.sort(highlights, Comparator.comparingInt(HighlightData::getStartOffset));
for (int i = highlights.size() - 1; i >= 0; i--) {
HighlightData highlightData = highlights.get(i);
int startOffset = highlightData.getStartOffset();
HighlightData prevHighlightData = i == 0 ? null : highlights.get(i - 1);
if (prevHighlightData != null && startOffset <= prevHighlightData.getEndOffset() && highlightData.getHighlightType().equals(prevHighlightData.getHighlightType())) {
prevHighlightData.setEndOffset(highlightData.getEndOffset());
} else {
highlightData.addHighlToView(editor, myOptions.getSelectedScheme(), displayText);
}
}
alarm.cancelAllRequests();
alarm.addComponentRequest(() -> startBlinkingHighlights(editor, attrKey, highlighter, !show, alarm, count - 1, page), 400);
return matchingHighlights;
}
use of com.intellij.application.options.colors.highlighting.HighlightData in project intellij-community by JetBrains.
the class SimpleEditorPreview method navigate.
private void navigate(boolean select, @NotNull final LogicalPosition pos) {
int offset = myEditor.logicalPositionToOffset(pos);
final SyntaxHighlighter highlighter = myPage.getHighlighter();
String type;
HighlightData highlightData = getDataFromOffset(offset);
if (highlightData != null) {
// tag-based navigation first
type = RainbowHighlighter.isRainbowTempKey(highlightData.getHighlightKey()) ? RainbowHighlighter.RAINBOW_TYPE : highlightData.getHighlightType();
} else {
// if failed, try the highlighter-based navigation
type = selectItem(myEditor.getHighlighter().createIterator(offset), highlighter);
}
setCursor(type == null ? Cursor.TEXT_CURSOR : Cursor.HAND_CURSOR);
if (select && type != null) {
myDispatcher.getMulticaster().selectionInPreviewChanged(type);
}
}
Aggregations