WEB-20496 regression - bold text in injected regions

This commit is contained in:
Dmitry Batrak
2016-02-26 11:28:20 +03:00
parent 0cacfe0176
commit 44e465682f
7 changed files with 44 additions and 19 deletions
@@ -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));
}
}
@@ -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);
}
}
@@ -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()));
@@ -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()]);
Binary file not shown.

After

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

@@ -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);
}
}