Merge lp:~schwann/ubuntu-keyboard/keyboard-delete-words into lp:ubuntu-keyboard

Proposed by Günter Schwann
Status: Merged
Approved by: Thomas Moenicke
Approved revision: 85
Merged at revision: 84
Proposed branch: lp:~schwann/ubuntu-keyboard/keyboard-delete-words
Merge into: lp:ubuntu-keyboard
Diff against target: 137 lines (+66/-3)
3 files modified
src/plugin/inputmethod.cpp (+8/-0)
src/view/abstracttexteditor.cpp (+54/-3)
src/view/abstracttexteditor.h (+4/-0)
To merge this branch: bzr merge lp:~schwann/ubuntu-keyboard/keyboard-delete-words
Reviewer Review Type Date Requested Status
Thomas Moenicke (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+192325@code.launchpad.net

Commit message

After holding the backspace for a while, remove whole words

Description of the change

After holding the backspace for a while, remove whole words

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
85. By Günter Schwann

Always keep sending at least one backspace

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomas Moenicke (thomas-moenicke) wrote :

tested on the device, I confirm deleting first characters, later entire words is working (messaging app + notes-app)
code looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/inputmethod.cpp'
2--- src/plugin/inputmethod.cpp 2013-10-21 13:21:28 +0000
3+++ src/plugin/inputmethod.cpp 2013-10-24 07:15:22 +0000
4@@ -385,6 +385,14 @@
5 if (emitPredictionEnabled)
6 Q_EMIT predictionEnabledChanged();
7
8+ QString text;
9+ int position;
10+ bool ok = d->host->surroundingText(text, position);
11+ if (ok) {
12+ d->editor.text()->setSurrounding(text);
13+ d->editor.text()->setSurroundingOffset(position);
14+ }
15+
16 updateAutoCaps();
17 }
18
19
20=== modified file 'src/view/abstracttexteditor.cpp'
21--- src/view/abstracttexteditor.cpp 2013-10-07 14:46:39 +0000
22+++ src/view/abstracttexteditor.cpp 2013-10-24 07:15:22 +0000
23@@ -35,6 +35,8 @@
24 #include "logic/chineselanguagefeatures.h"
25 #include "logic/languagefeatures.h"
26
27+#include <QElapsedTimer>
28+
29 namespace MaliitKeyboard {
30
31 //! \class EditorOptions
32@@ -263,13 +265,16 @@
33
34 EditorOptions::EditorOptions()
35 : backspace_auto_repeat_delay(500)
36- , backspace_auto_repeat_interval(300)
37+ , backspace_auto_repeat_interval(200)
38+ , backspace_word_delay(3000)
39+ , backspace_word_interval(400)
40 {}
41
42 class AbstractTextEditorPrivate
43 {
44 public:
45 QTimer auto_repeat_backspace_timer;
46+ QElapsedTimer backspace_hold_timer;
47 bool backspace_sent;
48 EditorOptions options;
49 QScopedPointer<Model::Text> text;
50@@ -389,6 +394,7 @@
51
52 commitPreedit();
53 d->auto_repeat_backspace_timer.start(d->options.backspace_auto_repeat_delay);
54+ d->backspace_hold_timer.restart();
55 }
56 }
57
58@@ -666,10 +672,55 @@
59 {
60 Q_D(AbstractTextEditor);
61
62+ if (d->backspace_hold_timer.elapsed() < d->options.backspace_word_delay) {
63+ QKeyEvent ev(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
64+ sendKeyEvent(ev);
65+ d->backspace_sent = true;
66+ d->auto_repeat_backspace_timer.start(d->options.backspace_auto_repeat_interval);
67+ } else {
68+ autoRepeatWordBackspace();
69+ }
70+}
71+
72+/*!
73+ * \brief AbstractTextEditor::autoRepeatWordBackspace same as autoRepeatBackspace()
74+ * but deletes whole words
75+ */
76+void AbstractTextEditor::autoRepeatWordBackspace()
77+{
78+ Q_D(AbstractTextEditor);
79+
80 QKeyEvent ev(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
81- sendKeyEvent(ev);
82+
83+ if (d->text->surroundingOffset() > 0) {
84+ QString word = wordLeftOfCursor();
85+ for (int i=0; i<word.length(); ++i)
86+ sendKeyEvent(ev);
87+ } else {
88+ sendKeyEvent(ev);
89+ }
90+
91 d->backspace_sent = true;
92- d->auto_repeat_backspace_timer.start(d->options.backspace_auto_repeat_interval);
93+ d->auto_repeat_backspace_timer.start(d->options.backspace_word_interval);
94+}
95+
96+/*!
97+ * \brief AbstractTextEditor::wordLeftOfCursor returns the word that is left to
98+ * to the cursor
99+ * \return
100+ */
101+QString AbstractTextEditor::wordLeftOfCursor() const
102+{
103+ Q_D(const AbstractTextEditor);
104+
105+ const QString leftSurrounding = d->text->surroundingLeft();
106+ int idx = leftSurrounding.length() - 1;
107+ while (idx >= 0 && !isSeparator(leftSurrounding.at(idx))) {
108+ --idx;
109+ }
110+ int length = d->text->surroundingOffset() - idx;
111+
112+ return leftSurrounding.right(length);
113 }
114
115 //! \brief Emits wordCandidatesChanged() signal with current preedit
116
117=== modified file 'src/view/abstracttexteditor.h'
118--- src/view/abstracttexteditor.h 2013-07-19 12:05:07 +0000
119+++ src/view/abstracttexteditor.h 2013-10-24 07:15:22 +0000
120@@ -49,6 +49,8 @@
121 // all delays are in milliseconds
122 int backspace_auto_repeat_delay; // delay before first automatically repeated key
123 int backspace_auto_repeat_interval; // interval between automatically repeated keys
124+ int backspace_word_delay; // delay before first automatically delete whole words
125+ int backspace_word_interval; // interval between deleting word on while pressing the backspace
126 };
127
128 class AbstractTextEditorPrivate;
129@@ -156,6 +158,8 @@
130
131 void commitPreedit();
132 Q_SLOT void autoRepeatBackspace();
133+ void autoRepeatWordBackspace();
134+ QString wordLeftOfCursor() const;
135 };
136
137 } // namespace MaliitKeyboard

Subscribers

People subscribed via source and target branches