diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2016-11-12 22:00:48 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-11-25 09:59:45 +0000 |
commit | 98aa04821f6b851a990f3fc0e1ac29291d28de14 (patch) | |
tree | cda4f3395181e7b5f8676252e641b65ea1172be6 | |
parent | 13a199e6e2c5f27b0f12eff380df4f0c0d156e6e (diff) |
Fix duplicate shift state change when focus object changes
Previously the shift state could be set twice when focus object changed,
first in reset() method and then in autoCapitalize() method.
This change eliminates the initial shift state in reset() method.
Task-number: QTBUG-57082
Change-Id: I4bba5c85aae1d0d631e7e30577d0d4068c9cc582
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/virtualkeyboard/shifthandler.cpp | 8 | ||||
-rw-r--r-- | tests/auto/inputpanel/data/inputpanel/inputpanel.qml | 7 | ||||
-rw-r--r-- | tests/auto/inputpanel/data/tst_inputpanel.qml | 21 |
3 files changed, 33 insertions, 3 deletions
diff --git a/src/virtualkeyboard/shifthandler.cpp b/src/virtualkeyboard/shifthandler.cpp index 69735665..22302129 100644 --- a/src/virtualkeyboard/shifthandler.cpp +++ b/src/virtualkeyboard/shifthandler.cpp @@ -191,10 +191,13 @@ void ShiftHandler::reset() autoCapitalizationEnabled = false; toggleShiftEnabled = false; } - d->inputContext->setShift(preferUpperCase); - d->inputContext->setCapsLock(preferUpperCase); setToggleShiftEnabled(toggleShiftEnabled); setAutoCapitalizationEnabled(autoCapitalizationEnabled); + d->inputContext->setCapsLock(preferUpperCase); + if (preferUpperCase) + d->inputContext->setShift(preferUpperCase); + else + autoCapitalize(); } } @@ -227,7 +230,6 @@ void ShiftHandler::autoCapitalize() void ShiftHandler::restart() { reset(); - autoCapitalize(); } void ShiftHandler::shiftChanged() diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml index 5f864445..9586a736 100644 --- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml +++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml @@ -72,6 +72,7 @@ InputPanel { property alias soundEffectSpy: soundEffectSpy property alias inputMethodResultSpy: inputMethodResultSpy property alias wordCandidateListChangedSpy: wordCandidateListChangedSpy + property alias shiftStateSpy: shiftStateSpy signal inputMethodResult(var text) @@ -151,6 +152,12 @@ InputPanel { signalName: "dataChanged" } + SignalSpy { + id: shiftStateSpy + target: InputContext + signalName: "onShiftChanged" + } + function findChildByProperty(parent, propertyName, propertyValue, compareCb) { var obj = null if (parent === null) diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index 85de31d4..919597a1 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -363,6 +363,27 @@ Rectangle { compare(textInput.text, data.outputText) } + function test_focusAndShiftState() { + prepareTest() + + // Initial focus is set to textInput, shift state should not change + // when focus is set to container + inputPanel.shiftStateSpy.clear() + container.forceActiveFocus() + compare(inputPanel.shiftStateSpy.count, 0, "Unexpected number of shift state changes after focus change (ImhNone -> ImhNone)") + + // Change to lower case + inputPanel.shiftStateSpy.clear() + inputPanel.toggleShift() + compare(inputPanel.shiftStateSpy.count, 1, "Unexpected number of shift state changes after shift key press") + + // Set focus back to textInput, and expect that shift state is changed + // to auto upper case + inputPanel.shiftStateSpy.clear() + textInput.forceActiveFocus() + compare(inputPanel.shiftStateSpy.count, 1, "Unexpected number of shift state changes after focus change (auto upper case)") + } + function test_symbolMode() { prepareTest({ initInputMethodHints: Qt.ImhNoPredictiveText }) |