This script will check to see if the selected block is already commented (select the delimiters too), if so it will uncomment the block, otherwise it will comment it. Currently, it only checks for HTML and XML files to apply the <!----> block comments, every other type of file gets /**/. I use the file extension to determine the comment type, so it won't work on embedded scripts or styles in an HTML doc or on unsaved documents. If I can figure out how to determine the current highlighter, I will change it.
This is my first RJ TextEd script, so comments are appreciated.
Code: Select all
var selectedText = Document.SelText;
var firstTwoSelChars = Copy(selectedText, 1, 2);
var selectionLength = Length(selectedText);
if (firstTwoSelChars == "/*") {
Document.SelText = Copy(selectedText, 3, (selectionLength - 4));
} else if (firstTwoSelChars == "<!") {
Document.SelText = Copy(selectedText, 5, (selectionLength - 7));
} else {
var fileName = Document.FileName;
var dotPos = -1;
var i = Length(fileName);
while ((dotPos == -1) && (i > 0)) {
if (fileName[i] == ".") {
dotPos = i;
} else {
i--;
}
}
var fileExtension = Copy(fileName, dotPos + 1, Length(fileName));
if ((fileExtension == "html") || (fileExtension == "xml")) {
Document.SelText = "<!--" + Document.SelText + "-->";
} else {
Document.SelText = "/*" + Document.SelText + "*/";
}
}