「字下げ・字上げ」の版間の差分
ナビゲーションに移動
検索に移動
細 (見出しレベルを1→2に変更) |
(マクロ修正) |
||
3行目: | 3行目: | ||
[[ファイル:Indent-Unindent.png]] | [[ファイル:Indent-Unindent.png]] | ||
==更新履歴== | |||
* 2015/02/14 | |||
** (字上げ) 「インデントの定義」に正規表現の特殊文字があると誤動作する不具合を修正。 | |||
** 矩形選択(始点or終点が左下かつ論理行頭)時、下端の行が範囲から漏れる不具合を修正。 | |||
* 2014/02/09 | |||
** 初版公開。 | |||
==字下げ (インデント)== | ==字下げ (インデント)== | ||
11行目: | 18行目: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
//■字下げ(インデント) | //■字下げ(インデント) | ||
// 2014/02/09 | // 2014/02/09-2015/02/14 | ||
//・論理行単位で字下げする。空行は字下げしない。非選択時/単行選択時はタブ挿入。 | //・論理行単位で字下げする。空行は字下げしない。非選択時/単行選択時はタブ挿入。 | ||
18行目: | 25行目: | ||
with (Document.Selection) { | with (Document.Selection) { | ||
//非選択時/単行選択時はタブ挿入して終了 | |||
if (GetTopPointY(mePosView)==GetBottomPointY(mePosView)) {Text="\t"; Quit();} | |||
var | var ty = GetTopPointY(mePosLogical); | ||
var | var by = GetBottomPointY(mePosLogical); | ||
var | var bx = GetBottomPointX(mePosLogical); | ||
var | var br =(Text.match(/\n/g)||[]).length; | ||
if ( | if (bx==1 && by-ty==br && br) by--; //次行行頭を含めないよう対策 | ||
SetActivePoint( | SetActivePoint(mePosLogical, 1, by+1); | ||
SetAnchorPoint( | SetAnchorPoint(mePosLogical, 1, ty); | ||
Text = Text.replace(/^(?!$)/gm,$indent); //(空行を除く)行頭にインデントを付加 | Text = Text.replace(/^(?!$)/gm,$indent); //(空行を除く)行頭にインデントを付加 | ||
SetActivePoint( | SetActivePoint(mePosLogical, 1, by+1); | ||
SetAnchorPoint( | SetAnchorPoint(mePosLogical, 1, ty); | ||
} | } | ||
</source> | </source> | ||
41行目: | 47行目: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
//■字上げ(アンインデント) | //■字上げ(アンインデント) | ||
// 2014/02/09 | // 2014/02/09-2015/02/14 | ||
//・論理行単位で字上げする。非選択時/単行選択時でも字上げする。 | //・論理行単位で字上げする。非選択時/単行選択時でも字上げする。 | ||
48行目: | 54行目: | ||
with (Document.Selection) { | with (Document.Selection) { | ||
//特殊文字をエスケープ | |||
var ty = GetTopPointY( | $indent = new RegExp("^"+$indent.replace(/([$()*+.?[\\\]^{|}])/g,"\\$1"),"gm"); | ||
var by = GetBottomPointY( | |||
var bx = GetBottomPointX( | var ty = GetTopPointY(mePosLogical); | ||
if ( | var by = GetBottomPointY(mePosLogical); | ||
SetActivePoint( | var bx = GetBottomPointX(mePosLogical); | ||
SetAnchorPoint( | var br =(Text.match(/\n/g)||[]).length; | ||
Text = Text.replace( | if (bx==1 && by-ty==br && br) by--; //次行行頭を含めないよう対策 | ||
SetActivePoint( | SetActivePoint(mePosLogical, 1, by+1); | ||
SetAnchorPoint( | SetAnchorPoint(mePosLogical, 1, ty); | ||
Text = Text.replace($indent,""); //行頭のインデントを削除 | |||
SetActivePoint(mePosLogical, 1, by+1); | |||
SetAnchorPoint(mePosLogical, 1, ty); | |||
} | } | ||
</source> | </source> |
2015年2月14日 (土) 09:11時点における版
論理行単位で字下げ・字上げします。
インデントには任意の文字列を設定できます。※初期設定は半角空白2個です。
更新履歴
- 2015/02/14
- (字上げ) 「インデントの定義」に正規表現の特殊文字があると誤動作する不具合を修正。
- 矩形選択(始点or終点が左下かつ論理行頭)時、下端の行が範囲から漏れる不具合を修正。
- 2014/02/09
- 初版公開。
字下げ (インデント)
- 複数行選択時 (選択範囲が2行以上) は、字下げします。
単一行選択時 (選択範囲が1行以内) または非選択時は、タブ文字を挿入します。
※選択範囲の行数は、ステータスバーの「xx文字 (xx行) 選択」の部分で判断してください。 - 空行 (改行のみの行) は字下げされません。
- 「Tab」キーなどに割り当ててご利用ください。
//■字下げ(インデント)
// 2014/02/09-2015/02/14
//・論理行単位で字下げする。空行は字下げしない。非選択時/単行選択時はタブ挿入。
//■インデントの定義 ●初期値=" " (半角空白2個)
var $indent = " ";
with (Document.Selection) {
//非選択時/単行選択時はタブ挿入して終了
if (GetTopPointY(mePosView)==GetBottomPointY(mePosView)) {Text="\t"; Quit();}
var ty = GetTopPointY(mePosLogical);
var by = GetBottomPointY(mePosLogical);
var bx = GetBottomPointX(mePosLogical);
var br =(Text.match(/\n/g)||[]).length;
if (bx==1 && by-ty==br && br) by--; //次行行頭を含めないよう対策
SetActivePoint(mePosLogical, 1, by+1);
SetAnchorPoint(mePosLogical, 1, ty);
Text = Text.replace(/^(?!$)/gm,$indent); //(空行を除く)行頭にインデントを付加
SetActivePoint(mePosLogical, 1, by+1);
SetAnchorPoint(mePosLogical, 1, ty);
}
字上げ (アンインデント)
- 単一行選択時 (選択範囲が1行以内) または非選択時でも、字上げします。
- 「Shift + Tab」キーなどに割り当ててご利用ください。
//■字上げ(アンインデント)
// 2014/02/09-2015/02/14
//・論理行単位で字上げする。非選択時/単行選択時でも字上げする。
//■インデントの定義 ●初期値=" " (半角空白2個)
var $indent = " ";
with (Document.Selection) {
//特殊文字をエスケープ
$indent = new RegExp("^"+$indent.replace(/([$()*+.?[\\\]^{|}])/g,"\\$1"),"gm");
var ty = GetTopPointY(mePosLogical);
var by = GetBottomPointY(mePosLogical);
var bx = GetBottomPointX(mePosLogical);
var br =(Text.match(/\n/g)||[]).length;
if (bx==1 && by-ty==br && br) by--; //次行行頭を含めないよう対策
SetActivePoint(mePosLogical, 1, by+1);
SetAnchorPoint(mePosLogical, 1, ty);
Text = Text.replace($indent,""); //行頭のインデントを削除
SetActivePoint(mePosLogical, 1, by+1);
SetAnchorPoint(mePosLogical, 1, ty);
}
スポンサーリンク