【关键字】
API 11 / 光标位置 / 输入框 / 自定义键盘 / getCaretOffset
【问题描述】
自定义键盘删除键实现的逻辑,需要获取到当前光标位置。但是目前API没有相关方法,只有设置光标位置的方法caretPosition,没有获取光标位置的方法。
【解决方案】
getCaretOffset方法可以获得TextInput内的光标位置,参考链接如下:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-basic-components-textinput-0000001774121266#ZH-CN_TOPIC_0000001774121266__getcaretoffset11