Skip to content

Commit

Permalink
Fix cursor not showing in empty block preceding a table
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ville Voutilainen <[email protected]>
  • Loading branch information
Kari Hormi committed Oct 14, 2019
1 parent 689405f commit 79d7487
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/gui/text/qtextdocumentlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 79d7487

Please sign in to comment.