diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index f653e03c68b..1b0128350d0 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -397,7 +397,7 @@ public: bool expanded, bool active, bool hovered) const; - void drawLineAnnotation(QPainter &painter, const QTextBlock &block, qreal start, const QRect &eventRect); + void updateLineAnnotation(QPainter &painter, const QTextBlock &block, qreal start, const QRect &eventRect); void toggleBlockVisible(const QTextBlock &block); QRect foldBox(); @@ -3866,9 +3866,11 @@ QRectF TextEditorWidgetPrivate::getLastLineLineRect(const QTextBlock &block) return line.naturalTextRect().translated(contentOffset.x(), top).adjusted(0, 0, -1, -1); } -void TextEditorWidgetPrivate::drawLineAnnotation( +void TextEditorWidgetPrivate::updateLineAnnotation( QPainter &painter, const QTextBlock &block, qreal rightMargin, const QRect &eventRect) { + m_annotationRects.remove(block.blockNumber()); + if (!m_displaySettings.m_displayAnnotations) return; @@ -3912,9 +3914,9 @@ void TextEditorWidgetPrivate::drawLineAnnotation( boundingRect = QRectF(x, lineRect.top(), q->viewport()->width() - x, lineRect.height()); if (boundingRect.isEmpty()) break; + if (eventRect.intersects(boundingRect.toRect())) + mark->paintAnnotation(painter, &boundingRect, offset, itemOffset / 2, q->contentOffset()); - // paint annotation - mark->paintAnnotation(painter, &boundingRect, offset, itemOffset / 2, q->contentOffset()); x = boundingRect.right(); offset = itemOffset / 2; m_annotationRects[block.blockNumber()].append({boundingRect, mark}); @@ -4426,10 +4428,8 @@ void TextEditorWidget::paintEvent(QPaintEvent *e) || d->m_blockSelection.positionColumn == d->m_blockSelection.anchorColumn) && blockSelectionCursorRect.isValid()) painter.fillRect(blockSelectionCursorRect, palette().text()); - - d->m_annotationRects.remove(block.blockNumber()); - d->drawLineAnnotation(painter, block, lineX < viewportRect.width() ? lineX : 0, er); } + d->updateLineAnnotation(painter, block, lineX < viewportRect.width() ? lineX : 0, er); offset.ry() += r.height();