aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartlomiej Moskal <bartlomiej.moskal@qt.io>2021-01-19 10:41:48 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-18 08:01:44 +0000
commit69ae7eb1abee9e8d212c7277076285fe15a47f08 (patch)
tree49bfc07b157ba004641e47f0ad7e560e46a5465a
parentbe794a433489b2d580abbfb8f54cc2a26a5aa92b (diff)
qquicktextinput: Fix Undo history for IM event
Do not set m_cursor (cursor position) before calling removeSelectedText() in processInputMethodEvent(QInputMethodEvent *) method. Before this change, DeleteSelection command was added to history with new cursor position. If this command will be later rolled back, cursor position will not be set correctly. It should be set to position before handling the event. Task-number: QTBUG-90239 Change-Id: Ib5e46d232e6b32f904e745da4f9e5bc03a58963f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 6ec8c62ca22c363fa00e085de10198a90e3d65dc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquicktextinput.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index daa92d8d20..253ab9d3fb 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -3429,17 +3429,19 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
if (event->replacementStart() <= 0)
c += event->commitString().length() - qMin(-event->replacementStart(), event->replacementLength());
- m_cursor += event->replacementStart();
- if (m_cursor < 0)
- m_cursor = 0;
+ int cursorInsertPos = m_cursor + event->replacementStart();
+ if (cursorInsertPos < 0)
+ cursorInsertPos = 0;
// insert commit string
if (event->replacementLength()) {
- m_selstart = m_cursor;
+ m_selstart = cursorInsertPos;
m_selend = m_selstart + event->replacementLength();
m_selend = qMin(m_selend, m_text.length());
removeSelectedText();
}
+ m_cursor = cursorInsertPos;
+
if (!event->commitString().isEmpty()) {
internalInsert(event->commitString());
cursorPositionChanged = true;