Fix cursor not showing in empty block preceding a table

When an empty text block precedes a table in QTextEdit, the cursor in
the said text block is drawn twice (in order to make sure that the
cursor is drawn on top of the table) with inverted colors, resulting in
nothing showing up. This commit checks for an empty block before the table
and skips the first drawing of the cursor if that's what it finds.

Fixes: QTBUG-62919
Change-Id: I828d06e0645007ac42e3f308a35868b4f0db1380
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
bb10
Kari Hormi 2019-10-10 17:49:43 +03:00
parent 689405fb5c
commit 79d7487c89
1 changed files with 6 additions and 2 deletions

View File

@ -1336,8 +1336,12 @@ void QTextDocumentLayoutPrivate::drawBlock(const QPointF &offset, QPainter *pain
tl->draw(painter, offset, selections, context.clip.isValid() ? (context.clip & clipRect) : clipRect);
if ((context.cursorPosition >= blpos && context.cursorPosition < blpos + bllen)
|| (context.cursorPosition < -1 && !tl->preeditAreaText().isEmpty())) {
// if the block is empty and it precedes a table, do not draw the cursor.
// the cursor is drawn later after the table has been drawn so no need
// to draw it here.
if (!isEmptyBlockBeforeTable(frameIteratorForTextPosition(blpos))
&& ((context.cursorPosition >= blpos && context.cursorPosition < blpos + bllen)
|| (context.cursorPosition < -1 && !tl->preeditAreaText().isEmpty()))) {
int cpos = context.cursorPosition;
if (cpos < -1)
cpos = tl->preeditAreaPosition() - (cpos + 2);