void (@NotNull Graphics g, @NotNull Point position, @NotNull Rectangle clip, @NotNull Color defaultBackground, @JdkConstants.FontStyle int fontType) { // There is a possible case that the user performed selection at soft wrap virtual space. We need to paint corresponding background // there then. VisualPosition selectionStartPosition = getSelectionStartPositionForPaint(); VisualPosition selectionEndPosition = getSelectionEndPositionForPaint(); if (selectionStartPosition.equals(selectionEndPosition)) { return; } int currentVisualLine = position.y / getLineHeight(); int lastColumn = EditorUtil.getLastVisualLineColumnNumber(this, currentVisualLine); // Check if the first soft wrap line is within the visual selection. if (currentVisualLine < selectionStartPosition.line || currentVisualLine > selectionEndPosition.line || currentVisualLine == selectionEndPosition.line && selectionEndPosition.column <= lastColumn) { return; } // Adjust 'x' if selection starts at soft wrap virtual space. final int columnsToSkip = selectionStartPosition.column - lastColumn; if (columnsToSkip > 0) { position.x += getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED); position.x += (columnsToSkip - 1) * EditorUtil.getSpaceWidth(Font.PLAIN, this); } // Calculate selection width. final int width; if (selectionEndPosition.line > currentVisualLine) { width = clip.x + clip.width - position.x; } else if (selectionStartPosition.line < currentVisualLine || selectionStartPosition.column <= lastColumn) { width = getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED) + (selectionEndPosition.column - lastColumn - 1) * EditorUtil.getSpaceWidth(fontType, this); } else { width = (selectionEndPosition.column - selectionStartPosition.column) * EditorUtil.getSpaceWidth(fontType, this); } drawBackground(g, getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), width, position, defaultBackground, clip); }