From 33c358e5766b488b866381a4195d178c1e5be655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20My=C3=B6h=C3=A4nen?= Date: Tue, 16 Jun 2020 12:01:58 +0300 Subject: 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 (cherry picked from commit 5760593c66928c77b193a8502b8433e122980bc1) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/openwnn/plugin/openwnninputmethod.cpp | 2 ++ tests/auto/inputpanel/data/tst_inputpanel.qml | 33 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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. -- cgit v1.2.3