aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Myöhänen <janne.myohanen@code-q.fi>2020-06-16 12:01:58 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-06-23 08:56:20 +0000
commit33c358e5766b488b866381a4195d178c1e5be655 (patch)
treea1eadafbd6861dedf53bb1f698ca8890369c937c
parent1d4f747311bce953c527969cb8f2016ffd21209b (diff)
Fix cursor position in Japanese input
Fix cursor position in Japanese input when suggestion is selected. The selected text is set as preedit text just before committing. Fixes: QTBUG-74664 Change-Id: I7d1dd35fad8b844f5849c3006145c69792ce8725 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 5760593c66928c77b193a8502b8433e122980bc1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/openwnn/plugin/openwnninputmethod.cpp2
-rw-r--r--tests/auto/inputpanel/data/tst_inputpanel.qml33
2 files changed, 35 insertions, 0 deletions
diff --git a/src/plugins/openwnn/plugin/openwnninputmethod.cpp b/src/plugins/openwnn/plugin/openwnninputmethod.cpp
index d6206732..efe68a1e 100644
--- a/src/plugins/openwnn/plugin/openwnninputmethod.cpp
+++ b/src/plugins/openwnn/plugin/openwnninputmethod.cpp
@@ -805,6 +805,8 @@ void OpenWnnInputMethod::selectionListItemSelected(QVirtualKeyboardSelectionList
{
Q_UNUSED(type)
Q_D(OpenWnnInputMethod);
+ // Set selected text as preeditText to place cursor at the end of selected text
+ inputContext()->setPreeditText(d->candidateList.at(index)->candidate);
d->commitText(*d->candidateList.at(index));
}
diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml
index 44a718c0..9bb1e086 100644
--- a/tests/auto/inputpanel/data/tst_inputpanel.qml
+++ b/tests/auto/inputpanel/data/tst_inputpanel.qml
@@ -1195,6 +1195,39 @@ Rectangle {
compare(textInput.cursorPosition, data.expectedCursorPosition)
}
+ function test_japaneseInputSelectionCursorPosition_data() {
+ return [
+ // Selection for first word of text
+ { initLocale: "ja_JP", initInputMode: "Hiragana", inputSequence: ["i"], expectedCandidates: [ "\u3044\u3064\u3082" ], outputText: "\u3044\u3064\u3082", expectedCursorPosition: 3 },
+ // Selection for last word of text
+ { initLocale: "ja_JP", initInputMode: "Hiragana", inputSequence: ["i",Qt.Key_Space,Qt.Key_Return,Qt.Key_Space,"i"], expectedCandidates: [ "\u3044\u3064\u3082" ], outputText: "\u3044\u3000\u3044\u3064\u3082", expectedCursorPosition: 5 },
+ // Selection for word in middle of text
+ { initLocale: "ja_JP", initInputMode: "Hiragana", inputSequence: [
+ // Input two words
+ "i",Qt.Key_Space,Qt.Key_Return,Qt.Key_Space,"i",Qt.Key_Space,Qt.Key_Return,
+ // Move betwen the words and add space
+ Qt.Key_Left,Qt.Key_Left,Qt.Key_Space,
+ // Input first letter of new word
+ "i"], expectedCandidates: [ "\u3044\u3064\u3082" ], outputText: "\u3044\u3000\u3044\u3064\u3082\u3000\u3044", expectedCursorPosition: 5 }
+ ]
+ }
+
+ function test_japaneseInputSelectionCursorPosition(data) {
+ prepareTest(data, true)
+
+ for (var inputIndex in data.inputSequence) {
+ verify(inputPanel.virtualKeyClick(data.inputSequence[inputIndex]))
+ }
+ waitForRendering(inputPanel)
+
+ for (var candidateIndex in data.expectedCandidates) {
+ verify(inputPanel.selectionListSearchSuggestion(data.expectedCandidates[candidateIndex]))
+ verify(inputPanel.selectionListSelectCurrentItem())
+ }
+
+ compare(textInput.cursorPosition, data.expectedCursorPosition)
+ }
+
function test_baseKeyNoModifier() {
// The Japanese keyboard uses the BaseKey.noModifier flag for the arrow keys.
// Without this flag the arrow key + shift would extend the text selection.