From bc7194648792a354cc5d4b1673043908dcc15d0e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 27 Jun 2018 10:35:16 +0200 Subject: [PATCH] Don't position cursor inside complex graphemes when clicking outside line If you clicked to the right of a text line ended with a grapheme consisting of several characters, either because it was a unicode surrogate pair or a ligature, we would always to the previous character in logical order, without checking if this was a valid cursor position. One result of this would be that hitting backspace when the cursor was positioned in an invalid position, would cause the entire contents of the document to become invalid. Instead we should search backwards for the previous grapheme boundary using QTextEngine::previousLogicalPosition(). [ChangeLog][QtGui][Text] Fixed position of text cursor set by clicking outside the bounds of a text line that ends with a surrogate pair or ligature. Task-number: QTBUG-69085 Change-Id: I7224c065f332f398bdfbb3f42b2b3ec8280c76a4 Reviewed-by: Simon Hausmann --- src/gui/text/qtextlayout.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 860d1e8c7c..ca6866d836 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -3002,9 +3002,8 @@ int QTextLine::xToCursor(qreal _x, CursorPosition cpos) const // character between lines is a space and we want // to position the cursor to the left of that // character. - // ###### breaks with japanese for example if (this->index < eng->lines.count() - 1) - --maxPos; + maxPos = eng->previousLogicalPosition(maxPos); pos = qMin(pos, maxPos); return pos;