「行頭に移動」の版間の差分

MSY-07 (トーク | 投稿記録)
スペースからタブに変更、空白の除去
MSY-07 (トーク | 投稿記録)
ソースコードの最適化
20行目: 20行目:
// インデントとして認識する文字(半角空白、全角空白、タブ)
// インデントとして認識する文字(半角空白、全角空白、タブ)
var indent = new RegExp(" | |\t");
var indent = new RegExp(" | |\t");
// Selection オブジェクトを取得
var sel = document.selection;


// 現在位置取得
// 現在位置取得
var x1 = document.selection.GetActivePointX(mePosView);
var x1 = sel.GetActivePointX(mePosView);
var y1 = document.selection.GetActivePointY(mePosView);
var y1 = sel.GetActivePointY(mePosView);


// 選択終了位置取得
// 選択終了位置取得
var x2 = document.selection.GetBottomPointX(mePosView);
var x2 = sel.GetBottomPointX(mePosView);
var y2 = document.selection.GetBottomPointY(mePosView);
var y2 = sel.GetBottomPointY(mePosView);


// カーソルを行末に移動
// カーソルを行末に移動
document.selection.EndOfLine(false);
sel.EndOfLine(false);


// カーソルを行頭に移動(これで1行選択)
// カーソルを行頭に移動(これで1行選択)
document.selection.StartOfLine(true);
sel.StartOfLine(true);


var s = document.selection.Text;
var s = sel.Text;
var i = 0;
var i = 0;


50行目: 53行目:
// シフトオンの場合、選択終了位置に移動
// シフトオンの場合、選択終了位置に移動
if (shift) {
if (shift) {
document.selection.SetActivePoint(mePosView, x2, y2, false);
sel.SetActivePoint(mePosView, x2, y2, false);
}
}


// 現在位置が1より大きくてタブの数以下の場合は行頭に移動
// 現在位置が1より大きくてタブの数以下の場合は行頭に移動
if (x1 > 1 && x1 <= i + 1) {
if (x1 > 1 && x1 <= i + 1) {
document.selection.StartOfLine(shift);
sel.StartOfLine(shift);
// それ以外の場合はタブの数だけ進める
// それ以外の場合はタブの数だけ進める
} else {
} else {
document.selection.SetActivePoint(mePosView, i + 1, y1, shift);
sel.SetActivePoint(mePosView, i + 1, y1, shift);
}
}
</syntaxhighlight>
</syntaxhighlight>
スポンサーリンク