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
=== modified file 'src/lib/logic/wordengine.cpp'
--- src/lib/logic/wordengine.cpp 2014-12-08 14:26:19 +0000
+++ src/lib/logic/wordengine.cpp 2015-02-02 15:06:53 +0000
@@ -346,6 +346,14 @@
346 primary.setPrimary(true);346 primary.setPrimary(true);
347 d->candidates->replace(0, primary);347 d->candidates->replace(0, primary);
348 Q_EMIT primaryCandidateChanged(primary.word());348 Q_EMIT primaryCandidateChanged(primary.word());
349 } else if (d->currentText && d->currentText->restoredPreedit()) {
350 // The pre-edit has just been restored by the user pressing backspace after
351 // auto-completing a word, so the user input should be the primary candidate
352 WordCandidate primary = d->candidates->value(0);
353 primary.setPrimary(true);
354 d->candidates->replace(0, primary);
355 Q_EMIT primaryCandidateChanged(primary.word());
356 d->currentText->setRestoredPreedit(false);
349 } else if (!d->languagePlugin->languageFeature()->ignoreSimilarity()357 } else if (!d->languagePlugin->languageFeature()->ignoreSimilarity()
350 && !similarWords(d->candidates->at(0).word(), d->candidates->at(1).word())) {358 && !similarWords(d->candidates->at(0).word(), d->candidates->at(1).word())) {
351 // The prediction is too different to the user input, so the user input 359 // The prediction is too different to the user input, so the user input
352360
=== modified file 'src/lib/models/text.cpp'
--- src/lib/models/text.cpp 2013-10-30 14:20:15 +0000
+++ src/lib/models/text.cpp 2015-02-02 15:06:53 +0000
@@ -47,6 +47,7 @@
47 , m_surrounding_offset(0)47 , m_surrounding_offset(0)
48 , m_face(PreeditDefault)48 , m_face(PreeditDefault)
49 , m_cursor_position(0)49 , m_cursor_position(0)
50 , m_restored_preedit(false)
50{}51{}
5152
52//! Returns current preedit.53//! Returns current preedit.
@@ -194,4 +195,17 @@
194 m_cursor_position = cursor_position;195 m_cursor_position = cursor_position;
195}196}
196197
198//! Indicates if the preedit has been restored by the user pressing backspace
199bool Text::restoredPreedit() const
200{
201 return m_restored_preedit;
202}
203
204//! Sets whether the preedit has been recently restored
205//! \param restored Preedit restoration state
206void Text::setRestoredPreedit(bool restored)
207{
208 m_restored_preedit = restored;
209}
210
197}} // namespace Model, MaliitKeyboard211}} // namespace Model, MaliitKeyboard
198212
=== modified file 'src/lib/models/text.h'
--- src/lib/models/text.h 2013-10-30 17:12:49 +0000
+++ src/lib/models/text.h 2015-02-02 15:06:53 +0000
@@ -55,6 +55,7 @@
55 uint m_surrounding_offset; //!< offset of cursor position in surrounding text.55 uint m_surrounding_offset; //!< offset of cursor position in surrounding text.
56 PreeditFace m_face; //!< face of preedit.56 PreeditFace m_face; //!< face of preedit.
57 int m_cursor_position; //!< position of cursor in preedit string.57 int m_cursor_position; //!< position of cursor in preedit string.
58 bool m_restored_preedit; //!< indicates that the preedit has just been restored by the user pressing backspace
5859
59public:60public:
60 explicit Text();61 explicit Text();
@@ -82,6 +83,9 @@
8283
83 int cursorPosition() const;84 int cursorPosition() const;
84 void setCursorPosition(int cursor_position);85 void setCursorPosition(int cursor_position);
86
87 bool restoredPreedit() const;
88 void setRestoredPreedit(bool restored);
85};89};
8690
87}} // namespace Model, MaliitKeyboard91}} // namespace Model, MaliitKeyboard
8892
=== modified file 'src/view/abstracttexteditor.cpp'
--- src/view/abstracttexteditor.cpp 2015-01-08 09:13:21 +0000
+++ src/view/abstracttexteditor.cpp 2015-02-02 15:06:53 +0000
@@ -294,6 +294,8 @@
294 int backspace_word_acceleration;294 int backspace_word_acceleration;
295 int deleted_words;295 int deleted_words;
296 QString keyboardState;296 QString keyboardState;
297 QString previous_preedit;
298 int previous_preedit_position;
297299
298 explicit AbstractTextEditorPrivate(const EditorOptions &new_options,300 explicit AbstractTextEditorPrivate(const EditorOptions &new_options,
299 Model::Text *new_text,301 Model::Text *new_text,
@@ -323,6 +325,8 @@
323 , backspace_word_acceleration(0)325 , backspace_word_acceleration(0)
324 , deleted_words(0)326 , deleted_words(0)
325 , keyboardState("CHARACTERS")327 , keyboardState("CHARACTERS")
328 , previous_preedit("")
329 , previous_preedit_position(0)
326{330{
327 auto_repeat_backspace_timer.setSingleShot(true);331 auto_repeat_backspace_timer.setSingleShot(true);
328 (void) valid();332 (void) valid();
@@ -460,6 +464,8 @@
460 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() && 464 const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() &&
461 not d->text->preedit().isEmpty() && isSeparator;465 not d->text->preedit().isEmpty() && isSeparator;
462466
467 d->previous_preedit = "";
468
463 if (d->preedit_enabled) {469 if (d->preedit_enabled) {
464 if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected) {470 if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected) {
465 // We're editing in the middle of a word or entering an email address, so just insert characters directly471 // We're editing in the middle of a word or entering an email address, so just insert characters directly
@@ -556,6 +562,8 @@
556 } else {562 } else {
557 space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());563 space = d->appendix_for_previous_preedit = d->word_engine->languageFeature()->appendixForReplacedPreedit(d->text->preedit());
558 }564 }
565 d->previous_preedit = d->text->preedit();
566 d->previous_preedit_position = d->text->surroundingOffset();
559 d->text->setPreedit(d->text->primaryCandidate());567 d->text->setPreedit(d->text->primaryCandidate());
560 }568 }
561 else if (look_for_a_double_space && not stopSequence.isEmpty()) {569 else if (look_for_a_double_space && not stopSequence.isEmpty()) {
@@ -1118,6 +1126,15 @@
1118 singleBackspace();1126 singleBackspace();
1119 }1127 }
11201128
1129 if (!d->previous_preedit.isEmpty()) {
1130 int deletePos = d->text->surroundingOffset() - d->previous_preedit_position - recreatedPreedit.size();
1131 if (deletePos == 0 || deletePos == 1) {
1132 recreatedPreedit = d->previous_preedit;
1133 text()->setRestoredPreedit(true);
1134 }
1135 d->previous_preedit = "";
1136 }
1137
1121 replaceTextWithPreedit(recreatedPreedit, 0, 0, recreatedPreedit.size());1138 replaceTextWithPreedit(recreatedPreedit, 0, 0, recreatedPreedit.size());
1122 }1139 }
11231140
11241141
=== modified file 'tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py'
--- tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2015-01-08 18:07:27 +0000
+++ tests/autopilot/ubuntu_keyboard/tests/test_keyboard.py 2015-02-02 15:06:53 +0000
@@ -527,6 +527,33 @@
527 Eventually(Equals(expected))527 Eventually(Equals(expected))
528 )528 )
529529
530 def test_restore_preedit(self):
531 """Pressing delete after autocompleting a word should restore
532 the original preedit state.
533
534 """
535 text_area = self.launch_test_input_area()
536 self.ensure_focus_on_input(text_area)
537 keyboard = Keyboard()
538 self.addCleanup(keyboard.dismiss)
539
540 keyboard.type('Helfn ')
541
542 expected = "Helen "
543 self.assertThat(
544 text_area.text,
545 Eventually(Equals(expected))
546 )
547
548 keyboard.type('\b ')
549
550 expected = "Helfn "
551 self.assertThat(
552 text_area.text,
553 Eventually(Equals(expected))
554 )
555
556
530 def test_long_press(self):557 def test_long_press(self):
531 """Long pressing a key should enter the default extended character.558 """Long pressing a key should enter the default extended character.
532559

Subscribers

People subscribed via source and target branches