選択範囲を維持したまま選択範囲の末尾に文字列(改行)を追加する方法

投稿者: ent2 声2 投稿

マクロで選択範囲を維持したまま選択範囲の末尾に文字列(改行)を追加する方法、 もしくは、選択範囲の末尾に改行が含まれているときにその改行の分を選択範囲から除外する(選択範囲を狭める)ことができないでしょうか。
ent 様 いつもお世話になっております。江村です。 マクロを作成しましたので、お試しください。

x1 = document.selection.GetTopPointX( eePosLogical );
y1 = document.selection.GetTopPointY( eePosLogical );
x2 = document.selection.GetBottomPointX( eePosLogical );
y2 = document.selection.GetBottomPointY( eePosLogical );
s = document.selection.Text;
n = s.charCodeAt( s.length - 1 );
if( n == 13 || n == 10 ) {   // CR or LF, remove the last character
	s = s.substr( 0, s.length - 1 );
	if( n == 10 && s.charCodeAt( s.length - 1 ) == 13 ) {   // if n was LF, check for CR
		s = s.substr( 0, s.length - 1 );
	}
	y2--;
	x2 = document.GetLine( y1 ).length + 1;
}
else {  // add CR+LF
	s = s + "\r\n";
	y2++;
	x2 = 1;
}
document.selection.Text = s;
document.selection.SetAnchorPoint( eePosLogical, x1, y1 );
document.selection.SetActivePoint( eePosLogical, x2, y2, true );
よろしくお願いします。

このトピックの投稿: 2