亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

修復從右到左語言切換時 Atom 光標的行為

修復從右到左語言切換時 Atom 光標的行為

夢里花落0921 2022-10-13 16:25:21
我一直在嘗試更改文本編輯器 Atom 的默認設置,以支持 RTL(從右到左)語言。所以在課堂上,我在這里LinesTileComponent添加了一個新屬性。dir="rtl"這已將整個腳本切換為向右切換,如此處所示。https://i.stack.imgur.com/QfBR0.gif鍵入阿拉伯語時光標消失。對文本的任何點擊都不會帶回光標(稍后在 GIF 中發生)。我無法從行外選擇一個特定的單詞,當我在 RTL 文本之后單擊時,光標只會出現在左側。我懷疑這可能是由于cursor.js、cursor.less或selection.js或其他中的代碼造成的。我正在努力解決這個光標的行為。是否有任何特定文件或快速修復程序可以幫助您解決此問題?
查看完整描述

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 做出貢獻。



查看完整回答
反對 回復 2022-10-13
  • 1 回答
  • 0 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號