|
16 | 16 | import android.text.Layout;
|
17 | 17 | import android.text.Selection;
|
18 | 18 | import android.text.TextPaint;
|
| 19 | +import android.text.method.TextKeyListener; |
19 | 20 | import android.view.KeyEvent;
|
20 | 21 | import android.view.View;
|
21 | 22 | import android.view.inputmethod.BaseInputConnection;
|
@@ -321,35 +322,11 @@ public boolean sendKeyEvent(KeyEvent event) {
|
321 | 322 | updateEditingState();
|
322 | 323 | return true;
|
323 | 324 | } else if (selStart > 0) {
|
324 |
| - // Delete to the left/right of the cursor depending on direction of text. |
325 |
| - // TODO(garyq): Explore how to obtain per-character direction. The |
326 |
| - // isRTLCharAt() call below is returning blanket direction assumption |
327 |
| - // based on the first character in the line. |
328 |
| - boolean isRtl = mLayout.isRtlCharAt(mLayout.getLineForOffset(selStart)); |
329 |
| - try { |
330 |
| - if (isRtl) { |
331 |
| - Selection.extendRight(mEditable, mLayout); |
332 |
| - } else { |
333 |
| - Selection.extendLeft(mEditable, mLayout); |
334 |
| - } |
335 |
| - } catch (IndexOutOfBoundsException e) { |
336 |
| - // On some Chinese devices (primarily Huawei, some Xiaomi), |
337 |
| - // on initial app startup before focus is lost, the |
338 |
| - // Selection.extendLeft and extendRight calls always extend |
339 |
| - // from the index of the initial contents of mEditable. This |
340 |
| - // try-catch will prevent crashing on Huawei devices by falling |
341 |
| - // back to a simple way of deletion, although this a hack and |
342 |
| - // will not handle emojis. |
343 |
| - Selection.setSelection(mEditable, selStart, selStart - 1); |
| 325 | + if (TextKeyListener.getInstance().onKeyDown(null, mEditable, event.getKeyCode(), event)) { |
| 326 | + updateEditingState(); |
| 327 | + return true; |
344 | 328 | }
|
345 |
| - int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable); |
346 |
| - int newEnd = clampIndexToEditable(Selection.getSelectionEnd(mEditable), mEditable); |
347 |
| - Selection.setSelection(mEditable, Math.min(newStart, newEnd)); |
348 |
| - // Min/Max the values since RTL selections will start at a higher |
349 |
| - // index than they end at. |
350 |
| - mEditable.delete(Math.min(newStart, newEnd), Math.max(newStart, newEnd)); |
351 |
| - updateEditingState(); |
352 |
| - return true; |
| 329 | + return false; |
353 | 330 | }
|
354 | 331 | } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
|
355 | 332 | int selStart = Selection.getSelectionStart(mEditable);
|
|
0 commit comments