浏览代码

Fix Android delete problem.

/main
Yuncong Zhang 5 年前
当前提交
6afee74a
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16
      Runtime/Plugins/platform/android/editing/InputConnectionAdaptor.java

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


if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
int selStart = Selection.getSelectionStart(mEditable);
int selEnd = Selection.getSelectionEnd(mEditable);
String text = mEditable.toString();
if(selStart >= 0 && selStart < text.length() && isTrailSurrogate(text.charAt(selStart)))
selStart++;
if(selEnd >= 0 && selEnd < text.length() && isTrailSurrogate(text.charAt(selEnd)))
selEnd++;
if (selEnd > selStart) {
// Delete the selection.
Selection.setSelection(mEditable, selStart);

} else if (selStart > 0) {
// Delete to the left of the cursor.
int newSel = Math.max(selStart - 1, 0);
if(selStart >= 2 && isTrailSurrogate(text.charAt(selStart-1)))
newSel = selStart - 2;
Selection.setSelection(mEditable, newSel);
mEditable.delete(newSel, selStart);
updateEditingState();

break;
}
return true;
}
private boolean isLeadSurrogate(int c) {
return (c & 0xfffffc00) == 0xd800;
}
private boolean isTrailSurrogate(int c) {
return (c & 0xfffffc00) == 0xdc00;
}
}
正在加载...
取消
保存