diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java index c54c9e36756c..be9708f1ca91 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java @@ -102,7 +102,10 @@ class RangeHighlighterImpl extends RangeMarkerImpl implements RangeHighlighterEx public void setTextAttributes(@NotNull TextAttributes textAttributes) { TextAttributes old = myTextAttributes; myTextAttributes = textAttributes; - if (!Comparing.equal(old, textAttributes)) { + if (old != textAttributes && (old == TextAttributes.ERASE_MARKER || textAttributes == TextAttributes.ERASE_MARKER)) { + fireChanged(false, true); + } + else if (!Comparing.equal(old, textAttributes)) { fireChanged(false, getFontStyle(old) != getFontStyle(textAttributes)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java index b61f936d7d09..7ca257da3030 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java @@ -29,6 +29,7 @@ import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry; import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.editor.impl.FontInfo; import com.intellij.openapi.editor.impl.IterationState; +import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.editor.textarea.TextComponentEditor; import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl; import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; @@ -887,6 +888,10 @@ public final class EditorUtil { int endOffset = editor.logicalPositionToOffset(position); return editor.getSoftWrapModel().getSoftWrapsForRange(startOffset, endOffset).size(); } + + public static boolean attributesImpactFontStyle(@Nullable TextAttributes attributes) { + return attributes == TextAttributes.ERASE_MARKER || (attributes != null && attributes.getFontType() != Font.PLAIN); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 5502668ecc8c..d56a23d4e629 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -376,12 +376,14 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } @Override public void afterAdded(@NotNull RangeHighlighterEx highlighter) { - attributesChanged(highlighter, areRenderersInvolved(highlighter), false); + attributesChanged(highlighter, areRenderersInvolved(highlighter), + EditorUtil.attributesImpactFontStyle(highlighter.getTextAttributes())); } @Override public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) { - attributesChanged(highlighter, areRenderersInvolved(highlighter), false); + attributesChanged(highlighter, areRenderersInvolved(highlighter), + EditorUtil.attributesImpactFontStyle(highlighter.getTextAttributes())); } @Override @@ -409,8 +411,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int startLine = start == -1 ? 0 : myDocument.getLineNumber(start); int endLine = end == -1 ? myDocument.getLineCount() : myDocument.getLineNumber(end); - TextAttributes attributes = highlighter.getTextAttributes(); - if (myUseNewRendering && start != end && (fontStyleChanged || attributes != null && attributes.getFontType() != Font.PLAIN)) { + if (myUseNewRendering && start != end && fontStyleChanged) { myView.invalidateRange(start, end); } repaintLines(Math.max(0, startLine - 1), Math.min(endLine + 1, getDocument().getLineCount())); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/IterationState.java index 139fc74e54e9..d8bc746e2b99 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/IterationState.java @@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.ex.*; +import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.HighlighterLayer; @@ -211,8 +212,7 @@ public class IterationState { return (!onlyFullLine || ex.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) && (!onlyFontAffecting || - ex.getTextAttributes() != null && - ex.getTextAttributes().getFontType() != Font.PLAIN); + EditorUtil.attributesImpactFontStyle(ex.getTextAttributes())); } }); highlighters = list.isEmpty() ? RangeHighlighterEx.EMPTY_ARRAY : list.toArray(new RangeHighlighterEx[list.size()]); diff --git a/platform/platform-tests/testData/editor/painting/_fontBold.png b/platform/platform-tests/testData/editor/painting/_fontBold.png new file mode 100644 index 000000000000..bcac79bb09b2 Binary files /dev/null and b/platform/platform-tests/testData/editor/painting/_fontBold.png differ diff --git a/platform/platform-tests/testData/editor/painting/eraseMarker.png b/platform/platform-tests/testData/editor/painting/eraseMarker.png new file mode 100644 index 000000000000..f18656fd53e3 Binary files /dev/null and b/platform/platform-tests/testData/editor/painting/eraseMarker.png differ diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java index 0a51ff26f3ba..72bcca058e93 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java @@ -71,7 +71,7 @@ public class EditorPaintingTest extends AbstractEditorTest { public void testCaretRowWinsOverSyntaxEvenInPresenceOfHighlighter() throws Exception { initText("foo"); - ((EditorEx)myEditor).setHighlighter(new UniformHighlighter(new TextAttributes(null, Color.red, null, null, Font.PLAIN))); + setUniformEditorHighlighter(new TextAttributes(null, Color.red, null, null, Font.PLAIN)); addRangeHighlighter(0, 3, 0, null, Color.blue); checkResult(); } @@ -102,6 +102,17 @@ public class EditorPaintingTest extends AbstractEditorTest { checkResult(); } + public void testEraseMarker() throws Exception { + initText("abc"); + setUniformEditorHighlighter(new TextAttributes(null, null, null, null, Font.BOLD)); + addRangeHighlighter(1, 2, 0, TextAttributes.ERASE_MARKER); + checkResult(); + } + + private static void setUniformEditorHighlighter(TextAttributes attributes) { + ((EditorEx)myEditor).setHighlighter(new UniformHighlighter(attributes)); + } + private static void addRangeHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); } @@ -150,8 +161,9 @@ public class EditorPaintingTest extends AbstractEditorTest { editorComponent.setSize(size); //noinspection UndesirableClassUsage BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); - BitmapFont bitmapFont = BitmapFont.loadFromFile(getFontFile()); - MyGraphics graphics = new MyGraphics(image.createGraphics(), bitmapFont); + BitmapFont plainFont = BitmapFont.loadFromFile(getFontFile(false)); + BitmapFont boldFont = BitmapFont.loadFromFile(getFontFile(true)); + MyGraphics graphics = new MyGraphics(image.createGraphics(), plainFont, boldFont); try { editorComponent.paint(graphics); } @@ -194,8 +206,8 @@ public class EditorPaintingTest extends AbstractEditorTest { expectedResultsFile.getAbsolutePath(), savedImage.getAbsolutePath()); } - private static File getFontFile() { - return getTestDataFile("_font.png"); + private static File getFontFile(boolean bold) { + return getTestDataFile(bold ? "_fontBold.png" : "_font.png"); } private static File getTestDataFile(String fileName) { @@ -205,16 +217,20 @@ public class EditorPaintingTest extends AbstractEditorTest { // renders font characters to be used for text painting in tests (to make font rendering platform-independent) public static void main(String[] args) throws Exception { Font font = Font.createFont(Font.TRUETYPE_FONT, EditorPaintingTest.class.getResourceAsStream("/fonts/Inconsolata.ttf")); - BitmapFont bitmapFont = BitmapFont.createFromFont(font); - bitmapFont.saveToFile(getFontFile()); + BitmapFont plainFont = BitmapFont.createFromFont(font); + plainFont.saveToFile(getFontFile(false)); + BitmapFont boldBont = BitmapFont.createFromFont(font.deriveFont(Font.BOLD)); + boldBont.saveToFile(getFontFile(true)); } public static class MyGraphics extends Graphics2DDelegate { - private final BitmapFont myBitmapFont; + private final BitmapFont myPlainFont; + private final BitmapFont myBoldFont; - public MyGraphics(Graphics2D g2d, BitmapFont bitmapFont) { + public MyGraphics(Graphics2D g2d, BitmapFont plainFont, BitmapFont boldFont) { super(g2d); - myBitmapFont = bitmapFont; + myPlainFont = plainFont; + myBoldFont = boldFont; } @Override @@ -232,7 +248,7 @@ public class EditorPaintingTest extends AbstractEditorTest { @NotNull @Override public Graphics create() { - return new MyGraphics((Graphics2D)myDelegate.create(), myBitmapFont); + return new MyGraphics((Graphics2D)myDelegate.create(), myPlainFont, myBoldFont); } @Override @@ -252,7 +268,7 @@ public class EditorPaintingTest extends AbstractEditorTest { } private void drawChar(char c, int x, int y) { - myBitmapFont.draw(myDelegate, c, x, y); + (((getFont().getStyle() & Font.BOLD) == 0) ? myPlainFont : myBoldFont).draw(myDelegate, c, x, y); } }