Merge lp:~michael-sheldon/ubuntu-keyboard/fix-1375951 into lp:ubuntu-keyboard

Proposed by Michael Sheldon
Status: Merged
Approved by: Bill Filler
Approved revision: 236
Merged at revision: 232
Proposed branch: lp:~michael-sheldon/ubuntu-keyboard/fix-1375951
Merge into: lp:ubuntu-keyboard
Diff against target: 190 lines (+40/-22)
4 files modified
qml/keys/CharKey.qml (+3/-2)
src/plugin/inputmethod.cpp (+9/-9)
src/plugin/inputmethod.h (+1/-1)
src/view/abstracttexteditor.cpp (+27/-10)
To merge this branch: bzr merge lp:~michael-sheldon/ubuntu-keyboard/fix-1375951
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+237458@code.launchpad.net

Commit message

Fix re-entry of preedit when in the middle of a sentence, disable preedit when editing in the middle of a word and re-evaluate autocaps whenever the cursor position changes.

Description of the change

Fix re-entry of preedit when in the middle of a sentence, disable preedit when editing in the middle of a word and re-evaluate autocaps whenever the cursor position changes.

To post a comment you must log in.
Revision history for this message
Michael Sheldon (michael-sheldon) wrote :

Are there any related MPs required for this MP to build/function as expected? Please list.

 * No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)

 * Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?

 * Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/ubuntu-keyboard) on device or emulator?

 * Yes

If you changed the UI, was the change specified/approved by design?

 * No change

If you changed UI labels, did you update the pot file?

 * No change

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?

 * No change

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

Works quite well except for one issue. If you move the cursor to the end of a word and start backspacing, predit gets correctly enabled and shows word choices. The problem is when you select one (or press the space) bar, an additional space gets inserted after the word, leaving you with a double space.

Example:
"Hello brother and sister."

move cursor to end of brother
start backspacing until only "bro" is left. Then type a "t". Now select "brother" from word ribbon and you are left with:

"Hello brother and sister."

I think the fix would be to only auto insert the space if you detect we are at end of the line if that is possible?

review: Needs Fixing
234. By Michael Sheldon

Only insert spaces on autocomplete if we're not in the middle of a sentence

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
235. By Michael Sheldon

Return space behaviour to normal if the user continues typing after editing a word in the middle of a sentence.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
236. By Michael Sheldon

Don't insert spaces when editing words in the middle of sentences from word ribbon selection

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

tested, all issues fixed

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/keys/CharKey.qml'
2--- qml/keys/CharKey.qml 2014-09-26 17:41:47 +0000
3+++ qml/keys/CharKey.qml 2014-10-10 13:28:23 +0000
4@@ -206,8 +206,8 @@
5 extendedKeysSelector.closePopover();
6 }
7 } else if(!swipedOut) {
8- event_handler.onKeyReleased(valueToSubmit, action);
9-
10+ // Read this prior to altering autocaps
11+ var keyToSend = valueToSubmit;
12 if (magnifier.currentlyAssignedKey == key) {
13 magnifier.shown = false;
14 }
15@@ -222,6 +222,7 @@
16 if (switchBackFromSymbols && panel.state === "SYMBOLS") {
17 panel.state = "CHARACTERS";
18 }
19+ event_handler.onKeyReleased(keyToSend, action);
20 }
21 }
22
23
24=== modified file 'src/plugin/inputmethod.cpp'
25--- src/plugin/inputmethod.cpp 2014-09-25 13:44:09 +0000
26+++ src/plugin/inputmethod.cpp 2014-10-10 13:28:23 +0000
27@@ -370,7 +370,7 @@
28 d->editor.text()->setSurroundingOffset(position);
29
30 updateAutoCaps();
31- checkInitialAutocaps();
32+ checkAutocaps();
33 d->previous_position = position;
34 }
35 }
36@@ -412,9 +412,9 @@
37 updateAutoCaps();
38 }
39
40-//! \brief InputMethod::checkInitialAutocaps Checks if the keyboard should be
41-//! set to uppercase, because the auto caps is enabled and the text is empty.
42-void InputMethod::checkInitialAutocaps()
43+//! \brief InputMethod::checkAutocaps Checks if the keyboard should be
44+//! set to uppercase after the cursor position has been changed.
45+void InputMethod::checkAutocaps()
46 {
47 Q_D(InputMethod);
48
49@@ -422,12 +422,12 @@
50 QString text;
51 int position;
52 bool ok = d->host->surroundingText(text, position);
53- QString textOnLeft = (d->editor.text()->surroundingLeft() + d->editor.text()->preedit()).trimmed();
54- if (ok && text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0) {
55+ QString textOnLeft = d->editor.text()->surroundingLeft() + d->editor.text()->preedit();
56+ if (ok && ((text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0)
57+ || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft)
58+ || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft.trimmed()))) {
59 Q_EMIT activateAutocaps();
60- } else if (!d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft)) {
61- // Clear autocaps if it has been set by us previously being in an
62- // empty field
63+ } else {
64 Q_EMIT deactivateAutocaps();
65 }
66 }
67
68=== modified file 'src/plugin/inputmethod.h'
69--- src/plugin/inputmethod.h 2014-09-10 14:57:52 +0000
70+++ src/plugin/inputmethod.h 2014-10-10 13:28:23 +0000
71@@ -147,7 +147,7 @@
72 Q_SLOT void onLayoutWidthChanged(int width);
73 Q_SLOT void onLayoutHeightChanged(int height);
74
75- void checkInitialAutocaps();
76+ void checkAutocaps();
77
78 const QScopedPointer<InputMethodPrivate> d_ptr;
79 };
80
81=== modified file 'src/view/abstracttexteditor.cpp'
82--- src/view/abstracttexteditor.cpp 2014-09-25 15:18:42 +0000
83+++ src/view/abstracttexteditor.cpp 2014-10-10 13:28:23 +0000
84@@ -287,6 +287,7 @@
85 QString ignore_next_surrounding_text;
86 bool look_for_a_double_space;
87 bool double_space_full_stop_enabled;
88+ bool editing_middle_of_text;
89 QString appendix_for_previous_preedit;
90 int backspace_word_acceleration;
91 QString keyboardState;
92@@ -313,6 +314,7 @@
93 , ignore_next_surrounding_text()
94 , look_for_a_double_space(false)
95 , double_space_full_stop_enabled(false)
96+ , editing_middle_of_text(false)
97 , appendix_for_previous_preedit()
98 , backspace_word_acceleration(0)
99 , keyboardState("CHARACTERS")
100@@ -443,7 +445,12 @@
101 not d->text->preedit().isEmpty() && isSeparator;
102
103 if (d->preedit_enabled) {
104- if (replace_preedit) {
105+ if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]"))) {
106+ // We're editing in the middle of a word, so just insert characters directly
107+ d->text->appendToPreedit(text);
108+ commitPreedit();
109+ alreadyAppended = true;
110+ } else if (replace_preedit) {
111 // this means we should commit the candidate, add the separator and whitespace
112 d->text->setPreedit(d->text->primaryCandidate());
113 d->text->appendToPreedit(text);
114@@ -510,6 +517,7 @@
115 case Key::ActionSpace: {
116 QString space = " ";
117 QString textOnLeft = d->text->surroundingLeft() + d->text->preedit();
118+ QString textOnRight = d->text->surroundingRight().trimmed();
119 bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(textOnLeft);
120 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() && not d->text->preedit().isEmpty();
121 const QString stopSequence = d->word_engine->languageFeature()->fullStopSequence();
122@@ -520,7 +528,14 @@
123 }
124
125 if (replace_preedit) {
126- space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
127+ if (!textOnRight.isEmpty() && d->editing_middle_of_text) {
128+ // Don't insert a space if we are correcting a word in the middle of a sentence
129+ space = "";
130+ d->look_for_a_double_space = false;
131+ d->editing_middle_of_text = false;
132+ } else {
133+ space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
134+ }
135 d->text->setPreedit(d->text->primaryCandidate());
136 }
137 else if (look_for_a_double_space && not stopSequence.isEmpty()) {
138@@ -543,10 +558,6 @@
139 case Key::ActionReturn: {
140 event_key = Qt::Key_Return;
141 keyText = QString("\r");
142-
143- if (d->word_engine->languageFeature()->activateAutoCaps(keyText) && d->auto_caps_enabled) {
144- Q_EMIT autoCapsActivated();
145- }
146 } break;
147
148 case Key::ActionClose:
149@@ -672,6 +683,11 @@
150 const bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->preedit());
151 d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
152 if (d->auto_correct_enabled) {
153+ if (!d->text->surroundingRight().trimmed().isEmpty() && d->editing_middle_of_text) {
154+ // Don't insert a space if we are correcting a word in the middle of a sentence
155+ d->appendix_for_previous_preedit = "";
156+ d->editing_middle_of_text = false;
157+ }
158 d->text->appendToPreedit(d->appendix_for_previous_preedit);
159 }
160 commitPreedit();
161@@ -943,6 +959,9 @@
162 }
163 }
164
165+ if(!d->text->surroundingRight().trimmed().isEmpty()) {
166+ d->editing_middle_of_text = true;
167+ }
168 d->backspace_sent = true;
169 }
170
171@@ -1052,8 +1071,8 @@
172 leftWords.removeLast();
173 trimDiff += 1;
174 }
175- if(!text()->surroundingRight().trimmed().isEmpty()) {
176- // We don't currently handle reentering preedit in the middle of the text
177+ if(d->text->surroundingRight().left(1).contains(QRegExp("[\\w]"))) {
178+ // Don't enter pre-edit in the middle of a word
179 return;
180 }
181 QString recreatedPreedit = leftWords.last();
182@@ -1062,8 +1081,6 @@
183 // as the last backspace hasn't been committed yet.
184 recreatedPreedit.chop(1);
185 }
186- int position = currentOffset - recreatedPreedit.size();
187- QString surroundWithoutPreedit = text()->surrounding().remove(position, recreatedPreedit.size());
188
189 for(int i = 0; i < recreatedPreedit.size(); i++) {
190 singleBackspace();

Subscribers

People subscribed via source and target branches