行頭に移動
インデント位置<カーソル位置の場合は、インデント位置に、
カーソル位置≦インデント位置の場合は、(表示)行頭に移動します。
「Home」キーなどに割り当ててご利用ください。
「shift」変数を「true」に書き換えると、選択しながら移動します。
「Shift + Home」キーなどに割り当ててご利用ください。
Kuro 版
// -----------------------------------------------------------------------------
// 行頭に移動
//
// Copyright (c) Kuro. All Rights Reserved.
// www: http://www.haijin-boys.com/
// -----------------------------------------------------------------------------
// シフトの状態(オンの場合は選択、オフの場合は移動)
var shift = false;
// インデントとして認識する文字(半角空白、全角空白、タブ)
var indent = new RegExp(" | |\t");
// 現在位置取得
var x1 = document.selection.GetActivePointX(mePosView);
var y1 = document.selection.GetActivePointY(mePosView);
// 選択終了位置取得
var x2 = document.selection.GetBottomPointX(mePosView);
var y2 = document.selection.GetBottomPointY(mePosView);
// カーソルを行末に移動
document.selection.EndOfLine(false);
// カーソルを行頭に移動(これで1行選択)
document.selection.StartOfLine(true);
var s = document.selection.Text;
var i = 0;
// 行頭からタブの数を確認
for (var j = 0; j < s.length; j++) {
c = s.charAt(j);
if (indent.test(c))
i++;
else
break;
}
// シフトオンの場合、選択終了位置に移動
if (shift)
document.selection.SetActivePoint(mePosView, x2, y2, false);
// 現在位置が1より大きくてタブの数以下の場合は行頭に移動
if (x1 > 1 && x1 <= i + 1)
document.selection.StartOfLine(shift);
// それ以外の場合はタブの数だけ進める
else
document.selection.SetActivePoint(mePosView, i + 1, y1, shift);
masme 版 (2014/02) ※バグのため公開停止
- 2014/02/07 正常に動作しないバグが見つかったため、公開停止中です。
スポンサーリンク