UltraEdit沒有內置的命令將選定的行與行號複製到剪貼板。
但是,在將塊粘貼到電子郵件應用程序之前,可以運行UltraEdit腳本來將行號添加到複製到剪貼板之前的文本中。
// Get content of clipboard as an array of lines assuming that the
// clipboard contains text data and the lines have carriage return
// plus line-feed as line termination.
if (UltraEdit.clipboardContent.length)
{
var asLines = UltraEdit.clipboardContent.split("\r\n");
// Remove the last string from array if being empty because
// the text in clipboard ends with a line termination.
if (!asLines[asLines.length-1].length) asLines.pop();
// Convert the number of lines to a string using decimal
// system and replace each digit in string by character 0.
var sLeadingZeros = asLines.length.toString(10).replace(/./g,'0');
// Insert at beginning of each line a number with
// leading zeros according to maximum number of lines.
for (var nLine = 0; nLine < asLines.length; nLine++)
{
var sLineNumber = (nLine+1).toString(10);
sLineNumber = sLeadingZeros.substr(sLineNumber.length) + sLineNumber;
if (asLines[nLine].length)
{
asLines[nLine] = sLineNumber + " " + asLines[nLine];
}
else // For an empty line just add the line number without spaces.
{
asLines[nLine] = sLineNumber;
}
}
// Append an empty string to array of lines to have finally the
// block in clipboard terminated with carriage return and line-feed.
asLines.push("");
// Join the modified lines back to a block in clipboard.
UltraEdit.clipboardContent = asLines.join("\r\n");
}
複製&將此腳本代碼粘貼到一個新的ANSI文件並將其保存例如與文件名Add Line Numbers.js
。然後將此腳本添加到腳本列表沒有熱鍵用於在將塊複製到剪貼板或使用快捷鍵或和絃(多鍵分配)將鍵快速執行後從腳本列表執行。
腳本本身也可以製作所選文本的副本。
當在活動文件中選定的文本上執行此腳本的稍微修改版本而不是剪貼板內容時,也可以在活動文件中使用實際行號。