コメントの挿入/削除マクロ
選択範囲の各行について、行コメントのあるなしを切り替えます。
function ToggleLineComment() {
with (document.selection) {
Collapse();
StartOfLine(false, eeLineLogical);
LineDown(true, 1);
var before = Text;
editor.ExecuteCommandByID(4371);
var after = Text;
//行コメント用の記号(//とか)
var commmark = after.substr(0, after.indexOf(before));
if (commmark.length > 0) {
if (before.indexOf(commmark) == 0) {
//すでにコメントになっている
editor.ExecuteCommandByID(4372);
editor.ExecuteCommandByID(4372);
}
}
}
}
Redraw = false;
with (document.selection) {
var y0 = GetTopPointY(eePosLogical);
var y1 = GetBottomPointY(eePosLogical);
if (GetBottomPointX(eePosLogical) == 1) y1 -= 1;
if (y0 >= y1) {
//複数行選択ではない
SetActivePoint(eePosLogical, 1, y0, false);
ToggleLineComment();
} else {
var reverse = (GetActivePointY(eePosLogical) == y0);
//複数行選択中
for (var y= y0 ; y <= y1 ; ++y) {
SetActivePoint(eePosLogical, 1, y, false);
ToggleLineComment();
}
//選択の復元
SetActivePoint(eePosLogical, 1, reverse ? (y1 + 1) : y0, false);
SetActivePoint(eePosLogical, 1, reverse ? y0 : (y1 + 1), true);
}
}
Redraw = true;
