修复从右到左语言切换时 Atom 光标的行为

我一直在尝试更改文本编辑器 Atom 的默认设置,以支持 RTL(从右到左)语言。

所以在课堂上,我在这里LinesTileComponent添加了一个新属性。dir="rtl"

这已将整个脚本切换为向右切换,如此处所示。

https://i.stack.imgur.com/QfBR0.gif

键入阿拉伯语时光标消失。对文本的任何点击都不会带回光标(稍后在 GIF 中发生)。我无法从行外选择一个特定的单词,当我在 RTL 文本之后单击时,光标只会出现在左侧。

我怀疑这可能是由于cursor.jscursor.lessselection.js或其他中的代码造成的。

我正在努力解决这个光标的行为。是否有任何特定文件或快速修复程序可以帮助您解决此问题?


梦里花落0921
浏览 83回答 1
1回答

慕少森

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

相关分类

JavaScript