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

Yuko (トーク | 投稿記録)
編集の要約なし
Yuko (トーク | 投稿記録)
編集の要約なし
1行目: 1行目:
== 選択範囲を広げる ==
== 選択範囲を徐々に広げる ==
選択範囲を徐々に広げます。VSCode や IntelliJ っぽいやつです。
選択範囲を徐々に広げます。VSCode や IntelliJ っぽいやつです。


17行目: 17行目:
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
#title = "選択範囲を広げる"
#title = "選択範囲を広げる"
/**
/**
  * 選択範囲を広げるためのマクロです。
  * 選択範囲を広げるためのマクロです。
76行目: 75行目:
             // ドットの場合
             // ドットの場合
             // ドットの1つ右の単語まで拡張
             // ドットの1つ右の単語まで拡張
             selectFuncNameToChild(sel.GetActivePos());
             selectFuncNameToChild(sel.GetActivePos() - 1);
         }
         }
     } else {
     } else {
98行目: 97行目:
             // 末尾方向にドットを検索
             // 末尾方向にドットを検索
             sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
             sel.SetActivePoint(mePosLogical, bottomX, bottomY, false);
             selectFuncNameToChild(sel.GetActivePos() + 1);
             selectFuncNameToChild(sel.GetActivePos());
             sel.SetAnchorPoint(mePosLogical, topX, topY);
             sel.SetAnchorPoint(mePosLogical, topX, topY);
         } else if (rightIndex % 2 === 0) {
         } else if (rightIndex % 2 === 0) {
142行目: 141行目:


function selectFuncNameToChild(pos) {
function selectFuncNameToChild(pos) {
     var minIndex = txt.length;
     var movePos = txt.slice(pos + 1).search(/[^a-z0-9()]/i) + pos + 1;
    var toSeparator = txt.indexOf(".", pos);
     sel.SetActivePos(movePos, true);
    if (toSeparator !== -1 && toSeparator < minIndex) minIndex = toSeparator;
    toSeparator = txt.indexOf("\n", pos);
    if (toSeparator !== -1 && toSeparator < minIndex) minIndex = toSeparator;
    toSeparator = txt.indexOf(" ", pos);
    if (toSeparator !== -1 && toSeparator < minIndex) minIndex = toSeparator;
    toSeparator = txt.indexOf("\t", pos);
    if (toSeparator !== -1 && toSeparator < minIndex) minIndex = toSeparator;
    toSeparator = txt.indexOf(" ", pos);
    if (toSeparator !== -1 && toSeparator < minIndex) minIndex = toSeparator;
     sel.SetActivePos(minIndex, true);
}
}


259行目: 248行目:
     sel.SetActivePos(startPos);
     sel.SetActivePos(startPos);
     sel.SetActivePos(endPos, true);
     sel.SetActivePos(endPos, true);
}
function moveToBracketEnd(selectStartPos, selectEndPos) {
    //■範囲選択(true:する/false:しない)
    var SHIFT = true;
    quit: {
        var startPos = selectStartPos;
        var endPos = selectEndPos;
        var startChar = txt.charAt(startPos - 1); //選択範囲開始左側の文字を取得
        var startBrcIdx = BRACKET.indexOf(startChar);
        var endChar = txt.charAt(selectEndPos); //選択範囲末尾右側の文字を取得
        var endBrcIdx = BRACKET.indexOf(endChar);
        var nest = 1;
        var s;
        var e;
        var pairChar;
        if (leftCharIsStartBracket(selectStartPos)) {
            //◆開き括弧の場合、末尾方向へ探す
            pairChar = BRACKET.charAt(startBrcIdx + 1); //対応する閉じ括弧を取得
            s = txt.indexOf(startChar, startPos - 1);
            while (nest) {
                e = txt.indexOf(pairChar, s + 1);
                s = txt.indexOf(startChar, s + 1);
                if (e === -1) break;
                if (s < e && s !== -1) {
                    nest++;
                    e = s;
                } else {
                    nest--;
                    s = e;
                }
                if (e !== -1 && endPos < e) {
                    endPos = e;
                }
            }
        } else if (rightCharIsEndBracket(selectEndPos)) {
            //◆閉じ括弧の場合、先頭方向へ探す
            pairChar = BRACKET.charAt(endBrcIdx - 1); //対応する開き括弧を取得
            e = txt.lastIndexOf(endChar, endPos);
            while (nest) {
                s = txt.lastIndexOf(pairChar, e - 1);
                e = txt.lastIndexOf(endChar, e - 1);
                if (s === -1 || startPos <= 0) break;
                if (s < e && s !== -1) {
                    nest++;
                    s = e;
                } else {
                    nest--;
                    e = s;
                }
                if (s !== -1 && startPos > s) {
                    startPos = s + 1;
                }
            }
        } else {
            break quit;
        }
        sel.SetActivePos(startPos);
        sel.SetActivePos(endPos, SHIFT);
    }
}
}


スポンサーリンク