#7577
crowdy
Member

try this


// save current position
var g_curX = document.selection.GetActivePointX(eePosLogical);
var g_curY = document.selection.GetActivePointY(eePosLogical);

function newLine() {
// make new line
document.selection.EndOfLine(false,eeLineView);
document.selection.NewLine(1);
}

function main() {
var line;
if (document.selection.IsEmpty) {
// get current single line
document.selection.StartOfLine(false, eeLineLogical);
document.selection.EndOfLine(true, eeLineLogical);
line = document.selection.Text;
} else {
line = document.selection.Text;
}

if (line.indexOf('#')>0) {
var strNum = prompt("how many times do you want to repeat?", "10");
repeatnum = parseInt(strNum);

// is it numeric?
if (!isNaN(repeatnum)) {

newLine();

// do repeat
for (var i=1; i<=repeatnum; i++) {
document.writeln(line.replace(/#/g, i));
}
}
}

document.selection.Collapse();
document.selection.SetActivePoint(eePosLogical, g_curX, g_curY);
}

main();