「選択範囲を広げる」の版間の差分

Yuko (トーク | 投稿記録)
編集の要約なし
Yuko (トーク | 投稿記録)
編集の要約なし
6行目: 6行目:
=== 未選択状態での動作: ===
=== 未選択状態での動作: ===
* 選択範囲が空の場合、カーソル位置の単語を選択します。
* 選択範囲が空の場合、カーソル位置の単語を選択します。
* カーソル位置が括弧だった場合は、括弧の中身を選択します。
* カーソル位置が括弧だった場合は、括弧の中身も選択します。
* ドットを検出した場合は、ドットの1つ右の単語まで拡張します。
* ドットを検出した場合は、ドットの1つ右の単語も選択します。
* ハイフンを検出した場合は、ハイフンで区切られた1つ右の単語も選択します。


=== 選択状態での動作: ===
=== 選択状態での動作: ===
* 選択範囲がある場合、選択範囲の前後にある括弧を検出し、その中身を選択します。
* 選択範囲がある場合、選択範囲の前後にある括弧を検出し、その中身を選択します。
* ドットを検出した場合は、ドットの1つ左または右の単語まで拡張します。
* ドットを検出した場合は、ドットの1つ左または右の単語まで拡張します。
* ハイフンを検出した場合は、ハイフンで区切られた1つ右の単語まで拡張します。
* これらの記号を検出しなかった場合は、単純な選択範囲の拡張を行います。
* これらの記号を検出しなかった場合は、単純な選択範囲の拡張を行います。


21行目: 23行目:
  *  
  *  
  * 選択範囲が空の場合、カーソル位置の単語を選択します。
  * 選択範囲が空の場合、カーソル位置の単語を選択します。
  * カーソル位置が括弧だった場合は、括弧の中身を選択します。
  * カーソル位置が括弧だった場合は、括弧の中身も選択します。
  * ドットを検出した場合は、ドットの1つ右の単語まで拡張します。
  * ドットを検出した場合は、ドットの1つ右の単語も選択します。
* ハイフンを検出した場合は、ハイフンで区切られた1つ右の単語も選択します。
  *  
  *  
  * 選択範囲がある場合、選択範囲の前後にある括弧を検出し、その中身を選択します。
  * 選択範囲がある場合、選択範囲の前後にある括弧を検出し、その中身を選択します。
  * ドットを検出した場合は、ドットの1つ左または右の単語まで拡張します。
  * ドットを検出した場合は、ドットの1つ左または右の単語まで拡張します。
* ハイフンを検出した場合は、ハイフンで区切られた1つ右の単語まで拡張します。
  * これらの記号を検出しなかった場合は、単純な選択範囲の拡張を行います。
  * これらの記号を検出しなかった場合は、単純な選択範囲の拡張を行います。
  */
  */
43行目: 47行目:
     if (sel.IsEmpty) {
     if (sel.IsEmpty) {
         // 未選択の場合
         // 未選択の場合
 
        var beforePos = sel.GetActivePos();
         sel.SelectWord();
         sel.SelectWord();


67行目: 71行目:
                 var activePos = sel.GetActivePos();
                 var activePos = sel.GetActivePos();
                 selectToBracketEnd(topX, topY, bottomX, bottomY, selChar);
                 selectToBracketEnd(topX, topY, bottomX, bottomY, selChar);
                 if (activePos !== sel.GetActivePos()) {
                 if (beforePos === activePos) {
                    // 行末で先頭方向に向かって選択していた場合は、先頭の開き括弧の選択を外す
                    sel.SetAnchorPos(beforePos);
                } else if (activePos !== sel.GetActivePos()) {
                     // 括弧の中身が選択された場合、閉じ括弧も選択する
                     // 括弧の中身が選択された場合、閉じ括弧も選択する
                     sel.SetActivePos(sel.GetActivePos() + 1, true);
                     sel.SetActivePos(sel.GetActivePos() + 1, true);
76行目: 83行目:
             // ドットの1つ右の単語まで拡張
             // ドットの1つ右の単語まで拡張
             selectFuncNameToChild(sel.GetActivePos() - 1);
             selectFuncNameToChild(sel.GetActivePos() - 1);
        } else if (selChar === "-") {
            // ドットの場合
            // ドットの1つ右の単語まで拡張
            selectHyphenSeparatedWord(sel.GetActivePos() - 1);
         }
         }
     } else {
     } else {
         // 選択済みの場合
         // 選択済みの場合


         // 選択範囲の左右の文字を取得
         // 現在の選択範囲を取得
         var topX = sel.GetTopPointX(mePosLogical);
         var topX = sel.GetTopPointX(mePosLogical);
         var topY = sel.GetTopPointY(mePosLogical);
         var topY = sel.GetTopPointY(mePosLogical);
98行目: 109行目:
             sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
             sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
             selectFuncNameToChild(sel.GetActivePos());
             selectFuncNameToChild(sel.GetActivePos());
            sel.SetAnchorPoint(mePosLogical, topX, topY);
        } else if (rightChar === "-") {
            // 選択範囲の右にハイフンがある場合
            sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
            selectHyphenSeparatedWord(sel.GetActivePos());
             sel.SetAnchorPoint(mePosLogical, topX, topY);
             sel.SetAnchorPoint(mePosLogical, topX, topY);
         } else if (rightIndex % 2 === 0) {
         } else if (rightIndex % 2 === 0) {
116行目: 132行目:
             selectToBracketStart(topX, topY, bottomX, bottomY, rightChar);
             selectToBracketStart(topX, topY, bottomX, bottomY, rightChar);
         } else if (leftIndex % 2 === 0) {
         } else if (leftIndex % 2 === 0) {
            alert(leftChar)
             // 左位置に括弧があるかをチェック
             // 左位置に括弧があるかをチェック
             // 選択範囲を広げる
             // 選択範囲を広げる
141行目: 156行目:


function selectFuncNameToChild(pos) {
function selectFuncNameToChild(pos) {
     var movePos = txt.slice(pos + 1).search(/[^a-z0-9]/i) + pos + 1;
     var movePos = txt.slice(pos + 1).search(/[^a-z0-9_-]/i) + pos + 1;
     sel.SetActivePos(movePos, true);
     sel.SetActivePos(movePos, true);
}
}
155行目: 170行目:
}
}


// 単純な選択範囲の広げ
function selectHyphenSeparatedWord(pos) {
    var movePos = txt.slice(pos + 1).search(/[^a-z0-9_]/i) + pos + 1;
    sel.SetActivePos(movePos, true);
}
 
// 単純な選択範囲の拡大
function simpleExpand(topX, topY, bottomX, bottomY, offset) {
function simpleExpand(topX, topY, bottomX, bottomY, offset) {
     // 左側を広げ位置を取得
     // 拡大範囲は行を跨がないようにする
    sel.SetActivePoint(mePosLogical, topX, topY, false);
 
    sel.CharLeft(false, 1 + offset);
     // 左側の拡大後の位置を取得
     sel.SelectWord();
     var simpleExpandTopX = sel.GetTopPointX(mePosLogical);
     var simpleExpandTopX = sel.GetTopPointX(mePosLogical);
     var simpleExpandTopY = sel.GetTopPointY(mePosLogical);
     var simpleExpandTopY = sel.GetTopPointY(mePosLogical);
    sel.SetActivePoint(mePosLogical, topX, topY, false);
    var leftChar = txt.charAt(sel.GetActivePos() - 1);
    if (leftChar !== "\n" && leftChar !== "") {
        // 行頭以外のときだけ、左側を拡大
        sel.CharLeft(false, 1 + offset);
        sel.SelectWord();
        simpleExpandTopX = sel.GetTopPointX(mePosLogical);
        simpleExpandTopY = sel.GetTopPointY(mePosLogical);
    }


     // 右側を広げ位置を取得
     // 右側の拡大後の位置を取得
     sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
     sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
    if (offset > 0) sel.CharRight(false, offset);
    sel.SelectWord();
     var simpleExpandBottomX = sel.GetBottomPointX(mePosLogical);
     var simpleExpandBottomX = sel.GetBottomPointX(mePosLogical);
     var simpleExpandBottomY = sel.GetBottomPointY(mePosLogical);
     var simpleExpandBottomY = sel.GetBottomPointY(mePosLogical);
    var rightChar = txt.charAt(sel.GetActivePos());
    if (rightChar !== "\n" && rightChar !== "") {
        // 行末以外のときだけ、右側を拡大
        if (offset > 0) {
            sel.CharRight(false, offset);
        }
        sel.SelectWord();
        simpleExpandBottomX = sel.GetBottomPointX(mePosLogical);
        simpleExpandBottomY = sel.GetBottomPointY(mePosLogical);
    }


     // 選択範囲を広げる
     // 選択範囲を広げる
スポンサーリンク