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
=== modified file 'qml/keys/CharKey.qml'
--- qml/keys/CharKey.qml 2014-09-26 17:41:47 +0000
+++ qml/keys/CharKey.qml 2014-10-10 13:28:23 +0000
@@ -206,8 +206,8 @@
206 extendedKeysSelector.closePopover(); 206 extendedKeysSelector.closePopover();
207 }207 }
208 } else if(!swipedOut) {208 } else if(!swipedOut) {
209 event_handler.onKeyReleased(valueToSubmit, action);209 // Read this prior to altering autocaps
210210 var keyToSend = valueToSubmit;
211 if (magnifier.currentlyAssignedKey == key) {211 if (magnifier.currentlyAssignedKey == key) {
212 magnifier.shown = false;212 magnifier.shown = false;
213 }213 }
@@ -222,6 +222,7 @@
222 if (switchBackFromSymbols && panel.state === "SYMBOLS") {222 if (switchBackFromSymbols && panel.state === "SYMBOLS") {
223 panel.state = "CHARACTERS";223 panel.state = "CHARACTERS";
224 }224 }
225 event_handler.onKeyReleased(keyToSend, action);
225 }226 }
226 }227 }
227228
228229
=== modified file 'src/plugin/inputmethod.cpp'
--- src/plugin/inputmethod.cpp 2014-09-25 13:44:09 +0000
+++ src/plugin/inputmethod.cpp 2014-10-10 13:28:23 +0000
@@ -370,7 +370,7 @@
370 d->editor.text()->setSurroundingOffset(position);370 d->editor.text()->setSurroundingOffset(position);
371371
372 updateAutoCaps();372 updateAutoCaps();
373 checkInitialAutocaps();373 checkAutocaps();
374 d->previous_position = position;374 d->previous_position = position;
375 }375 }
376}376}
@@ -412,9 +412,9 @@
412 updateAutoCaps();412 updateAutoCaps();
413}413}
414414
415//! \brief InputMethod::checkInitialAutocaps Checks if the keyboard should be415//! \brief InputMethod::checkAutocaps Checks if the keyboard should be
416//! set to uppercase, because the auto caps is enabled and the text is empty.416//! set to uppercase after the cursor position has been changed.
417void InputMethod::checkInitialAutocaps()417void InputMethod::checkAutocaps()
418{418{
419 Q_D(InputMethod);419 Q_D(InputMethod);
420420
@@ -422,12 +422,12 @@
422 QString text;422 QString text;
423 int position;423 int position;
424 bool ok = d->host->surroundingText(text, position);424 bool ok = d->host->surroundingText(text, position);
425 QString textOnLeft = (d->editor.text()->surroundingLeft() + d->editor.text()->preedit()).trimmed();425 QString textOnLeft = d->editor.text()->surroundingLeft() + d->editor.text()->preedit();
426 if (ok && text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0) {426 if (ok && ((text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0)
427 || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft)
428 || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft.trimmed()))) {
427 Q_EMIT activateAutocaps();429 Q_EMIT activateAutocaps();
428 } else if (!d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft)) {430 } else {
429 // Clear autocaps if it has been set by us previously being in an
430 // empty field
431 Q_EMIT deactivateAutocaps();431 Q_EMIT deactivateAutocaps();
432 }432 }
433 }433 }
434434
=== modified file 'src/plugin/inputmethod.h'
--- src/plugin/inputmethod.h 2014-09-10 14:57:52 +0000
+++ src/plugin/inputmethod.h 2014-10-10 13:28:23 +0000
@@ -147,7 +147,7 @@
147 Q_SLOT void onLayoutWidthChanged(int width);147 Q_SLOT void onLayoutWidthChanged(int width);
148 Q_SLOT void onLayoutHeightChanged(int height);148 Q_SLOT void onLayoutHeightChanged(int height);
149149
150 void checkInitialAutocaps();150 void checkAutocaps();
151151
152 const QScopedPointer<InputMethodPrivate> d_ptr;152 const QScopedPointer<InputMethodPrivate> d_ptr;
153};153};
154154
=== modified file 'src/view/abstracttexteditor.cpp'
--- src/view/abstracttexteditor.cpp 2014-09-25 15:18:42 +0000
+++ src/view/abstracttexteditor.cpp 2014-10-10 13:28:23 +0000
@@ -287,6 +287,7 @@
287 QString ignore_next_surrounding_text;287 QString ignore_next_surrounding_text;
288 bool look_for_a_double_space;288 bool look_for_a_double_space;
289 bool double_space_full_stop_enabled;289 bool double_space_full_stop_enabled;
290 bool editing_middle_of_text;
290 QString appendix_for_previous_preedit;291 QString appendix_for_previous_preedit;
291 int backspace_word_acceleration;292 int backspace_word_acceleration;
292 QString keyboardState;293 QString keyboardState;
@@ -313,6 +314,7 @@
313 , ignore_next_surrounding_text()314 , ignore_next_surrounding_text()
314 , look_for_a_double_space(false)315 , look_for_a_double_space(false)
315 , double_space_full_stop_enabled(false)316 , double_space_full_stop_enabled(false)
317 , editing_middle_of_text(false)
316 , appendix_for_previous_preedit()318 , appendix_for_previous_preedit()
317 , backspace_word_acceleration(0)319 , backspace_word_acceleration(0)
318 , keyboardState("CHARACTERS")320 , keyboardState("CHARACTERS")
@@ -443,7 +445,12 @@
443 not d->text->preedit().isEmpty() && isSeparator;445 not d->text->preedit().isEmpty() && isSeparator;
444446
445 if (d->preedit_enabled) {447 if (d->preedit_enabled) {
446 if (replace_preedit) {448 if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]"))) {
449 // We're editing in the middle of a word, so just insert characters directly
450 d->text->appendToPreedit(text);
451 commitPreedit();
452 alreadyAppended = true;
453 } else if (replace_preedit) {
447 // this means we should commit the candidate, add the separator and whitespace454 // this means we should commit the candidate, add the separator and whitespace
448 d->text->setPreedit(d->text->primaryCandidate());455 d->text->setPreedit(d->text->primaryCandidate());
449 d->text->appendToPreedit(text);456 d->text->appendToPreedit(text);
@@ -510,6 +517,7 @@
510 case Key::ActionSpace: {517 case Key::ActionSpace: {
511 QString space = " ";518 QString space = " ";
512 QString textOnLeft = d->text->surroundingLeft() + d->text->preedit();519 QString textOnLeft = d->text->surroundingLeft() + d->text->preedit();
520 QString textOnRight = d->text->surroundingRight().trimmed();
513 bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(textOnLeft);521 bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(textOnLeft);
514 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() && not d->text->preedit().isEmpty();522 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() && not d->text->preedit().isEmpty();
515 const QString stopSequence = d->word_engine->languageFeature()->fullStopSequence();523 const QString stopSequence = d->word_engine->languageFeature()->fullStopSequence();
@@ -520,7 +528,14 @@
520 }528 }
521529
522 if (replace_preedit) {530 if (replace_preedit) {
523 space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());531 if (!textOnRight.isEmpty() && d->editing_middle_of_text) {
532 // Don't insert a space if we are correcting a word in the middle of a sentence
533 space = "";
534 d->look_for_a_double_space = false;
535 d->editing_middle_of_text = false;
536 } else {
537 space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
538 }
524 d->text->setPreedit(d->text->primaryCandidate());539 d->text->setPreedit(d->text->primaryCandidate());
525 }540 }
526 else if (look_for_a_double_space && not stopSequence.isEmpty()) {541 else if (look_for_a_double_space && not stopSequence.isEmpty()) {
@@ -543,10 +558,6 @@
543 case Key::ActionReturn: {558 case Key::ActionReturn: {
544 event_key = Qt::Key_Return;559 event_key = Qt::Key_Return;
545 keyText = QString("\r");560 keyText = QString("\r");
546
547 if (d->word_engine->languageFeature()->activateAutoCaps(keyText) && d->auto_caps_enabled) {
548 Q_EMIT autoCapsActivated();
549 }
550 } break;561 } break;
551562
552 case Key::ActionClose:563 case Key::ActionClose:
@@ -672,6 +683,11 @@
672 const bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->preedit());683 const bool auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->preedit());
673 d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());684 d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
674 if (d->auto_correct_enabled) {685 if (d->auto_correct_enabled) {
686 if (!d->text->surroundingRight().trimmed().isEmpty() && d->editing_middle_of_text) {
687 // Don't insert a space if we are correcting a word in the middle of a sentence
688 d->appendix_for_previous_preedit = "";
689 d->editing_middle_of_text = false;
690 }
675 d->text->appendToPreedit(d->appendix_for_previous_preedit);691 d->text->appendToPreedit(d->appendix_for_previous_preedit);
676 }692 }
677 commitPreedit();693 commitPreedit();
@@ -943,6 +959,9 @@
943 }959 }
944 }960 }
945961
962 if(!d->text->surroundingRight().trimmed().isEmpty()) {
963 d->editing_middle_of_text = true;
964 }
946 d->backspace_sent = true;965 d->backspace_sent = true;
947}966}
948967
@@ -1052,8 +1071,8 @@
1052 leftWords.removeLast();1071 leftWords.removeLast();
1053 trimDiff += 1;1072 trimDiff += 1;
1054 }1073 }
1055 if(!text()->surroundingRight().trimmed().isEmpty()) {1074 if(d->text->surroundingRight().left(1).contains(QRegExp("[\\w]"))) {
1056 // We don't currently handle reentering preedit in the middle of the text1075 // Don't enter pre-edit in the middle of a word
1057 return;1076 return;
1058 }1077 }
1059 QString recreatedPreedit = leftWords.last();1078 QString recreatedPreedit = leftWords.last();
@@ -1062,8 +1081,6 @@
1062 // as the last backspace hasn't been committed yet.1081 // as the last backspace hasn't been committed yet.
1063 recreatedPreedit.chop(1);1082 recreatedPreedit.chop(1);
1064 }1083 }
1065 int position = currentOffset - recreatedPreedit.size();
1066 QString surroundWithoutPreedit = text()->surrounding().remove(position, recreatedPreedit.size());
10671084
1068 for(int i = 0; i < recreatedPreedit.size(); i++) {1085 for(int i = 0; i < recreatedPreedit.size(); i++) {
1069 singleBackspace();1086 singleBackspace();

Subscribers

People subscribed via source and target branches