From 27441054197d0ecff6b83e7e6511e0d6955f4593 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 8 Dec 2011 14:52:19 +0200 Subject: Protect QAbstractTextDocumentLayout::anchorAt() from preedit Previously the method didn't take into account that hitTest() returns visual index, i.e. containing the preedit, and thus was easily hitting assertion. Need to compensate for that before checking for actual link. Change-Id: I119e7f91088b4db9d347a3da338f6df915ce9719 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qabstracttextdocumentlayout.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp index 589c0f701f..e14cfe0f82 100644 --- a/src/gui/text/qabstracttextdocumentlayout.cpp +++ b/src/gui/text/qabstracttextdocumentlayout.cpp @@ -577,6 +577,21 @@ QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const if (cursorPos == -1) return QString(); + // compensate for preedit in the hit text block + QTextBlock block = document()->firstBlock(); + while (block.isValid()) { + QRectF blockBr = blockBoundingRect(block); + if (blockBr.contains(pos)) { + QTextLayout *layout = block.layout(); + int relativeCursorPos = cursorPos - block.position(); + const int preeditLength = layout ? layout->preeditAreaText().length() : 0; + if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition()) + cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength); + break; + } + block = block.next(); + } + QTextDocumentPrivate *pieceTable = qobject_cast(parent())->docHandle(); QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos); QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format); -- cgit v1.2.3