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 <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-11-09 10:58:44 +01:00
parent 80885d12e0
commit 4b126550c1

View File

@@ -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<int, QList<AnnotationRect>> 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<AnnotationRect> previousRects = m_annotationRects.take(data.block.blockNumber());
if (!m_displaySettings.m_displayAnnotations)
return;
@@ -4080,6 +4082,7 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data,
}
}
QList<AnnotationRect> 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)