use of com.intellij.ui.LightweightHint 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;
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class ShowContainerInfoHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
PsiElement container = null;
WeakReference<LightweightHint> ref = editor.getUserData(MY_LAST_HINT_KEY);
LightweightHint hint = SoftReference.dereference(ref);
if (hint != null && hint.isVisible()) {
hint.hide();
container = hint.getUserData(CONTAINER_KEY);
if (container != null && !container.isValid()) {
container = null;
}
}
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(editor);
boolean goOneLevelUp = true;
try {
if (container == null) {
goOneLevelUp = false;
Object element = model.getCurrentEditorElement();
if (element instanceof PsiElement) {
container = (PsiElement) element;
}
}
} finally {
model.dispose();
}
while (true) {
if (container == null || container instanceof PsiFile) {
return;
}
if (goOneLevelUp) {
goOneLevelUp = false;
} else {
if (!isDeclarationVisible(container, editor)) {
break;
}
}
container = container.getParent();
while (container != null && DeclarationRangeUtil.getPossibleDeclarationAtRange(container) == null) {
container = container.getParent();
if (container instanceof PsiFile)
return;
}
}
}
if (container == null) {
return;
}
final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container);
if (range == null) {
return;
}
final PsiElement _container = container;
ApplicationManager.getApplication().invokeLater(() -> {
LightweightHint hint1 = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true);
if (hint1 != null) {
hint1.putUserData(CONTAINER_KEY, _container);
editor.putUserData(MY_LAST_HINT_KEY, new WeakReference<>(hint1));
}
});
}
use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.
the class BraceHighlightingHandler method clearBraceHighlighters.
void clearBraceHighlighters() {
List<RangeHighlighter> highlighters = getHighlightersList();
for (final RangeHighlighter highlighter : highlighters) {
highlighter.dispose();
}
highlighters.clear();
LightweightHint hint = myEditor.getUserData(HINT_IN_EDITOR_KEY);
if (hint != null) {
hint.hide();
myEditor.putUserData(HINT_IN_EDITOR_KEY, null);
}
}
Aggregations