diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2021-06-08 15:25:09 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-21 15:07:18 +0000 |
commit | f273b5b7080ea2aca92d98594c5af0f61268b6c7 (patch) | |
tree | 584a1c5614f98279798d7fa9fbfc031d11a9fa03 | |
parent | 0f810a6befdfa228a9c74714bcffc54e99ad1220 (diff) |
Fix processing of hard Qt::Key_Backspace and Qt::Key_Delete
Even though the virtual keyboard does not support hard keys at the
moment, this kind of processing could be possible in the future.
In the mean time, fix processing of backspace and delete keys.
In particular, if such key is pressed the pre-edit text is not empty:
- Reset input method state (should not modify pre-edit)
- Clear pre-edit
- Return true (to indicate no further processing is required)
[ChangeLog] Fix processing of hard backspace and delete keys.
Fixes: QTBUG-94017
Change-Id: I7035f7612e966de6d17d92e754ecd7bdb3a6e530
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
(cherry picked from commit ca5b712dfc8e67aece0eb7374ffe5921e2aa45e8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp | 14 | ||||
-rw-r--r-- | tests/auto/inputpanel/data/tst_inputpanel.qml | 24 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp index 6a394128..e6bc3fdb 100644 --- a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp +++ b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp @@ -519,6 +519,7 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) QEvent::Type type = event->type(); if (type == QEvent::KeyPress || type == QEvent::KeyRelease) { const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event); + const int key = keyEvent->key(); // Keep track of pressed keys update key event state if (type == QEvent::KeyPress) @@ -532,7 +533,6 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) setState(State::KeyEvent); #ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION - int key = keyEvent->key(); if ((key >= Qt::Key_Left && key <= Qt::Key_Down) || key == Qt::Key_Return) { if (type == QEvent::KeyPress && platformInputContext->isInputPanelVisible()) { activeNavigationKeys += key; @@ -547,8 +547,16 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) #endif // Break composing text since the virtual keyboard does not support hard keyboard events - if (!preeditText.isEmpty()) - commit(); + if (!preeditText.isEmpty()) { + if (type == QEvent::KeyPress && (key == Qt::Key_Delete || key == Qt::Key_Backspace)) { + reset(); + Q_Q(QVirtualKeyboardInputContext); + q->clear(); + return true; + } else { + commit(); + } + } } #ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION else if (type == QEvent::ShortcutOverride) { diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index 91394bea..7496ba40 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -329,6 +329,30 @@ Rectangle { compare(textInput.text, "A") } + function test_hardKeyBackspaceClearsInput_data() { + return [ + { initLocale: "en_GB", initText: "12345", initCursorPosition: 1, inputSequence: "hello", outputText: "12345", expectedCursorPosition: 1 }, + ] + } + + function test_hardKeyBackspaceClearsInput(data) { + prepareTest(data) + + if (!inputPanel.wordCandidateListVisibleHint) + skip("Prediction/spell correction not enabled") + + compare(Qt.inputMethod.locale.name, Qt.locale(data.initLocale).name) + for (var inputIndex in data.inputSequence) { + verify(inputPanel.virtualKeyClick(data.inputSequence[inputIndex])) + } + + keyClick(Qt.Key_Backspace) + waitForRendering(textInput) + + compare(textInput.text, data.outputText) + compare(textInput.cursorPosition, data.expectedCursorPosition) + } + function test_hardKeyInput() { prepareTest() |