diff options
author | David Schulz <[email protected]> | 2025-09-09 14:38:29 +0200 |
---|---|---|
committer | David Schulz <[email protected]> | 2025-09-11 05:14:15 +0000 |
commit | 8ef92a38e09f26b732f829c0ce6c9617f8ad7c09 (patch) | |
tree | ad7e73f6698f2d7680d6c29586baff4529f6766b | |
parent | 4917cdba5871d208ea8e77d642f57bb274c68fd6 (diff) |
Editor: fix overlay painting for wrapped blocks
Change-Id: Ifa6077ddf349a671a8f6bd91d75904ac6f4a237e
Reviewed-by: Christian Stenger <[email protected]>
-rw-r--r-- | src/plugins/texteditor/texteditoroverlay.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp index 2f3a35daa39..e7cc02107d3 100644 --- a/src/plugins/texteditor/texteditoroverlay.cpp +++ b/src/plugins/texteditor/texteditoroverlay.cpp @@ -11,6 +11,7 @@ #include <QTextBlock> #include <algorithm> +#include <utils/plaintextedit/texteditorlayout.h> #include <utils/qtcassert.h> using namespace TextEditor; @@ -126,12 +127,15 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co if (block.blockNumber() < m_editor->firstVisibleBlock().blockNumber() - 1) block = document->findBlockByNumber(m_editor->firstVisibleBlock().blockNumber() - 1); + auto layout = [this](const QTextBlock &block){ + return m_editor->editorLayout()->blockLayout(block); + }; + if (begin.position() == end.position()) { // special case empty selections const QRectF blockGeometry = m_editor->blockBoundingGeometry(block); - QTextLayout *blockLayout = block.layout(); int pos = begin.position() - begin.block().position(); - QTextLine line = blockLayout->lineForTextPosition(pos); + QTextLine line = layout(block)->lineForTextPosition(pos); QTC_ASSERT(line.isValid(), return {}); QRectF lineRect = line.naturalTextRect(); lineRect = lineRect.translated(blockGeometry.topLeft()); @@ -155,15 +159,16 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co continue; const QRectF blockGeometry = m_editor->blockBoundingGeometry(block); - QTextLayout *blockLayout = block.layout(); + QTextLayout *blockLayout = layout(block); int firstLine = 0; int beginChar = 0; if (block == begin.block()) { beginChar = begin.positionInBlock(); - const QString preeditAreaText = begin.block().layout()->preeditAreaText(); - if (!preeditAreaText.isEmpty() && beginChar >= begin.block().layout()->preeditAreaPosition()) + QTextLayout *beginLayout = layout(begin.block()); + const QString preeditAreaText = beginLayout->preeditAreaText(); + if (!preeditAreaText.isEmpty() && beginChar >= beginLayout->preeditAreaPosition()) beginChar += preeditAreaText.length(); QTextLine line = blockLayout->lineForTextPosition(beginChar); QTC_ASSERT(line.isValid(), return {}); @@ -177,8 +182,9 @@ QPainterPath TextEditorOverlay::createSelectionPath(const QTextCursor &begin, co int endChar = -1; if (block == end.block()) { endChar = end.positionInBlock(); - const QString preeditAreaText = end.block().layout()->preeditAreaText(); - if (!preeditAreaText.isEmpty() && endChar >= end.block().layout()->preeditAreaPosition()) + QTextLayout *endLayout = layout(end.block()); + const QString preeditAreaText = endLayout->preeditAreaText(); + if (!preeditAreaText.isEmpty() && endChar >= endLayout->preeditAreaPosition()) endChar += preeditAreaText.length(); QTextLine line = blockLayout->lineForTextPosition(endChar); QTC_ASSERT(line.isValid(), return {}); |