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

MSY-07 (トーク | 投稿記録)
注意事項の追加、見出しの追加
MSY-07 (トーク | 投稿記録)
スペースからタブに変更、空白の除去
40行目: 40行目:
// 行頭からタブの数を確認
// 行頭からタブの数を確認
for (var j = 0; j < s.length; j++) {
for (var j = 0; j < s.length; j++) {
  c = s.charAt(j);
c = s.charAt(j);
  if (indent.test(c)) {
if (indent.test(c)) {
    i++;
i++;
  } else {
} else {
    break;
break;
  }
}
}
}


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


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


(function(){
(function(){
  var sel = Document.Selection;
var sel = Document.Selection;
  var meP = logic? mePosLogical: mePosView;
var meP = logic? mePosLogical: mePosView;
  var meGL = logic? 0: meGetLineView;
var meGL = logic? 0: meGetLineView;
  var px = sel.GetActivePointX(meP);
var px = sel.GetActivePointX(meP);
  var py = sel.GetActivePointY(meP);
var py = sel.GetActivePointY(meP);
  var line = Document.GetLine(py, meGL);
var line = Document.GetLine(py, meGL);
  var ix = 1+ (line.match(indent)||{lastIndex:0}).lastIndex;
var ix = 1+ (line.match(indent)||{lastIndex:0}).lastIndex;
  if (ix<px) //◆ix<px インデント位置<カーソル位置の場合、インデント位置へ
if (ix<px) //◆ix<px インデント位置<カーソル位置の場合、インデント位置へ
    sel.SetActivePoint(meP, ix, py, shift);
sel.SetActivePoint(meP, ix, py, shift);
  else //◆px<=ix カーソル位置≦インデント位置の場合、行頭へ
else //◆px<=ix カーソル位置≦インデント位置の場合、行頭へ
    sel.StartOfLine(shift, meP);
sel.StartOfLine(shift, meP);
})();
})();
</syntaxhighlight>
</syntaxhighlight>
105行目: 105行目:
var indent = /^[  \t]+/;  // インデントの定義
var indent = /^[  \t]+/;  // インデントの定義
(function(){
(function(){
    var getToXView = function(line, nowX, ignore_indent) {
var getToXView = function(line, nowX, ignore_indent) {
        if (ignore_indent) return 1;
if (ignore_indent) return 1;
        var m = line.match(indent);
var m = line.match(indent);
        var toX = (m === null) ? 1 : (1 + m.lastIndex);
var toX = (m === null) ? 1 : (1 + m.lastIndex);
        return (toX < nowX) ? toX : 1;
return (toX < nowX) ? toX : 1;
    };
};
    var sel = Document.Selection;
var sel = Document.Selection;
    var tp = sel.GetTopPointX(mePosLogical);
var tp = sel.GetTopPointX(mePosLogical);
    var bt = sel.GetBottomPointX(mePosLogical);
var bt = sel.GetBottomPointX(mePosLogical);
    var selecting_now = (tp != bt);
var selecting_now = (tp != bt);
    var posX_l = sel.GetActivePointX(mePosLogical);
var posX_l = sel.GetActivePointX(mePosLogical);
    var posY_l = sel.GetActivePointY(mePosLogical);
var posY_l = sel.GetActivePointY(mePosLogical);
    var posX_v = sel.GetActivePointX(mePosView);
var posX_v = sel.GetActivePointX(mePosView);
    var posY_v = sel.GetActivePointY(mePosView);
var posY_v = sel.GetActivePointY(mePosView);
    if (posX_l == 1) {
if (posX_l == 1) {
        if (go_prev_line) {
if (go_prev_line) {
            sel.LineUp(selecting_now, 1);
sel.LineUp(selecting_now, 1);
            if (posY_v != sel.GetActivePointY(mePosView)) {
if (posY_v != sel.GetActivePointY(mePosView)) {
                sel.EndOfLine(selecting_now, mePosView);
sel.EndOfLine(selecting_now, mePosView);
            }
}
        }
}
        return;
return;
    }
}
    var toX_v = null;
var toX_v = null;
    var line_l = Document.GetLine(posY_l, 0);
var line_l = Document.GetLine(posY_l, 0);
    var line_v = Document.GetLine(posY_v, meGetLineView);
var line_v = Document.GetLine(posY_v, meGetLineView);
    if (view_line && (line_l != line_v)) {
if (view_line && (line_l != line_v)) {
        if (posX_v > 1) {
if (posX_v > 1) {
            toX_v = getToXView(line_v, posX_v, (!view_line_indent));
toX_v = getToXView(line_v, posX_v, (!view_line_indent));
            sel.SetActivePoint(mePosView, toX_v, posY_v, selecting_now);
sel.SetActivePoint(mePosView, toX_v, posY_v, selecting_now);
        } else if (posY_v - posY_l > 1) {
} else if (posY_v - posY_l > 1) {
            toX_v = getToXView(Document.GetLine(posY_v - 1, meGetLineView), 9999, (!view_line_indent));
toX_v = getToXView(Document.GetLine(posY_v - 1, meGetLineView), 9999, (!view_line_indent));
            sel.SetActivePoint(mePosView, toX_v, posY_v - 1, selecting_now);
sel.SetActivePoint(mePosView, toX_v, posY_v - 1, selecting_now);
        }
}
    }
}
    if (toX_v === null) {
if (toX_v === null) {
        var m = line_l.match(indent);
var m = line_l.match(indent);
        toX_v = (m === null) ? 1 : (1 + m.lastIndex);
toX_v = (m === null) ? 1 : (1 + m.lastIndex);
        if (toX_v >= posX_l) toX_v = 1;
if (toX_v >= posX_l) toX_v = 1;
        sel.SetActivePoint(mePosLogical, toX_v, posY_l, selecting_now);
sel.SetActivePoint(mePosLogical, toX_v, posY_l, selecting_now);
    }
}
})();
})();
</syntaxhighlight>
</syntaxhighlight>
163行目: 163行目:


(function(){
(function(){
    var d = document, s = d.selection;
var d = document, s = d.selection;
    var meP = logic ? mePosLogical : mePosView;
var meP = logic ? mePosLogical : mePosView;
    var meGL = logic ? 0 : meGetLineView;
var meGL = logic ? 0 : meGetLineView;


    Redraw = false;
Redraw = false;
    var x = s.GetActivePointX( meP );
var x = s.GetActivePointX( meP );
    var y = s.GetActivePointY( meP );
var y = s.GetActivePointY( meP );
    var pos = s.GetActivePos(); // 現在位置
var pos = s.GetActivePos(); // 現在位置
    var top = pos + 1 - x;      // 行頭位置
var top = pos + 1 - x;      // 行頭位置
    var st = d.GetLine( y, meGL );
var st = d.GetLine( y, meGL );
    var sId = st.search( indent );    // 行頭の空白文字数
var sId = st.search( indent );    // 行頭の空白文字数
    var ind = top + sId;    // インデントの後ろ位置
var ind = top + sId;    // インデントの後ろ位置


    if ( ind < pos ) {
if ( ind < pos ) {
        // 文字列開始位置に移動(インデントの後ろ)
// 文字列開始位置に移動(インデントの後ろ)
        s.SetActivePos( ind, shift );
s.SetActivePos( ind, shift );
    }
}
    else {
else {
        // 文頭に移動
// 文頭に移動
        s.StartOfLine( shift, meP );
s.StartOfLine( shift, meP );
    }
}


    Redraw = true;
Redraw = true;
})();
})();
</syntaxhighlight>
</syntaxhighlight>
スポンサーリンク