From 4b126550c11b0f8b448e2787404f908044e967af Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 9 Nov 2022 10:58:44 +0100 Subject: [PATCH] Editor: completely repaint annotations on changed bounding rects If the rectangle of an annotation changes we need to completely redraw the annotation since the content might have shifted and the eliding character is now at a different position. Fixes: QTCREATORBUG-28411 Change-Id: I41b0f38a73b287e6a5d5318ba797aac6e2ff71b0 Reviewed-by: Eike Ziller --- src/plugins/texteditor/texteditor.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 6982ccbeb83..56627add292 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -687,6 +687,8 @@ public: { QRectF rect; const TextMark *mark; + friend bool operator==(const AnnotationRect &a, const AnnotationRect &b) + { return a.mark == b.mark && a.rect == b.rect; } }; QMap> m_annotationRects; QRectF getLastLineLineRect(const QTextBlock &block); @@ -4020,7 +4022,7 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data, const PaintEventBlockData &blockData, QPainter &painter) { - m_annotationRects.remove(data.block.blockNumber()); + const QList previousRects = m_annotationRects.take(data.block.blockNumber()); if (!m_displaySettings.m_displayAnnotations) return; @@ -4080,6 +4082,7 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data, } } + QList newRects; for (const TextMark *mark : std::as_const(marks)) { boundingRect = QRectF(x, boundingRect.top(), q->viewport()->width() - x, boundingRect.height()); if (boundingRect.isEmpty()) @@ -4094,8 +4097,16 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data, x = boundingRect.right(); offset = itemOffset / 2; - m_annotationRects[data.block.blockNumber()].append({boundingRect, mark}); + newRects.append({boundingRect, mark}); } + + if (previousRects != newRects) { + for (const AnnotationRect &annotationRect : qAsConst(newRects)) + q->viewport()->update(annotationRect.rect.toAlignedRect()); + for (const AnnotationRect &annotationRect : previousRects) + q->viewport()->update(annotationRect.rect.toAlignedRect()); + } + m_annotationRects[data.block.blockNumber()] = newRects; } QColor blendRightMarginColor(const FontSettings &settings, bool areaColor)