aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextcontrol.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2023-08-02 22:19:13 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2023-09-12 20:00:28 +0200
commitc1d5e46ea79762bfcc070fabbf10ff7fdf184e01 (patch)
tree00bcb946f7950c8a396e763ce52d45d925c18782 /src/quick/items/qquicktextcontrol.cpp
parent4044e232b1e57e835e7863f1f8c3ffeab09b1c7e (diff)
TextEdit/TextArea: don't deselect on release if IM just selected text
After 90d3fac73a10b9363fd34e6757cc730d7a0c086c we got a regression on Android at least: if you long-press to select a word, selection handles appear; then when you release, there's a QTouchEvent which is left unhandled, and then a synth-mouse release. In this case, we don't want to call setCursorPosition(), because it de-selects the selection that was just made by the input method. But the intention was to be able to set the cursor position (and also deselect text) by tapping on a touchscreen on other platforms that don't have text selection handles. (It seems to be consistent with Android behavior: there you can also deselect and move the cursor by simply tapping.) To avoid changing that behavior, we now set a flag if we get a mouse press and then a QInputMethodEvent with a Selection attribute, indicating that text got selected that way; and in that case, don't call setCursorPosition(). Fixes: QTBUG-115004 Pick-to: 6.5 6.6 Change-Id: I7e362da584f6e1cb1509dcc0eff024b291ef5df3 Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextcontrol.cpp')
-rw-r--r--src/quick/items/qquicktextcontrol.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp
index 929ce10136..510ece726a 100644
--- a/src/quick/items/qquicktextcontrol.cpp
+++ b/src/quick/items/qquicktextcontrol.cpp
@@ -81,6 +81,7 @@ QQuickTextControlPrivate::QQuickTextControlPrivate()
cursorRectangleChanged(false),
hoveredMarker(false),
selectByTouchDrag(false),
+ imSelectionAfterPress(false),
lastSelectionStart(-1),
lastSelectionEnd(-1)
{}
@@ -992,6 +993,7 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po
mousePressed = (interactionFlags & Qt::TextSelectableByMouse) && (e->button() & Qt::LeftButton);
mousePressPos = pos.toPoint();
+ imSelectionAfterPress = false;
if (sendMouseEventToInputContext(e, pos))
return;
@@ -1177,7 +1179,7 @@ void QQuickTextControlPrivate::mouseReleaseEvent(QMouseEvent *e, const QPointF &
q->insertFromMimeData(md);
#endif
}
- if (!isMouse && !selectByTouchDrag && interactionFlags.testFlag(Qt::TextEditable))
+ if (!isMouse && !selectByTouchDrag && !imSelectionAfterPress && interactionFlags.testFlag(Qt::TextEditable))
setCursorPosition(pos);
repaintOldAndNewSelection(oldSelection);
@@ -1322,6 +1324,8 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
for (int i = 0; i < e->attributes().size(); ++i) {
const QInputMethodEvent::Attribute &a = e->attributes().at(i);
if (a.type == QInputMethodEvent::Selection) {
+ if (mousePressed)
+ imSelectionAfterPress = true;
QTextCursor oldCursor = cursor;
int blockStart = a.start + cursor.block().position();
cursor.setPosition(blockStart, QTextCursor::MoveAnchor);