Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit d5efe76

Browse files
author
Yuncong Zhang
committed
Fix Android delete problem.
1 parent a78ca0f commit d5efe76

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Runtime/Plugins/platform/android/editing/InputConnectionAdaptor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public boolean sendKeyEvent(KeyEvent event) {
130130
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
131131
int selStart = Selection.getSelectionStart(mEditable);
132132
int selEnd = Selection.getSelectionEnd(mEditable);
133+
String text = mEditable.toString();
134+
if(selStart >= 0 && selStart < text.length() && isTrailSurrogate(text.charAt(selStart)))
135+
selStart++;
136+
if(selEnd >= 0 && selEnd < text.length() && isTrailSurrogate(text.charAt(selEnd)))
137+
selEnd++;
133138
if (selEnd > selStart) {
134139
// Delete the selection.
135140
Selection.setSelection(mEditable, selStart);
@@ -139,6 +144,8 @@ public boolean sendKeyEvent(KeyEvent event) {
139144
} else if (selStart > 0) {
140145
// Delete to the left of the cursor.
141146
int newSel = Math.max(selStart - 1, 0);
147+
if(selStart >= 2 && isTrailSurrogate(text.charAt(selStart-1)))
148+
newSel = selStart - 2;
142149
Selection.setSelection(mEditable, newSel);
143150
mEditable.delete(newSel, selStart);
144151
updateEditingState();
@@ -212,4 +219,13 @@ public boolean performEditorAction(int actionCode) {
212219
}
213220
return true;
214221
}
222+
223+
private boolean isLeadSurrogate(int c) {
224+
return (c & 0xfffffc00) == 0xd800;
225+
}
226+
227+
228+
private boolean isTrailSurrogate(int c) {
229+
return (c & 0xfffffc00) == 0xdc00;
230+
}
215231
}

0 commit comments

Comments
 (0)