From a3d039f0f74ce99a51d98ae55633210471312804 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 21 Jul 2015 13:01:48 +0300 Subject: [PATCH] IDEA-142898 Strike-through effect should change color the same way as the font --- .../intellij/ui/SimpleColoredComponent.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index a03071e72180..4605a7d17143 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -813,9 +813,8 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co g.setStroke(g.getStroke()); // 1. Strikeout effect - if (attributes.isStrikeout()) { - final int strikeOutAt = textBaseline + (baseMetrics.getDescent() - baseMetrics.getAscent()) / 2; - UIUtil.drawLine(g, offset, strikeOutAt, offset + fragmentWidth, strikeOutAt); + if (attributes.isStrikeout() && !attributes.isSearchMatch()) { + drawStrikeout(g, offset, offset + fragmentWidth, textBaseline); } // 2. Waved effect if (attributes.isWaved()) { @@ -837,7 +836,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co } if (attributes.isSearchMatch()) { - searchMatches.add(new Object[]{offset, offset + fragmentWidth, textBaseline, fragment, g.getFont()}); + searchMatches.add(new Object[]{offset, offset + fragmentWidth, textBaseline, fragment, g.getFont(), attributes}); } offset = endOffset; @@ -855,20 +854,34 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co // draw search matches after all for (final Object[] info : searchMatches) { - UIUtil.drawSearchMatch(g, (Integer)info[0], (Integer)info[1], getHeight()); + Integer x1 = (Integer)info[0]; + Integer x2 = (Integer)info[1]; + UIUtil.drawSearchMatch(g, x1, x2, getHeight()); g.setFont((Font)info[4]); + Integer baseline = (Integer)info[2]; + String text = (String)info[3]; if (shouldDrawMacShadow()) { g.setColor(SHADOW_COLOR); - g.drawString((String)info[3], (Integer)info[0], (Integer)info[2] + 1); + g.drawString(text, x1, baseline + 1); } g.setColor(new JBColor(Gray._50, Gray._0)); - g.drawString((String)info[3], (Integer)info[0], (Integer)info[2]); + g.drawString(text, x1, baseline); + + if (((SimpleTextAttributes)info[5]).isStrikeout()) { + drawStrikeout(g, x1, x2, baseline); + } } return offset; } + private static void drawStrikeout(Graphics g, int x1, int x2, int y) { + // magic of determining character height + int strikeOutAt = y - g.getFontMetrics().charWidth('a') / 2; + UIUtil.drawLine(g, x1, strikeOutAt, x2, strikeOutAt); + } + private int computeTextAlignShift(@NotNull Font font) { if (myTextAlign == SwingConstants.LEFT || myTextAlign == SwingConstants.LEADING) { return 0;