use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class IdentifierHighlighterPass method getHighlights.
private List<HighlightInfo> getHighlights() {
if (myReadAccessRanges.isEmpty() && myWriteAccessRanges.isEmpty()) {
return Collections.emptyList();
}
Set<Pair<Object, TextRange>> existingMarkupTooltips = new HashSet<>();
for (RangeHighlighter highlighter : myEditor.getMarkupModel().getAllHighlighters()) {
existingMarkupTooltips.add(Pair.create(highlighter.getErrorStripeTooltip(), new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset())));
}
List<HighlightInfo> result = new ArrayList<>(myReadAccessRanges.size() + myWriteAccessRanges.size());
for (TextRange range : myReadAccessRanges) {
ContainerUtil.addIfNotNull(result, createHighlightInfo(range, HighlightInfoType.ELEMENT_UNDER_CARET_READ, existingMarkupTooltips));
}
for (TextRange range : myWriteAccessRanges) {
ContainerUtil.addIfNotNull(result, createHighlightInfo(range, HighlightInfoType.ELEMENT_UNDER_CARET_WRITE, existingMarkupTooltips));
}
return result;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class IndentsPass method createHighlighter.
@NotNull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
highlighter.setCustomRenderer(RENDERER);
return highlighter;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LineMarkersUtil method setLineMarkersToEditor.
static void setLineMarkersToEditor(@NotNull Project project, @NotNull Document document, @NotNull Segment bounds, @NotNull Collection<LineMarkerInfo> markers, int group) {
ApplicationManager.getApplication().assertIsDispatchThread();
MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
HighlightersRecycler toReuse = new HighlightersRecycler();
processLineMarkers(project, document, bounds, group, info -> {
toReuse.recycleHighlighter(info.highlighter);
return true;
});
if (LOG.isDebugEnabled()) {
List<LineMarkerInfo> oldMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
LOG.debug("LineMarkersUtil.setLineMarkersToEditor(markers: " + markers + ", group: " + group + "); oldMarkers: " + oldMarkers + "; reused: " + toReuse.forAllInGarbageBin().size());
}
for (final LineMarkerInfo info : markers) {
PsiElement element = info.getElement();
if (element == null) {
continue;
}
TextRange textRange = element.getTextRange();
if (textRange == null)
continue;
TextRange elementRange = InjectedLanguageManager.getInstance(project).injectedToHost(element, textRange);
if (!TextRange.containsRange(bounds, elementRange)) {
continue;
}
createOrReuseLineMarker(info, markupModel, toReuse);
}
for (RangeHighlighter highlighter : toReuse.forAllInGarbageBin()) {
highlighter.dispose();
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ErrorStripeHandler method errorMarkerClicked.
@Override
public void errorMarkerClicked(@NotNull ErrorStripeEvent e) {
RangeHighlighter highlighter = e.getHighlighter();
if (!highlighter.isValid())
return;
HighlightInfo info = findInfo(highlighter);
if (info != null) {
GotoNextErrorHandler.navigateToError(myProject, e.getEditor(), info);
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class FindManagerImpl method highlightNextHighlighter.
private static boolean highlightNextHighlighter(RangeHighlighter[] highlighters, Editor editor, int offset, boolean isForward, boolean secondPass) {
RangeHighlighter highlighterToSelect = null;
Object wasNotFound = editor.getUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY);
for (RangeHighlighter highlighter : highlighters) {
int start = highlighter.getStartOffset();
int end = highlighter.getEndOffset();
if (highlighter.isValid() && start < end) {
if (isForward && (start > offset || start == offset && secondPass)) {
if (highlighterToSelect == null || highlighterToSelect.getStartOffset() > start)
highlighterToSelect = highlighter;
}
if (!isForward && (end < offset || end == offset && secondPass)) {
if (highlighterToSelect == null || highlighterToSelect.getEndOffset() < end)
highlighterToSelect = highlighter;
}
}
}
if (highlighterToSelect != null) {
expandFoldRegionsIfNecessary(editor, highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
editor.getSelectionModel().setSelection(highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
editor.getCaretModel().moveToOffset(highlighterToSelect.getStartOffset());
ScrollType scrollType;
if (secondPass) {
scrollType = isForward ? ScrollType.CENTER_UP : ScrollType.CENTER_DOWN;
} else {
scrollType = isForward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
}
editor.getScrollingModel().scrollToCaret(scrollType);
editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, null);
return true;
}
if (wasNotFound == null) {
editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, Boolean.TRUE);
String message = FindBundle.message("find.highlight.no.more.highlights.found");
if (isForward) {
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
if (shortcutsText.isEmpty()) {
message = FindBundle.message("find.search.again.from.top.action.message", message);
} else {
message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
}
} else {
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS);
String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
if (shortcutsText.isEmpty()) {
message = FindBundle.message("find.search.again.from.bottom.action.message", message);
} else {
message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message, shortcutsText);
}
}
JComponent component = HintUtil.createInformationLabel(message);
final LightweightHint hint = new LightweightHint(component);
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
return true;
}
if (!secondPass) {
offset = isForward ? 0 : editor.getDocument().getTextLength();
return highlightNextHighlighter(highlighters, editor, offset, isForward, true);
}
return false;
}
Aggregations