|
16 | 16 | import android.text.Layout;
|
17 | 17 | import android.text.Selection;
|
18 | 18 | import android.text.TextPaint;
|
| 19 | +import android.text.method.QwertyKeyListener; |
| 20 | +import android.text.method.TextKeyListener.Capitalize; |
19 | 21 | import android.view.KeyEvent;
|
20 | 22 | import android.view.View;
|
21 | 23 | import android.view.inputmethod.BaseInputConnection;
|
@@ -237,53 +239,12 @@ public boolean sendKeyEvent(KeyEvent event) {
|
237 | 239 | updateEditingState();
|
238 | 240 | return true;
|
239 | 241 | } else if (selStart > 0) {
|
240 |
| - // Delete to the left/right of the cursor depending on direction of text. |
241 |
| - // TODO(garyq): Explore how to obtain per-character direction. The |
242 |
| - // isRTLCharAt() call below is returning blanket direction assumption |
243 |
| - // based on the first character in the line. |
244 |
| - |
245 |
| - Boolean selectedCharIsEmoji = false; |
246 |
| - if (selStart > 1) { |
247 |
| - final String emo_regex = |
248 |
| - "([\\u20a0-\\u32ff\\ud83c\\udc00-\\ud83d\\udeff\\udbb9\\udce5-\\udbb9\\udcee])"; |
249 |
| - String lastChars = mLayout.getText().subSequence(selStart - 2, selStart).toString(); |
250 |
| - selectedCharIsEmoji = lastChars.matches(emo_regex); |
251 |
| - } |
252 |
| - |
253 |
| - // The Selection.extendLeft and extendRight calls have some problems |
254 |
| - // when mixing RTL and LTR text so if selected character is not emoji |
255 |
| - // simply select that character |
256 |
| - if (selectedCharIsEmoji) { |
257 |
| - boolean isRtl = |
258 |
| - mLayout.isRtlCharAt(mLayout.getLineStart(mLayout.getLineForOffset(selStart))); |
259 |
| - Log.i("isRtl", Boolean.toString(isRtl)); |
260 |
| - try { |
261 |
| - if (isRtl) { |
262 |
| - Selection.extendRight(mEditable, mLayout); |
263 |
| - } else { |
264 |
| - Selection.extendLeft(mEditable, mLayout); |
265 |
| - } |
266 |
| - } catch (IndexOutOfBoundsException e) { |
267 |
| - // On some Chinese devices (primarily Huawei, some Xiaomi), |
268 |
| - // on initial app startup before focus is lost, the |
269 |
| - // Selection.extendLeft and extendRight calls always extend |
270 |
| - // from the index of the initial contents of mEditable. This |
271 |
| - // try-catch will prevent crashing on Huawei devices by falling |
272 |
| - // back to a simple way of deletion, although this a hack and |
273 |
| - // will not handle emojis. |
274 |
| - Selection.setSelection(mEditable, selStart, selStart - 1); |
275 |
| - } |
276 |
| - } else { |
277 |
| - Selection.setSelection(mEditable, selStart, selStart - 1); |
| 242 | + QwertyKeyListener qwertyKeyListener = new QwertyKeyListener(Capitalize.NONE, false); |
| 243 | + if (qwertyKeyListener.onKeyDown(null, mEditable, event.getKeyCode(), event)) { |
| 244 | + updateEditingState(); |
| 245 | + return true; |
278 | 246 | }
|
279 |
| - int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable); |
280 |
| - int newEnd = clampIndexToEditable(Selection.getSelectionEnd(mEditable), mEditable); |
281 |
| - Selection.setSelection(mEditable, Math.min(newStart, newEnd)); |
282 |
| - // Min/Max the values since RTL selections will start at a higher |
283 |
| - // index than they end at. |
284 |
| - mEditable.delete(Math.min(newStart, newEnd), Math.max(newStart, newEnd)); |
285 |
| - updateEditingState(); |
286 |
| - return true; |
| 247 | + return false; |
287 | 248 | }
|
288 | 249 | } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
|
289 | 250 | int selStart = Selection.getSelectionStart(mEditable);
|
|
0 commit comments