问题描述
在编辑器中粘贴带有 unicode 的文本时,例如:
?? Please give me an authentic answer buddy.
并且正在做:
getCurrentInputConnection().setSelection(31,43);
所选文本不在正确位置。可能是因为开头的两个特殊的unicode字符?
解决方法
我相信这个功能可以解决这个问题:
public void setSelectionByUnicodePosition(InputConnection inputConnection,String currentString,int start,int end){
int firstUnicodeposition = currentString.offsetByCodePoints(0,start);
int secondUnicodePosition = currentString.offsetByCodePoints(0,end);
inputConnection.setSelection(firstUnicodeposition,secondUnicodePosition);
}