From 89873c8d4fe856cc79fa2fd4eeef28db29732772 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Mon, 8 Jun 2020 00:21:18 +0300 Subject: [PATCH] IDEA-242325 Incorrect speed search highlighting in structure dialog GitOrigin-RevId: 801bc67304612c704311d936151a2cd694e87971 --- .../intellij/ide/util/gotoByName/GotoActionModel.java | 2 ++ .../src/com/intellij/ui/SimpleColoredComponent.java | 11 ++++++++--- .../com/intellij/ui/speedSearch/SpeedSearchUtil.java | 1 + .../src/com/intellij/ide/ui/search/SearchUtil.java | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 49ee63c639f9..391be41923d0 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -970,9 +970,11 @@ public class GotoActionModel implements ChooseByNameModel, Comparator, D SimpleTextAttributes plain = new SimpleTextAttributes(STYLE_PLAIN, fg); SimpleTextAttributes highlighted = new SimpleTextAttributes(null, fg, null, STYLE_SEARCH_MATCH); List fragments = new ArrayList<>(); + nameComponent.setDynamicSearchMatchHighlighting(false); if (selected) { int matchStart = StringUtil.indexOfIgnoreCase(name, pattern, 0); if (matchStart >= 0) { + nameComponent.setDynamicSearchMatchHighlighting(true); fragments.add(TextRange.from(matchStart, pattern.length())); } } diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 666f3db86442..c068b02f5e41 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -96,6 +96,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co private boolean myIconOnTheRight; private boolean myTransparentIconBackground; + private boolean myDynamicSearchMatchHighlighting; public SimpleColoredComponent() { myFragments = new ArrayList<>(3); @@ -879,7 +880,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co Color fgColor; if (attributes.isSearchMatch()) { fgColor = new JBColor(Gray._50, Gray._0); - UIUtil.drawSearchMatch(g, x1, x2 + 1, height); + UIUtil.drawSearchMatch(g, x1, x2, height); } else if (attributes.isClickable()) { boolean selected = UIUtil.getTreeSelectionBackground(true) == getBackground(); @@ -903,7 +904,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co } private boolean drawWithClipping(int index, Graphics2D g, Font font, float x1, float x2, float baseline) { - if (!SystemInfo.isMacOSCatalina) return false; + if (!SystemInfo.isMacOSCatalina || !myDynamicSearchMatchHighlighting) return false; ColoredFragment fragment = myFragments.get(index); if (!fragment.attributes.isSearchMatch()) return false; ColoredFragment prevFragment = index > 0 ? myFragments.get(index - 1) : null; @@ -921,7 +922,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co + (nextFragment != null ? nextFragment.text : ""); Graphics2D clippedGraphics = (Graphics2D)g.create(); try { - clippedGraphics.setClip(new Rectangle2D.Float(x1, 0, x2 - x1 + 1, getHeight())); + clippedGraphics.setClip(new Rectangle2D.Float(x1, 0, x2 - x1, getHeight())); if (prevFragment != null) x1 -= computeStringWidth(prevFragment, font); clippedGraphics.drawString(mergedText, x1, baseline); @@ -1051,6 +1052,10 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co myTransparentIconBackground = transparentIconBackground; } + public void setDynamicSearchMatchHighlighting(boolean dynamicSearchMatchHighlighting) { + myDynamicSearchMatchHighlighting = dynamicSearchMatchHighlighting; + } + public static int getTextBaseLine(@NotNull FontMetrics metrics, final int height) { // adding leading to ascent, just like in editor (leads to bad presentation for certain fonts with Oracle JDK, see IDEA-167541) return (height - metrics.getHeight()) / 2 + metrics.getAscent() + diff --git a/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java b/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java index dfa10e02510b..776779b4c0eb 100644 --- a/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java +++ b/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java @@ -108,6 +108,7 @@ public final class SpeedSearchUtil { } final Iterable iterable = ((MinusculeMatcher)matcher).matchingFragments(text); + component.setDynamicSearchMatchHighlighting(iterable != null); if (iterable != null) { final Color fg = attributes.getFgColor(); final int style = attributes.getStyle(); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java index ad73f0863a8d..07548b6a3483 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java @@ -468,9 +468,11 @@ public final class SearchUtil { return; } if (filter == null || filter.length() == 0) { + textRenderer.setDynamicSearchMatchHighlighting(false); textRenderer.append(text, new SimpleTextAttributes(background, foreground, JBColor.RED, style)); } else { + textRenderer.setDynamicSearchMatchHighlighting(true); //markup ObjectOpenHashSet quoted = new ObjectOpenHashSet<>(); filter = processFilter(quoteStrictOccurrences(text, filter), quoted);