diff options
| author | 2010-09-02 15:48:55 -0400 | |
|---|---|---|
| committer | 2010-09-03 11:45:28 -0400 | |
| commit | e742c08ce01742c5a864ce0a16bda4735a970bd8 (patch) | |
| tree | 99760ebe17c1d3162330bfaa42a5c000cb76a192 | |
| parent | de7fb55369e9051d5c565414e7c0cbd7d15dcdc4 (diff) | |
Use the proper selection when performing a delete.
Bug: 2956964
Change-Id: I488c291b2fb3cfa5c5d510bd4a03afbc8949d8d8
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 4d850465166a..6c11a7f4bfdc 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -110,6 +110,11 @@ import java.util.ArrayList; // FIXME: This can be replaced with TextView.NO_FILTERS if that // is made public/protected. private static final InputFilter[] NO_FILTERS = new InputFilter[0]; + // For keeping track of the fact that the delete key was pressed, so + // we can simply pass a delete key instead of calling deleteSelection. + private boolean mGotDelete; + private int mDelSelStart; + private int mDelSelEnd; /** * Create a new WebTextView. @@ -159,9 +164,16 @@ import java.util.ArrayList; // However, if the cursor is at the beginning of the field, which // includes the case where it has zero length, then the text is not // changed, so send the events immediately. - if (KeyEvent.KEYCODE_DEL == keyCode && oldStart == 0 && oldEnd == 0) { - sendDomEvent(event); - return true; + if (KeyEvent.KEYCODE_DEL == keyCode) { + if (oldStart == 0 && oldEnd == 0) { + sendDomEvent(event); + return true; + } + if (down) { + mGotDelete = true; + mDelSelStart = oldStart; + mDelSelEnd = oldEnd; + } } if ((mSingle && KeyEvent.KEYCODE_ENTER == keyCode)) { @@ -412,17 +424,38 @@ import java.util.ArrayList; mPreChange = postChange; if (0 == count) { if (before > 0) { + // For this and all changes to the text, update our cache + updateCachedTextfield(); + if (mGotDelete) { + mGotDelete = false; + int oldEnd = start + before; + if (mDelSelEnd == oldEnd + && (mDelSelStart == start + || (mDelSelStart == oldEnd && before == 1))) { + // If the selection is set up properly before the + // delete, send the DOM events. + sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN, + KeyEvent.KEYCODE_DEL)); + sendDomEvent(new KeyEvent(KeyEvent.ACTION_UP, + KeyEvent.KEYCODE_DEL)); + return; + } + } // This was simply a delete or a cut, so just delete the // selection. mWebView.deleteSelection(start, start + before); - // For this and all changes to the text, update our cache - updateCachedTextfield(); } + mGotDelete = false; // before should never be negative, so whether it was a cut // (handled above), or before is 0, in which case nothing has // changed, we should return. return; } + // Ensure that this flag gets cleared, since with autocorrect on, a + // delete key press may have a more complex result than deleting one + // character or the existing selection, so it will not get cleared + // above. + mGotDelete = false; // Find the last character being replaced. If it can be represented by // events, we will pass them to native (after replacing the beginning // of the changed text), so we can see javascript events. |