RTL(右から左)言語をサポートするために、テキストエディタであるAtomのデフォルト設定を変更しようとしています。
そのため、クラスではLinesTileComponent
、dir="rtl"
ここに新しい属性を追加しました。
これにより、ここに示すように、スクリプト全体が右に切り替わりました。
アラビア語を入力するとカーソルが消えます。テキストをクリックしてもカーソルは戻りません(後でGIFで発生します)。行から特定の単語を選択する方法はありません。カーソルは、RTLテキストの後にクリックしたときにのみ左側に表示されます。
I'm suspecting this could be due to the code on cursor.js, cursor.less or in selection.js or others.
I'm struggling with fixing this cursor's behaviour. Are there any specific files or quick fixes that you could help with to fix this issue?
This has been a tough bug to fix. The fix has been submitted for review on Github PR for RTL to check out and contribute to.
要約すると、開発者はバイナリ検索アルゴリズムを使用して、ユーザーがクリックした文字を見つけました。二分探索アプローチでは、単語の後半が常に右側にあると想定していました。作業の後半が左側にあるため、これは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に貢献してください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加