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 做出貢獻。
添加回答
舉報