Moh*_*aie 5 javascript right-to-left coffeescript atom-editor
我一直在尝试更改文本编辑器 Atom 的默认设置,以支持 RTL(从右到左)语言。
所以在课堂上LinesTileComponent,我dir="rtl" 在这里添加了一个新属性。
这已将整个脚本切换到右侧,如下所示。
输入阿拉伯语时光标消失。对文本的任何点击都不会返回光标(稍后在 GIF 中发生)。我无法从该行中选择一个特定的单词,并且当我在 RTL 文本之后单击时,光标只会出现在左侧。
我怀疑这可能是由于cursor.js、cursor.less或selection.js或其他人的代码。
我正在努力修复此光标的行为。是否有任何特定文件或快速修复程序可以帮助您解决此问题?
这是一个很难修复的错误。该修复已提交到Github PR上供 RTL 审核并做出贡献。
总之,开发人员使用二分搜索算法来查找用户点击了哪个字母。二分查找方法假设单词的后半部分始终位于右侧。这与 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这段代码仍然缺少一些功能,例如处理同一行中的 RTL 和 LTR 内容以及其他小错误。应该做更多的工作并且合作是开放的,请为此 PR 做出贡献。
| 归档时间: |
|
| 查看次数: |
408 次 |
| 最近记录: |