From 5fe2ed48d60f383706274fa087f08a041c79dc73 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 26 Sep 2018 11:59:32 +0200 Subject: Fix scrollbar updates in QPlaintTextEdit on block-visibility changes Trigger documentSizeChanged when block visibility changes, since block count remains constant in this case. Task-number: QTBUG-69310 Change-Id: I5ec7a4f9008f26ea8602356bcbaefbda293e54a3 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qplaintextedit.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/widgets/widgets/qplaintextedit.cpp') diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 91fcaa48cf..d6f6a364a8 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -294,6 +294,7 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c QTextBlock changeStartBlock = doc->findBlock(from); QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsChanged - 1)); + bool blockVisibilityChanged = false; if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) { QTextBlock block = changeStartBlock; @@ -311,14 +312,18 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c QTextBlock block = changeStartBlock; do { block.clearLayout(); + const int lineCount = block.isVisible() ? 1 : 0; + if (block.lineCount() != lineCount) { + blockVisibilityChanged = true; + block.setLineCount(lineCount); + } if (block == changeEndBlock) break; block = block.next(); } while(block.isValid()); } - if (newBlockCount != d->blockCount) { - + if (newBlockCount != d->blockCount || blockVisibilityChanged) { int changeEnd = changeEndBlock.blockNumber(); int blockDiff = newBlockCount - d->blockCount; int oldChangeEnd = changeEnd - blockDiff; -- cgit v1.2.3