Fix selecting single character in middle of string
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Wed, 29 Jul 2015 12:27:58 +0000 (14:27 +0200)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Mon, 3 Aug 2015 07:18:52 +0000 (07:18 +0000)
The fix for QTBUG-46829 revealed a bug in the code to handle
selecting part of ligatures. The ranges were assumed to be
[start, end], while they are in fact [start, end>. This would
cause the engine to assume the previous node overlapped completely
with the selected node and that the node had thus already been
added to the graph.

Due to the bug in QTBUG-46829, this accidentally worked before,
but when that bug was fixed, this bug appeared.

Change-Id: I517d260de9f58db4504dd4320b7113fbbe305a81
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quick/items/qquicktextnodeengine.cpp
tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml [new file with mode: 0644]

index 5140ccb68f96ce2120ab7a98a46305c59aa3e1fe..efe79b382e6c39247028b163e4702befabe14589 100644 (file)
@@ -821,14 +821,14 @@ void  QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode,
                 for (int i = 0; i < node->ranges.size(); ++i) {
                     const QPair<int, int> &range = node->ranges.at(i);
 
-                    int rangeLength = range.second - range.first + 1;
+                    int rangeLength = range.second - range.first;
                     if (previousNode != 0) {
                         for (int j = 0; j < previousNode->ranges.size(); ++j) {
                             const QPair<int, int> &otherRange = previousNode->ranges.at(j);
-                            if (range.first <= otherRange.second && range.second >= otherRange.first) {
+                            if (range.first < otherRange.second && range.second > otherRange.first) {
                                 int start = qMax(range.first, otherRange.first);
                                 int end = qMin(range.second, otherRange.second);
-                                rangeLength -= end - start + 1;
+                                rangeLength -= end - start;
                                 if (rangeLength == 0)
                                     break;
                             }
@@ -839,10 +839,10 @@ void  QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode,
                         for (int j = 0; j < nextNode->ranges.size(); ++j) {
                             const QPair<int, int> &otherRange = nextNode->ranges.at(j);
 
-                            if (range.first <= otherRange.second && range.second >= otherRange.first) {
+                            if (range.first < otherRange.second && range.second > otherRange.first) {
                                 int start = qMax(range.first, otherRange.first);
                                 int end = qMin(range.second, otherRange.second);
-                                rangeLength -= end - start + 1;
+                                rangeLength -= end - start;
                                 if (rangeLength == 0)
                                     break;
                             }
diff --git a/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml b/tests/manual/scenegraph_lancelot/data/text/textedit_cyrillic_selected.qml
new file mode 100644 (file)
index 0000000..849e4b8
--- /dev/null
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+
+Item {
+    width: 320
+    height: 480
+    TextEdit {
+        id: textEdit
+        text: "и в у"
+        anchors.centerIn: parent
+        Component.onCompleted: textEdit.select(2, 3)
+        font.pixelSize: 14
+    }
+}