1 回答
TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個贊
這是一個很難修復(fù)的錯誤。該修復(fù)程序已在Github PR上提交以供審查,以便 RTL 簽出并做出貢獻(xiàn)。
https://i.stack.imgur.com/QGbVA.gif
總之,開發(fā)人員使用二分搜索算法來查找用戶點(diǎn)擊了哪個字母。二進(jìn)制搜索方法假設(shè)單詞的后半部分總是在右邊。這與 RTL 語言相反,因?yàn)楣ぷ鞯暮蟀氩糠衷谧髠?cè)。這是我如何制作修復(fù)原型的片段:
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 內(nèi)容以及其他小錯誤。應(yīng)該做更多的工作并且合作是開放的,請為此 PR 做出貢獻(xiàn)。
添加回答
舉報(bào)
