1 #title = "/*"
  2 #tooltip = "複数行コメント挟み込み"
  3 #include "lib\sgc4jsee.jsee"
  4 
  5 /**
  6  * @fileOverview
  7  * 選択範囲が単一行であれば、文字列を挟み込みます。<br />
  8  * 選択範囲が複数行であれば、行全体を挟み込みます。
  9  * 
 10  * @author gecca from 雪月花 (http://setsugecca.org/)
 11  * @version 1.00 for EmEditor v10.0
 12  */
 13 
 14 (function() {
 15 	var redraw = Redraw;
 16 	Redraw = false;
 17 	
 18 	if(!document.Config.Highlight.CommentBegin || !document.Config.Highlight.CommentEnd) {
 19 		alert("コメントの開始と終了が設定されていません。");
 20 		return;
 21 	}
 22 	
 23 	var topX = document.selection.GetTopPointX(eePosLogical);
 24 	var topY = document.selection.GetTopPointY(eePosLogical);
 25 	var bottomX = document.selection.GetBottomPointX(eePosLogical);
 26 	var bottomY = document.selection.GetBottomPointY(eePosLogical);
 27 	
 28 	// 選択範囲が単一行であれば、文字列を挟み込む
 29 	if(document.selection.Text && topY == bottomY) {
 30 		document.selection.Text = document.Config.Highlight.CommentBegin + document.selection.Text + document.Config.Highlight.CommentEnd;
 31 	
 32 	// 選択範囲が複数行であれば、行全体を挟み込む
 33 	} else {
 34 		var br = JseeUtil.getBr();
 35 		
 36 		JseeUtil.selectLines();
 37 		
 38 		var isLastLineSelected = (document.selection.GetBottomPointX(eePosLogical) != 1);
 39 		
 40 		// コメントで挟み込む
 41 		document.selection.Text = document.Config.Highlight.CommentBegin + br
 42 			+ document.selection.Text + (isLastLineSelected ? br : "") + document.Config.Highlight.CommentEnd + br;
 43 		
 44 		// 選択範囲を復元
 45 		Redraw = redraw;
 46 		document.selection.SetActivePoint(eePosLogical, topX, topY + 1);
 47 		document.selection.SetAnchorPoint(eePosLogical, bottomX, bottomY + 1);
 48 	}
 49 })();
 50