This repository was archived by the owner on Apr 29, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Runtime/Plugins/platform/android/editing Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,11 @@ public boolean sendKeyEvent(KeyEvent event) {
130
130
if (event .getKeyCode () == KeyEvent .KEYCODE_DEL ) {
131
131
int selStart = Selection .getSelectionStart (mEditable );
132
132
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 ++;
133
138
if (selEnd > selStart ) {
134
139
// Delete the selection.
135
140
Selection .setSelection (mEditable , selStart );
@@ -139,6 +144,8 @@ public boolean sendKeyEvent(KeyEvent event) {
139
144
} else if (selStart > 0 ) {
140
145
// Delete to the left of the cursor.
141
146
int newSel = Math .max (selStart - 1 , 0 );
147
+ if (selStart >= 2 && isTrailSurrogate (text .charAt (selStart -1 )))
148
+ newSel = selStart - 2 ;
142
149
Selection .setSelection (mEditable , newSel );
143
150
mEditable .delete (newSel , selStart );
144
151
updateEditingState ();
@@ -212,4 +219,13 @@ public boolean performEditorAction(int actionCode) {
212
219
}
213
220
return true ;
214
221
}
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
+ }
215
231
}
You can’t perform that action at this time.
0 commit comments