mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -26,19 +26,45 @@ import java.awt.geom.*;
|
||||
* @author Sergey.Malenkov
|
||||
*/
|
||||
public enum EffectPainter implements RegionPainter<Paint> {
|
||||
WAVE {
|
||||
/**
|
||||
* @see com.intellij.openapi.editor.markup.EffectType#LINE_UNDERSCORE
|
||||
*/
|
||||
LINE_UNDERSCORE {
|
||||
@Override
|
||||
public void paint(Graphics2D g, int x, int y, int width, int height, Paint paint) {
|
||||
// we assume here that Y is a baseline of a text
|
||||
if (!Registry.is("ide.text.effect.line.new")) {
|
||||
g.setPaint(paint);
|
||||
g.drawLine(x, y + 1, x + width, y + 1);
|
||||
}
|
||||
else if (paint != null && width > 0 && height > 0) {
|
||||
g.setPaint(paint);
|
||||
int h = height < 4 ? 2 : height >> 1;
|
||||
double pos = Registry.doubleValue("ide.text.effect.line.new.pos");
|
||||
y += (int)((double)height - h * pos);
|
||||
g.setPaint(paint);
|
||||
g.drawLine(x, y, x + width, y);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @see com.intellij.openapi.editor.markup.EffectType#WAVE_UNDERSCORE
|
||||
*/
|
||||
WAVE_UNDERSCORE {
|
||||
private final BasicStroke STROKE = new BasicStroke(.7f);
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g, int x, int y, int width, int height, Paint paint) {
|
||||
// we assume here that Y is a baseline of a text
|
||||
if (!Registry.is("ide.text.effect.wave.new")) {
|
||||
g.setPaint(paint);
|
||||
WavePainter.forColor(g.getColor()).paint(g, x, x + width, y + height);
|
||||
}
|
||||
else if (paint != null && width > 0 && height > 0) {
|
||||
if (!Registry.is("ide.text.effect.wave.new.scale")) {
|
||||
y += height - 3;
|
||||
height = 3;
|
||||
int h = height < 4 ? 2 : Registry.is("ide.text.effect.wave.new.scale") ? height >> 1 : 3;
|
||||
if (h != height) {
|
||||
y += height - h;
|
||||
height = h;
|
||||
}
|
||||
g = (Graphics2D)g.create(x, y, width, height);
|
||||
g.clipRect(0, 0, width, height);
|
||||
|
||||
@@ -833,12 +833,11 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
|
||||
}
|
||||
// 2. Waved effect
|
||||
if (attributes.isWaved()) {
|
||||
EffectPainter.WAVE.paint(g, offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()), attributes.getWaveColor());
|
||||
EffectPainter.WAVE_UNDERSCORE.paint(g, offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()), attributes.getWaveColor());
|
||||
}
|
||||
// 3. Underline
|
||||
if (attributes.isUnderline()) {
|
||||
final int underlineAt = textBaseline + 1;
|
||||
UIUtil.drawLine(g, offset, underlineAt, offset + fragmentWidth, underlineAt);
|
||||
EffectPainter.LINE_UNDERSCORE.paint(g, offset, textBaseline, fragmentWidth, metrics.getDescent(), g.getColor());
|
||||
}
|
||||
// 4. Bold Dotted Line
|
||||
if (attributes.isBoldDottedLine()) {
|
||||
|
||||
@@ -2413,7 +2413,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
int y = visibleLineToY(visibleStartLine) + getAscent() + 1;
|
||||
g.setColor(attributes.getEffectColor());
|
||||
if (attributes.getEffectType() == EffectType.WAVE_UNDERSCORE) {
|
||||
EffectPainter.WAVE.paint((Graphics2D)g, end.x, y, charWidth - 1, getDescent() - 1, attributes.getEffectColor());
|
||||
EffectPainter.WAVE_UNDERSCORE.paint((Graphics2D)g, end.x, y - 1, charWidth - 1, getDescent(), attributes.getEffectColor());
|
||||
}
|
||||
else if (attributes.getEffectType() == EffectType.BOLD_DOTTED_LINE) {
|
||||
final int dottedAt = SystemInfo.isMac ? y - 1 : y;
|
||||
@@ -2428,7 +2428,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
drawBoldLineUnderScore(g, end.x, y - 1, charWidth - 1);
|
||||
}
|
||||
else if (attributes.getEffectType() != EffectType.BOXED) {
|
||||
UIUtil.drawLine(g, end.x, y, end.x + charWidth - 1, y);
|
||||
EffectPainter.LINE_UNDERSCORE.paint((Graphics2D)g, end.x, y - 1, charWidth - 1, getDescent(), attributes.getEffectColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3546,8 +3546,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
}
|
||||
|
||||
if (effectType == EffectType.LINE_UNDERSCORE) {
|
||||
g.setColor(effectColor);
|
||||
UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
|
||||
EffectPainter.LINE_UNDERSCORE.paint((Graphics2D)g, xStart, y, xEnd - xStart, getDescent(), effectColor);
|
||||
g.setColor(savedColor);
|
||||
}
|
||||
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
|
||||
@@ -3562,7 +3561,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
g.setColor(savedColor);
|
||||
}
|
||||
else if (effectType == EffectType.WAVE_UNDERSCORE) {
|
||||
EffectPainter.WAVE.paint((Graphics2D)g, xStart, y + 1, xEnd - xStart, getDescent() - 1, effectColor);
|
||||
EffectPainter.WAVE_UNDERSCORE.paint((Graphics2D)g, xStart, y, xEnd - xStart, getDescent(), effectColor);
|
||||
g.setColor(savedColor);
|
||||
}
|
||||
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
|
||||
|
||||
@@ -429,7 +429,7 @@ class EditorPainter implements TextDrawingCallback {
|
||||
int xEnd = (int)xTo;
|
||||
g.setColor(effectColor);
|
||||
if (effectType == EffectType.LINE_UNDERSCORE) {
|
||||
UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
|
||||
EffectPainter.LINE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), effectColor);
|
||||
}
|
||||
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
|
||||
int height = JBUI.scale(Registry.intValue("editor.bold.underline.height", 2));
|
||||
@@ -440,7 +440,7 @@ class EditorPainter implements TextDrawingCallback {
|
||||
UIUtil.drawLine(g, xStart, y1, xEnd, y1);
|
||||
}
|
||||
else if (effectType == EffectType.WAVE_UNDERSCORE) {
|
||||
EffectPainter.WAVE.paint(g, xStart, y + 1, xEnd - xStart, myView.getDescent() - 1, effectColor);
|
||||
EffectPainter.WAVE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), effectColor);
|
||||
}
|
||||
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
|
||||
UIUtil.drawBoldDottedLine(g, xStart, xEnd, SystemInfo.isMac ? y : y + 1, myEditor.getBackgroundColor(), g.getColor(), false);
|
||||
|
||||
@@ -761,6 +761,10 @@ cidr.xcode.derived.data.override.description=Ignore Xcode DerivedData location s
|
||||
editor.rainbow.identifiers=false
|
||||
editor.rainbow.identifiers.description=Rainbow identifiers in editor
|
||||
|
||||
ide.text.effect.line.new=false
|
||||
ide.text.effect.line.new.description=Enables new line painter for text
|
||||
ide.text.effect.line.new.pos=0.5
|
||||
ide.text.effect.line.new.pos.description=Changes a line position
|
||||
ide.text.effect.wave.new=false
|
||||
ide.text.effect.wave.new.description=Enables new wave painter for text
|
||||
ide.text.effect.wave.new.scale=false
|
||||
|
||||
@@ -33,6 +33,8 @@ public class XmlFoldingTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
|
||||
public void testEntities() throws Throwable { doTest(); }
|
||||
|
||||
public void testDataUri() throws Throwable { doTest(); }
|
||||
|
||||
private void doTest() throws Throwable {
|
||||
doTest(".html");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<!doctype html>
|
||||
<img src="<fold text='data:'>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==</fold>" alt="Red dot" />
|
||||
@@ -34,6 +34,7 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
import com.intellij.xml.util.XmlTagUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -225,6 +226,9 @@ public abstract class XmlCodeFoldingBuilder implements FoldingBuilder, DumbAware
|
||||
@Override
|
||||
public String getPlaceholderText(@NotNull ASTNode node) {
|
||||
final PsiElement psi = node.getPsi();
|
||||
if (psi instanceof XmlAttribute && "src".equalsIgnoreCase(((XmlAttribute)psi).getName())) {
|
||||
return "data:";
|
||||
}
|
||||
if (psi instanceof XmlTag ||
|
||||
psi instanceof XmlComment ||
|
||||
psi instanceof XmlAttribute ||
|
||||
@@ -255,10 +259,18 @@ public abstract class XmlCodeFoldingBuilder implements FoldingBuilder, DumbAware
|
||||
final PsiElement psi = node.getPsi();
|
||||
final XmlCodeFoldingSettings foldingSettings = getFoldingSettings();
|
||||
return (psi instanceof XmlTag && foldingSettings.isCollapseXmlTags())
|
||||
|| (psi instanceof XmlAttribute && foldingSettings.isCollapseHtmlStyleAttribute())
|
||||
|| (psi instanceof XmlAttribute && (foldStyle((XmlAttribute)psi, foldingSettings) || foldSrc((XmlAttribute)psi, foldingSettings)))
|
||||
|| isEntity(psi) && foldingSettings.isCollapseEntities();
|
||||
}
|
||||
|
||||
private static boolean foldSrc(XmlAttribute psi, XmlCodeFoldingSettings settings) {
|
||||
return settings.isCollapseDataUri() && "src".equals(psi.getName());
|
||||
}
|
||||
|
||||
private static boolean foldStyle(XmlAttribute psi, XmlCodeFoldingSettings settings) {
|
||||
return settings.isCollapseHtmlStyleAttribute() && HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(psi.getName());
|
||||
}
|
||||
|
||||
protected boolean isEntity(PsiElement psi) {
|
||||
return psi instanceof XmlEntityRef ||
|
||||
(psi instanceof XmlTokenImpl && ((XmlTokenImpl)psi).getElementType() == XmlTokenType.XML_CHAR_ENTITY_REF);
|
||||
@@ -266,7 +278,8 @@ public abstract class XmlCodeFoldingBuilder implements FoldingBuilder, DumbAware
|
||||
|
||||
private static boolean isAttributeShouldBeFolded(XmlAttribute child) {
|
||||
return HtmlUtil.isHtmlFile(child.getContainingFile()) &&
|
||||
HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(child.getName());
|
||||
(HtmlUtil.STYLE_ATTRIBUTE_NAME.equalsIgnoreCase(child.getName()) ||
|
||||
"src".equals(child.getName()) && child.getValue() != null && URLUtil.isDataUri(child.getValue()));
|
||||
}
|
||||
|
||||
protected abstract XmlCodeFoldingSettings getFoldingSettings();
|
||||
|
||||
Reference in New Issue
Block a user