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

Proposed by Michael Sheldon
Status: Merged
Approved by: Bill Filler
Approved revision: 289
Merged at revision: 296
Proposed branch: lp:~michael-sheldon/ubuntu-keyboard/fix-1411645
Merge into: lp:ubuntu-keyboard
Diff against target: 163 lines (+70/-0)
5 files modified
src/lib/logic/wordengine.cpp (+8/-0)
src/lib/models/text.cpp (+14/-0)
src/lib/models/text.h (+4/-0)
src/view/abstracttexteditor.cpp (+17/-0)
tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py (+27/-0)
To merge this branch: bzr merge lp:~michael-sheldon/ubuntu-keyboard/fix-1411645
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+246712@code.launchpad.net

Commit message

Restore a user's original input if they press backspace immediately after auto-completing a word.

Description of the change

Restore a user's original input if they press backspace immediately after auto-completing a word.

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 :

Found one issue. If you use the cursor to re-position to a different word after autocompleting a word and then backspace the previous is word is replaced incorrectly.

For example type:
"I beleive" (space to autocomplete believe) "you" (space to complete)
then move cursor after "believe" and press backspace and "believe" is replaced with "you"

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

Works well in qml, but doesn't work in Gmail. Try to compose a mail and pressing backspace after auto-completing does not revert the word.

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

Strange it works well for a while and then stops working. Seems to happen after some newlines and then completing and reverting words. When it gets into the broken state it stops working from then on.

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

going to approve this now as it appears to be an oxide bug

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lib/logic/wordengine.cpp'
2--- src/lib/logic/wordengine.cpp 2014-12-08 14:26:19 +0000
3+++ src/lib/logic/wordengine.cpp 2015-02-02 15:06:53 +0000
4@@ -346,6 +346,14 @@
5 primary.setPrimary(true);
6 d->candidates->replace(0, primary);
7 Q_EMIT primaryCandidateChanged(primary.word());
8+ } else if (d->currentText && d->currentText->restoredPreedit()) {
9+ // The pre-edit has just been restored by the user pressing backspace after
10+ // auto-completing a word, so the user input should be the primary candidate
11+ WordCandidate primary = d->candidates->value(0);
12+ primary.setPrimary(true);
13+ d->candidates->replace(0, primary);
14+ Q_EMIT primaryCandidateChanged(primary.word());
15+ d->currentText->setRestoredPreedit(false);
16 } else if (!d->languagePlugin->languageFeature()->ignoreSimilarity()
17 && !similarWords(d->candidates->at(0).word(), d->candidates->at(1).word())) {
18 // The prediction is too different to the user input, so the user input
19
20=== modified file 'src/lib/models/text.cpp'
21--- src/lib/models/text.cpp 2013-10-30 14:20:15 +0000
22+++ src/lib/models/text.cpp 2015-02-02 15:06:53 +0000
23@@ -47,6 +47,7 @@
24 , m_surrounding_offset(0)
25 , m_face(PreeditDefault)
26 , m_cursor_position(0)
27+ , m_restored_preedit(false)
28 {}
29
30 //! Returns current preedit.
31@@ -194,4 +195,17 @@
32 m_cursor_position = cursor_position;
33 }
34
35+//! Indicates if the preedit has been restored by the user pressing backspace
36+bool Text::restoredPreedit() const
37+{
38+ return m_restored_preedit;
39+}
40+
41+//! Sets whether the preedit has been recently restored
42+//! \param restored Preedit restoration state
43+void Text::setRestoredPreedit(bool restored)
44+{
45+ m_restored_preedit = restored;
46+}
47+
48 }} // namespace Model, MaliitKeyboard
49
50=== modified file 'src/lib/models/text.h'
51--- src/lib/models/text.h 2013-10-30 17:12:49 +0000
52+++ src/lib/models/text.h 2015-02-02 15:06:53 +0000
53@@ -55,6 +55,7 @@
54 uint m_surrounding_offset; //!< offset of cursor position in surrounding text.
55 PreeditFace m_face; //!< face of preedit.
56 int m_cursor_position; //!< position of cursor in preedit string.
57+ bool m_restored_preedit; //!< indicates that the preedit has just been restored by the user pressing backspace
58
59 public:
60 explicit Text();
61@@ -82,6 +83,9 @@
62
63 int cursorPosition() const;
64 void setCursorPosition(int cursor_position);
65+
66+ bool restoredPreedit() const;
67+ void setRestoredPreedit(bool restored);
68 };
69
70 }} // namespace Model, MaliitKeyboard
71
72=== modified file 'src/view/abstracttexteditor.cpp'
73--- src/view/abstracttexteditor.cpp 2015-01-08 09:13:21 +0000
74+++ src/view/abstracttexteditor.cpp 2015-02-02 15:06:53 +0000
75@@ -294,6 +294,8 @@
76 int backspace_word_acceleration;
77 int deleted_words;
78 QString keyboardState;
79+ QString previous_preedit;
80+ int previous_preedit_position;
81
82 explicit AbstractTextEditorPrivate(const EditorOptions &new_options,
83 Model::Text *new_text,
84@@ -323,6 +325,8 @@
85 , backspace_word_acceleration(0)
86 , deleted_words(0)
87 , keyboardState("CHARACTERS")
88+ , previous_preedit("")
89+ , previous_preedit_position(0)
90 {
91 auto_repeat_backspace_timer.setSingleShot(true);
92 (void) valid();
93@@ -460,6 +464,8 @@
94 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() &&
95 not d->text->preedit().isEmpty() && isSeparator;
96
97+ d->previous_preedit = "";
98+
99 if (d->preedit_enabled) {
100 if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected) {
101 // We're editing in the middle of a word or entering an email address, so just insert characters directly
102@@ -556,6 +562,8 @@
103 } else {
104 space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
105 }
106+ d->previous_preedit = d->text->preedit();
107+ d->previous_preedit_position = d->text->surroundingOffset();
108 d->text->setPreedit(d->text->primaryCandidate());
109 }
110 else if (look_for_a_double_space && not stopSequence.isEmpty()) {
111@@ -1118,6 +1126,15 @@
112 singleBackspace();
113 }
114
115+ if (!d->previous_preedit.isEmpty()) {
116+ int deletePos = d->text->surroundingOffset() - d->previous_preedit_position - recreatedPreedit.size();
117+ if (deletePos == 0 || deletePos == 1) {
118+ recreatedPreedit = d->previous_preedit;
119+ text()->setRestoredPreedit(true);
120+ }
121+ d->previous_preedit = "";
122+ }
123+
124 replaceTextWithPreedit(recreatedPreedit, 0, 0, recreatedPreedit.size());
125 }
126
127
128=== modified file 'tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py'
129--- tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2015-01-08 18:07:27 +0000
130+++ tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2015-02-02 15:06:53 +0000
131@@ -527,6 +527,33 @@
132 Eventually(Equals(expected))
133 )
134
135+ def test_restore_preedit(self):
136+ """Pressing delete after autocompleting a word should restore
137+ the original preedit state.
138+
139+ """
140+ text_area = self.launch_test_input_area()
141+ self.ensure_focus_on_input(text_area)
142+ keyboard = Keyboard()
143+ self.addCleanup(keyboard.dismiss)
144+
145+ keyboard.type('Helfn ')
146+
147+ expected = "Helen "
148+ self.assertThat(
149+ text_area.text,
150+ Eventually(Equals(expected))
151+ )
152+
153+ keyboard.type('\b ')
154+
155+ expected = "Helfn "
156+ self.assertThat(
157+ text_area.text,
158+ Eventually(Equals(expected))
159+ )
160+
161+
162 def test_long_press(self):
163 """Long pressing a key should enter the default extended character.
164

Subscribers

People subscribed via source and target branches