1 回答
TA贡献2019条经验 获得超9个赞
这是一个很难修复的错误。该修复程序已在Github PR上提交以供审查,以便 RTL 签出并做出贡献。
https://i.stack.imgur.com/QGbVA.gif
总之,开发人员使用二分搜索算法来查找用户点击了哪个字母。二进制搜索方法假设单词的后半部分总是在右边。这与 RTL 语言相反,因为工作的后半部分在左侧。这是我如何制作修复原型的片段:
let characterIndex = 0;
{
let low = 0;
let high = containingTextNode.length - 1;
while (low <= high) {
const charIndex = low + ((high - low) >> 1);
const nextCharIndex = isPairedCharacter(
containingTextNode.textContent,
charIndex
)
? charIndex + 2
: charIndex + 1;
const rangeRect = clientRectForRange(
containingTextNode,
charIndex,
nextCharIndex
);
if (targetClientLeft < rangeRect.left && !rtl) {
high = charIndex - 1;
characterIndex = Math.max(0, charIndex - 1);
} else if (targetClientLeft > rangeRect.right && !rtl) {
low = nextCharIndex;
characterIndex = Math.min(
containingTextNode.textContent.length,
nextCharIndex
);
} else if (targetClientLeft > rangeRect.right && rtl) {
high = charIndex - 1;
characterIndex = Math.max(0, charIndex - 1);
} else if (targetClientLeft < rangeRect.left && rtl) {
low = nextCharIndex;
characterIndex = Math.min(
containingTextNode.textContent.length,
nextCharIndex
);
} else {
if (!rtl){
if (targetClientLeft <= (rangeRect.left + rangeRect.right) / 2) {
characterIndex = charIndex;
} else {
characterIndex = nextCharIndex;
}
}else{
if (targetClientLeft <= (rangeRect.left + rangeRect.right) / 2) {
characterIndex = nextCharIndex;
} else {
characterIndex = charIndex;
}
}
break;
}
}
}
不幸的是,此代码仍然缺少一些功能,例如在同一行中处理 RTL 和 LTR 内容以及其他小错误。应该做更多的工作并且合作是开放的,请为此 PR 做出贡献。
添加回答
举报