1 #title = "↑"
  2 #tooltip = "行移動(↑)"
  3 #include "lib\sgc4jsee.jsee"
  4 
  5 /**
  6  * @fileOverview
  7  * 上方向へ行移動します。
  8  * <p>
  9  * Eclipseを参考にしました。
 10  * </p>
 11  * 
 12  * @author gecca from 雪月花 (http://setsugecca.org/)
 13  * @version 1.00 for EmEditor v10.0
 14  */
 15 
 16 (function() {
 17 	var logger = JseeUtil.getLogger(false, "行移動(↑).jsee");
 18 	
 19 	var redraw = Redraw;
 20 	Redraw = false;
 21 	
 22 	// 選択上部の位置を取得
 23 	var topY = document.selection.GetTopPointY(eePosLogical);
 24 	// 1行目を含む場合は何もしない
 25 	if(topY <= 1) {
 26 		logger.log("対象外");
 27 		return;
 28 	}
 29 	
 30 	// 書き換え対象を選択
 31 	JseeUtil.selectLines();
 32 	document.selection.SetAnchorPoint(eePosLogical, 1, topY - 1);
 33 	
 34 	// JseeUtil.selectLines();で確定した選択下部を取得
 35 	var newBottomY = document.selection.GetBottomPointY(eePosLogical);
 36 	
 37 	// 書き換え・選択位置を復元
 38 	if(document.selection.Text.match(/^(.*?)(\r\n|\r|\n)$/)) {
 39 		logger.log("最下行からの移動 (最下行が空行の場合)");
 40 		document.selection.Text = document.selection.Text.replace(/^(.*?)(\r\n|\r|\n)$/, "$2$1");
 41 		document.selection.SetActivePoint(eePosLogical, 1, topY - 1);
 42 		Redraw = redraw;
 43 		document.selection.SetActivePoint(eePosLogical, 1, newBottomY, true);
 44 	
 45 	} else if(!document.selection.Text.match(/.+$/)) {
 46 		logger.log("通常の移動");
 47 		document.selection.Text = document.selection.Text.replace(/^(.*(\r\n|\r|\n))((\s|.)*)$/, "$3$1");
 48 		document.selection.SetActivePoint(eePosLogical, 1, topY - 1);
 49 		Redraw = redraw;
 50 		document.selection.SetActivePoint(eePosLogical, 1, newBottomY - 1, true);
 51 	
 52 	} else {
 53 		logger.log("最下行からの移動");
 54 		document.selection.Text = document.selection.Text.replace(/^(.*?)(\r\n|\r|\n)((\s|.)*)$/, "$3$2$1");
 55 		document.selection.SetActivePoint(eePosLogical, 1, topY - 1);
 56 		Redraw = redraw;
 57 		document.selection.SetActivePoint(eePosLogical, 1, newBottomY, true);
 58 	}
 59 })();
 60