private void paintSelectionOnFirstSoftWrapLineIfNecessary(
      Graphics2D g, int columnStart, float xStart, float xEnd, int y) {
    VisualPosition selectionStartPosition =
        myEditor.getSelectionModel().getSelectionStartPosition();
    VisualPosition selectionEndPosition = myEditor.getSelectionModel().getSelectionEndPosition();
    int visualLine = myView.yToVisualLine(y);

    if (selectionStartPosition.equals(selectionEndPosition)
        || visualLine < selectionStartPosition.line
        || visualLine > selectionEndPosition.line
        || visualLine == selectionEndPosition.line && selectionEndPosition.column <= columnStart) {
      return;
    }

    float startX =
        selectionStartPosition.line == visualLine && selectionStartPosition.column > columnStart
            ? myView.visualPositionToXY(selectionStartPosition).x
            : xStart;
    float endX =
        selectionEndPosition.line == visualLine
            ? myView.visualPositionToXY(selectionEndPosition).x
            : xEnd;

    paintBackground(
        g,
        myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR),
        startX,
        y,
        endX - startX);
  }
 private void paintVirtualSelectionIfNecessary(
     Graphics2D g,
     Map<Integer, Couple<Integer>> virtualSelectionMap,
     int columnStart,
     float xStart,
     float xEnd,
     int y) {
   int visualLine = myView.yToVisualLine(y);
   Couple<Integer> selectionRange = virtualSelectionMap.get(visualLine);
   if (selectionRange == null || selectionRange.second <= columnStart) return;
   float startX =
       selectionRange.first <= columnStart
           ? xStart
           : myView.visualPositionToXY(new VisualPosition(visualLine, selectionRange.first)).x;
   float endX =
       Math.min(
           xEnd,
           myView.visualPositionToXY(new VisualPosition(visualLine, selectionRange.second)).x);
   paintBackground(
       g,
       myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR),
       startX,
       y,
       endX - startX);
 }
  void paint(Graphics2D g) {
    Rectangle clip = g.getClipBounds();

    if (myEditor.getContentComponent().isOpaque()) {
      g.setColor(myEditor.getBackgroundColor());
      g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }

    if (paintPlaceholderText(g)) {
      paintCaret(g);
      return;
    }

    int startLine = myView.yToVisualLine(Math.max(clip.y, 0));
    int endLine = myView.yToVisualLine(Math.max(clip.y + clip.height, 0));
    int startOffset = myView.visualPositionToOffset(new VisualPosition(startLine, 0));
    int endOffset = myView.visualPositionToOffset(new VisualPosition(endLine + 1, 0, true));
    ClipDetector clipDetector = new ClipDetector(myEditor, clip);

    paintBackground(g, clip, startLine, endLine);
    paintRightMargin(g, clip);
    paintCustomRenderers(g, startOffset, endOffset);
    MarkupModelEx docMarkup =
        (MarkupModelEx) DocumentMarkupModel.forDocument(myDocument, myEditor.getProject(), true);
    paintLineMarkersSeparators(g, clip, docMarkup, startOffset, endOffset);
    paintLineMarkersSeparators(g, clip, myEditor.getMarkupModel(), startOffset, endOffset);
    paintTextWithEffects(g, clip, startLine, endLine);
    paintHighlightersAfterEndOfLine(g, docMarkup, startOffset, endOffset);
    paintHighlightersAfterEndOfLine(g, myEditor.getMarkupModel(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getHighlighter(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, docMarkup, startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getMarkupModel(), startOffset, endOffset);

    paintCaret(g);

    paintComposedTextDecoration(g);
  }