From 4ebf6981db3d2d0b434716f55d5f1ff6ac062a07 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 5 Feb 2020 13:23:59 +0100 Subject: [PATCH] Editor: Update viewport margin if extra area width differs Change-Id: I305bde817f70ac4b84054d04170700ef10f090cd Fixes: QTCREATORBUG-23238 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditor.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 2a5b885aca6..de814476295 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -564,7 +564,7 @@ public: void transformSelectedLines(ListTransformationMethod method); - void slotUpdateExtraAreaWidth(); + void slotUpdateExtraAreaWidth(Utils::optional width = {}); void slotUpdateRequest(const QRect &r, int dy); void slotUpdateBlockNotify(const QTextBlock &); void updateTabStops(); @@ -4925,15 +4925,21 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const if (d->m_codeFoldingVisible) space += foldBoxWidth(fm); + + if (viewportMargins() != QMargins{isLeftToRight() ? space : 0, 0, isLeftToRight() ? 0 : space, 0}) + d->slotUpdateExtraAreaWidth(space); + return space; } -void TextEditorWidgetPrivate::slotUpdateExtraAreaWidth() +void TextEditorWidgetPrivate::slotUpdateExtraAreaWidth(optional width) { + if (!width.has_value()) + width = q->extraAreaWidth(); if (q->isLeftToRight()) - q->setViewportMargins(q->extraAreaWidth(), 0, 0, 0); + q->setViewportMargins(*width, 0, 0, 0); else - q->setViewportMargins(0, 0, q->extraAreaWidth(), 0); + q->setViewportMargins(0, 0, *width, 0); } struct Internal::ExtraAreaPaintEventData