highlight element on breadcrumb hover

#WEB-427 fixed
This commit is contained in:
Dennis Ushakov
2014-10-29 23:44:32 +03:00
parent e71fc0b172
commit 4e8756970c
4 changed files with 36 additions and 8 deletions
@@ -16,6 +16,8 @@
package com.intellij.xml.breadcrumbs;
import com.intellij.application.options.editor.WebEditorOptions;
import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.XmlTagTreeHighlightingUtil;
import com.intellij.codeInsight.highlighting.HighlightManager;
import com.intellij.ide.ui.UISettings;
import com.intellij.ide.ui.UISettingsListener;
import com.intellij.lang.Language;
@@ -25,10 +27,14 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorFontType;
import com.intellij.openapi.editor.event.CaretAdapter;
import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
@@ -52,10 +58,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.*;
/**
* @author spleaner
@@ -64,6 +67,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
private final BreadcrumbsComponent<BreadcrumbsPsiItem> myComponent;
private final Project myProject;
private Editor myEditor;
private Collection<RangeHighlighter> myHighlighed;
private final VirtualFile myFile;
private boolean myUserCaretChange;
private final MergingUpdateQueue myQueue;
@@ -383,6 +387,27 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
}
}
@Override
public void itemHovered(@Nullable BreadcrumbsPsiItem item) {
if (myHighlighed != null) {
for (RangeHighlighter highlighter : myHighlighed) {
HighlightManager.getInstance(myProject).removeSegmentHighlighter(myEditor, highlighter);
}
myHighlighed = null;
}
if (item != null) {
final TextRange range = item.getPsiElement().getTextRange();
final TextAttributes attributes = new TextAttributes();
final CrumbPresentation p = item.getPresentation();
final Color color = p != null ? p.getBackgroundColor(false, false, false) : BreadcrumbsComponent.ButtonSettings.DEFAULT_BG_COLOR;
final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR);
attributes.setBackgroundColor(XmlTagTreeHighlightingUtil.makeTransparent(color, background, 0.3));
myHighlighed = new ArrayList<RangeHighlighter>(1);
HighlightManager.getInstance(myProject).addRangeHighlight(myEditor, range.getStartOffset(), range.getEndOffset(),
attributes, true, true, myHighlighed);
}
}
@Nullable
public static BreadcrumbsXmlWrapper getBreadcrumbsComponent(@NotNull Editor editor) {
return editor.getUserData(BREADCRUMBS_COMPONENT_KEY);
@@ -121,6 +121,9 @@ public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent
}
myHovered = crumb;
for (BreadcrumbsItemListener listener : myListeners) {
listener.itemHovered(myHovered != null ? myHovered.myItem : null);
}
repaint();
}
@@ -16,12 +16,12 @@
package com.intellij.xml.breadcrumbs;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author spleaner
*/
public interface BreadcrumbsItemListener<T extends BreadcrumbsItem> {
void itemSelected(@NotNull final T item, final int modifiers);
void itemHovered(@Nullable final T item);
}
@@ -33,7 +33,7 @@ import java.util.Set;
/**
* @author Eugene.Kudelevsky
*/
class XmlTagTreeHighlightingUtil {
public class XmlTagTreeHighlightingUtil {
private XmlTagTreeHighlightingUtil() {
}
@@ -76,7 +76,7 @@ class XmlTagTreeHighlightingUtil {
return false;
}
static Color makeTransparent(@NotNull Color color, @NotNull Color backgroundColor, double transparency) {
public static Color makeTransparent(@NotNull Color color, @NotNull Color backgroundColor, double transparency) {
int r = makeTransparent(transparency, color.getRed(), backgroundColor.getRed());
int g = makeTransparent(transparency, color.getGreen(), backgroundColor.getGreen());
int b = makeTransparent(transparency, color.getBlue(), backgroundColor.getBlue());