use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class CtrlMouseHandler method installHighlighterSet.
@NotNull
private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) {
final JComponent internalComponent = editor.getContentComponent();
internalComponent.addKeyListener(myEditorKeyListener);
editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
final Cursor cursor = internalComponent.getCursor();
if (info.isNavigatable()) {
internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);
List<RangeHighlighter> highlighters = new ArrayList<>();
TextAttributes attributes = info.isNavigatable() ? myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR) : new TextAttributes(null, HintUtil.getInformationColor(), null, null, Font.PLAIN);
for (TextRange range : info.getRanges()) {
TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor);
final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.HYPERLINK, attr, HighlighterTargetArea.EXACT_RANGE);
highlighters.add(highlighter);
}
return new HighlightersSet(highlighters, editor, cursor, info);
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class LivePreview method doHightlightRange.
private RangeHighlighter doHightlightRange(final TextRange textRange, final TextAttributes attributes, Set<RangeHighlighter> highlighters) {
HighlightManager highlightManager = HighlightManager.getInstance(mySearchResults.getProject());
MarkupModelEx markupModel = (MarkupModelEx) mySearchResults.getEditor().getMarkupModel();
final RangeHighlighter[] candidate = new RangeHighlighter[1];
boolean notFound = markupModel.processRangeHighlightersOverlappingWith(textRange.getStartOffset(), textRange.getEndOffset(), highlighter -> {
TextAttributes textAttributes = highlighter.getTextAttributes();
if (highlighter.getUserData(SEARCH_MARKER) != null && textAttributes != null && textAttributes.equals(attributes) && highlighter.getStartOffset() == textRange.getStartOffset() && highlighter.getEndOffset() == textRange.getEndOffset()) {
candidate[0] = highlighter;
return false;
}
return true;
});
if (!notFound && highlighters.contains(candidate[0])) {
return candidate[0];
}
final ArrayList<RangeHighlighter> dummy = new ArrayList<>();
highlightManager.addRangeHighlight(mySearchResults.getEditor(), textRange.getStartOffset(), textRange.getEndOffset(), attributes, false, dummy);
final RangeHighlighter h = dummy.get(0);
highlighters.add(h);
h.putUserData(SEARCH_MARKER, YES);
return h;
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class LivePreview method highlightUsages.
private void highlightUsages() {
if (mySearchResults.getEditor() == null)
return;
if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit())
return;
for (FindResult range : mySearchResults.getOccurrences()) {
if (range.getEndOffset() > mySearchResults.getEditor().getDocument().getTextLength())
continue;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
if (range.getLength() == 0) {
attributes = attributes.clone();
attributes.setEffectType(EffectType.BOXED);
attributes.setEffectColor(attributes.getBackgroundColor());
}
if (mySearchResults.isExcluded(range)) {
highlightRange(range, strikeout(), myHighlighters);
} else {
highlightRange(range, attributes, myHighlighters);
}
}
updateInSelectionHighlighters();
if (!myListeningSelection) {
mySearchResults.getEditor().getSelectionModel().addSelectionListener(this);
myListeningSelection = true;
}
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class LivePreview method updateCursorHighlighting.
private void updateCursorHighlighting() {
hideBalloon();
if (myCursorHighlighter != null) {
HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), myCursorHighlighter);
myCursorHighlighter = null;
}
final FindResult cursor = mySearchResults.getCursor();
Editor editor = mySearchResults.getEditor();
if (cursor != null && cursor.getEndOffset() <= editor.getDocument().getTextLength()) {
Set<RangeHighlighter> dummy = new HashSet<>();
Color color = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
highlightRange(cursor, new TextAttributes(null, null, color, EffectType.ROUNDED_BOX, Font.PLAIN), dummy);
if (!dummy.isEmpty()) {
myCursorHighlighter = dummy.iterator().next();
}
editor.getScrollingModel().runActionOnScrollingFinished(() -> showReplacementPreview());
}
}
use of com.intellij.openapi.editor.markup.TextAttributes in project intellij-community by JetBrains.
the class CallerChooserBase method updateEditorTexts.
private void updateEditorTexts(final MethodNodeBase<M> node) {
final MethodNodeBase<M> parentNode = getCalleeNode(node);
final MethodNodeBase<M> callerNode = getCallerNode(node);
final String callerText = node != myRoot ? getText(callerNode.getMethod()) : getEmptyCallerText();
final Document callerDocument = myCallerEditor.getDocument();
final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : getEmptyCalleeText();
final Document calleeDocument = myCalleeEditor.getDocument();
ApplicationManager.getApplication().runWriteAction(() -> {
callerDocument.setText(callerText);
calleeDocument.setText(calleeText);
});
final M caller = callerNode.getMethod();
final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null;
if (caller != null && caller.isPhysical() && callee != null) {
HighlightManager highlighter = HighlightManager.getInstance(myProject);
EditorColorsManager colorManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
int start = getStartOffset(caller);
for (PsiElement element : findElementsToHighlight(caller, callee)) {
highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start, element.getTextRange().getEndOffset() - start, attributes, false, null);
}
}
}
Aggregations