diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretAttributes.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretAttributes.java new file mode 100644 index 000000000000..1a86bb64ed12 --- /dev/null +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretAttributes.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor; + +import com.intellij.openapi.util.Key; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +/** + * Used to override Caret Painting Color and for non-block carets their Width + */ +final public class CaretAttributes { + final public static Key KEY = new Key<>("CaretAttributes"); + final public static CaretAttributes NULL = new CaretAttributes(null, Weight.NORMAL); + + public enum Weight { + THIN(-1), + NORMAL(0), + HEAVY(1); + + final private int delta; + + Weight(int delta) { + this.delta = delta; + } + + public int getDelta() { + return delta; + } + } + + final private @Nullable Color myColor; + final private Weight myWeight ; + + public CaretAttributes(@Nullable Color color, Weight weight) { + myColor = color; + myWeight = weight; + } + + @Nullable + public Color getColor() { + return myColor; + } + + public Weight getWeight() { + return myWeight; + } + + public int getWidth(int width) { + return width + myWeight.delta < 1 ? 1 : width +myWeight.delta; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java index e4dfd31268ad..19b8e74e2443 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java @@ -808,13 +808,15 @@ class EditorPainter implements TextDrawingCallback { if (caretColor == null) caretColor = new JBColor(CARET_DARK, CARET_LIGHT); int minX = getMinX(); for (EditorImpl.CaretRectangle location : locations) { - g.setColor(caretColor); int x = location.myPoint.x; int y = location.myPoint.y - topOverhang; Caret caret = location.myCaret; + CaretAttributes attr = caret == null ? null : caret.getUserData(CaretAttributes.KEY); + if (attr == null) attr = CaretAttributes.NULL; + g.setColor(attr.getColor() != null ? attr.getColor() : caretColor); boolean isRtl = location.myIsRtl; if (myEditor.isInsertMode() != settings.isBlockCursor()) { - int lineWidth = JBUI.scale(settings.getLineCursorWidth()); + int lineWidth = JBUI.scale(attr.getWidth(settings.getLineCursorWidth())); // fully cover extra character's pixel which can appear due to antialiasing // see IDEA-148843 for more details if (x > minX && lineWidth > 1) x--;