void (@NotNull Graphics g, int x, int y, int width, Caret caret) { int lineHeight = getLineHeight(); Rectangle viewRectangle = getScrollingModel().getVisibleArea(); if (x - viewRectangle.x < 0) { return; } g.setColor(myScheme.getColor(EditorColors.CARET_COLOR)); Graphics2D originalG = IdeBackgroundUtil.getOriginalGraphics(g); if (!paintBlockCaret()) { if (UIUtil.isRetina()) { originalG.fillRect(x, y, mySettings.getLineCursorWidth(), lineHeight); } else { g.fillRect(x, y, JBUI.scale(mySettings.getLineCursorWidth()), lineHeight); } } else { Color caretColor = myScheme.getColor(EditorColors.CARET_COLOR); if (caretColor == null) caretColor = new JBColor(Gray._0, Gray._255); g.setColor(caretColor); originalG.fillRect(x, y, width, lineHeight - 1); final LogicalPosition startPosition = caret == null ? getCaretModel().getLogicalPosition() : caret.getLogicalPosition(); final int offset = logicalPositionToOffset(startPosition); CharSequence chars = myDocument.getImmutableCharSequence(); if (chars.length() > offset && myDocument.getTextLength() > offset) { FoldRegion folding = myFoldingModel.getCollapsedRegionAtOffset(offset); final char ch; if (folding == null || folding.isExpanded()) { ch = chars.charAt(offset); } else { VisualPosition visual = caret == null ? getCaretModel().getVisualPosition() : caret.getVisualPosition(); VisualPosition foldingPosition = offsetToVisualPosition(folding.getStartOffset()); if (visual.line == foldingPosition.line) { ch = folding.getPlaceholderText().charAt(visual.column - foldingPosition.column); } else { ch = chars.charAt(offset); } } //don't worry it's cheap. Cache is not required IterationState state = new IterationState(EditorImpl.this, offset, offset + 1, true); TextAttributes attributes = state.getMergedAttributes(); FontInfo info = EditorUtil.fontForChar(ch, attributes.getFontType(), EditorImpl.this); g.setFont(info.getFont()); //todo[kb] //in case of italic style we paint out of the cursor block. Painting the symbol to a dedicated buffered image //solves the problem, but still looks weird because it leaves colored pixels at right. g.setColor(ColorUtil.isDark(caretColor) ? CURSOR_FOREGROUND_LIGHT : CURSOR_FOREGROUND_DARK); g.drawChars(new char[]{ch}, 0, 1, x, y + getAscent()); } } }