Merge lp:~michael-sheldon/ubuntu-keyboard/email-detection into lp:ubuntu-keyboard

Proposed by Michael Sheldon
Status: Merged
Approved by: Bill Filler
Approved revision: 237
Merged at revision: 236
Proposed branch: lp:~michael-sheldon/ubuntu-keyboard/email-detection
Merge into: lp:ubuntu-keyboard
Diff against target: 122 lines (+35/-12)
4 files modified
plugins/pinyin/src/chineselanguagefeatures.cpp (+1/-1)
qml/Keyboard.qml (+1/-0)
src/plugin/inputmethod.cpp (+6/-1)
src/view/abstracttexteditor.cpp (+27/-10)
To merge this branch: bzr merge lp:~michael-sheldon/ubuntu-keyboard/email-detection
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+239223@code.launchpad.net

Commit message

Detect if the user is entering an email address whilst in a field that supports predictions and suppress predictions, auto-caps and auto-spacing unless the input method requires predictions for standard character input (e.g. pinyin).

Description of the change

Detect if the user is entering an email address whilst in a field that supports predictions and suppress predictions, auto-caps and auto-spacing unless the input method requires predictions for standard character input (e.g. pinyin).

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 :

one minor issue:
I test trying to login to twitter.com using my email address for username. Seems that after typing the @ sign and then returning to the ABC keyboard layout the shift key gets enabled, which we don't want.

review: Needs Fixing
237. By Michael Sheldon

Fix delayed autocaps deactivation

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

same problem occurs where the caps is turned on after entering the @ sign and returning to the main layout. Easiest way to reproduce is with the twitter webapp

review: Needs Fixing
Revision history for this message
Bill Filler (bfiller) wrote :

works now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/pinyin/src/chineselanguagefeatures.cpp'
2--- plugins/pinyin/src/chineselanguagefeatures.cpp 2014-09-08 15:09:32 +0000
3+++ plugins/pinyin/src/chineselanguagefeatures.cpp 2014-10-29 17:51:15 +0000
4@@ -56,7 +56,7 @@
5
6 bool ChineseLanguageFeatures::isSeparator(const QString &text) const
7 {
8- static const QString separators = QString::fromUtf8("。、,!?:;\r\n");
9+ static const QString separators = QString::fromUtf8("。、,!?:;.\r\n");
10
11 if (text.isEmpty()) {
12 return false;
13
14=== modified file 'qml/Keyboard.qml'
15--- qml/Keyboard.qml 2014-09-16 12:39:01 +0000
16+++ qml/Keyboard.qml 2014-10-29 17:51:15 +0000
17@@ -258,6 +258,7 @@
18 keypad.activeKeypadState = "NORMAL";
19 keypad.autoCapsTriggered = false;
20 }
21+ keypad.delayedAutoCaps = false;
22 }
23 }
24
25
26=== modified file 'src/plugin/inputmethod.cpp'
27--- src/plugin/inputmethod.cpp 2014-10-07 15:44:46 +0000
28+++ src/plugin/inputmethod.cpp 2014-10-29 17:51:15 +0000
29@@ -423,7 +423,12 @@
30 int position;
31 bool ok = d->host->surroundingText(text, position);
32 QString textOnLeft = d->editor.text()->surroundingLeft() + d->editor.text()->preedit();
33- if (ok && ((text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0)
34+ QStringList leftHandWords = textOnLeft.split(" ");
35+ bool email_detected = false;
36+ if (!leftHandWords.isEmpty() && leftHandWords.last().contains("@")) {
37+ email_detected = true;
38+ }
39+ if (ok && !email_detected && ((text.isEmpty() && d->editor.text()->preedit().isEmpty() && position == 0)
40 || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft)
41 || d->editor.wordEngine()->languageFeature()->activateAutoCaps(textOnLeft.trimmed()))) {
42 Q_EMIT activateAutocaps();
43
44=== modified file 'src/view/abstracttexteditor.cpp'
45--- src/view/abstracttexteditor.cpp 2014-10-10 13:27:50 +0000
46+++ src/view/abstracttexteditor.cpp 2014-10-29 17:51:15 +0000
47@@ -429,6 +429,17 @@
48 QString keyText = QString("");
49 Qt::Key event_key = Qt::Key_unknown;
50 bool look_for_a_double_space = d->look_for_a_double_space;
51+ bool email_detected = false;
52+
53+ // Detect if the user is entering an email address and avoid spacing, autocaps and autocomplete changes
54+ QString textOnLeft = d->text->surroundingLeft() + d->text->preedit();
55+ if (key.action() == Key::ActionBackspace) {
56+ textOnLeft.chop(1);
57+ }
58+ QStringList leftHandWords = textOnLeft.split(" ");
59+ if (!d->word_engine->languageFeature()->alwaysShowSuggestions() && !leftHandWords.isEmpty() && leftHandWords.last().contains("@")) {
60+ email_detected = true;
61+ }
62
63 if (look_for_a_double_space) {
64 // we reset the flag here so that we won't have to add boilerplate code later
65@@ -445,8 +456,8 @@
66 not d->text->preedit().isEmpty() && isSeparator;
67
68 if (d->preedit_enabled) {
69- if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]"))) {
70- // We're editing in the middle of a word, so just insert characters directly
71+ if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected) {
72+ // We're editing in the middle of a word or entering an email address, so just insert characters directly
73 d->text->appendToPreedit(text);
74 commitPreedit();
75 alreadyAppended = true;
76@@ -454,24 +465,28 @@
77 // this means we should commit the candidate, add the separator and whitespace
78 d->text->setPreedit(d->text->primaryCandidate());
79 d->text->appendToPreedit(text);
80- if (d->keyboardState == "CHARACTERS") {
81+ if (d->keyboardState == "CHARACTERS" && !email_detected) {
82 d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
83 d->text->appendToPreedit(d->appendix_for_previous_preedit);
84 }
85 commitPreedit();
86- auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->surroundingLeft() + d->text->preedit() + text);
87+ if (!email_detected) {
88+ auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->surroundingLeft() + d->text->preedit() + text);
89+ }
90 alreadyAppended = true;
91 }
92 else if (d->auto_correct_enabled && (isSeparator || isSymbol)) {
93- if(isSeparator && d->keyboardState == "CHARACTERS") {
94+ if(isSeparator && d->keyboardState == "CHARACTERS" && !email_detected) {
95 // remove all whitespaces before the separator, then add a whitespace after it
96 removeTrailingWhitespaces();
97 }
98
99 d->text->appendToPreedit(text);
100- auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->surroundingLeft() + d->text->preedit());
101- if(isSeparator && d->keyboardState == "CHARACTERS") {
102- d->text->appendToPreedit(d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit()));
103+ if (!email_detected) {
104+ auto_caps_activated = d->word_engine->languageFeature()->activateAutoCaps(d->text->surroundingLeft() + d->text->preedit());
105+ if(isSeparator && d->keyboardState == "CHARACTERS") {
106+ d->text->appendToPreedit(d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit()));
107+ }
108 }
109 commitPreedit();
110 alreadyAppended = true;
111@@ -505,8 +520,10 @@
112 case Key::ActionBackspace: {
113 if (not d->backspace_sent) {
114 singleBackspace();
115- checkPreeditReentry(true);
116- } else {
117+ if (!email_detected) {
118+ checkPreeditReentry(true);
119+ }
120+ } else if (!email_detected) {
121 checkPreeditReentry(false);
122 }
123

Subscribers

People subscribed via source and target branches