The three scripting commands:
Code: Select all
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.perlReOn();
are member functions of object
UltraEdit in UltraEdit for Windows which means those three commands define insert mode on, column mode off and usage of Perl regular expression engine for entire instance of UltraEdit/UEStudio independent on which file is active. When you click with mouse on
Column - Column Mode, the column mode is enabled for all files and not just for the currently active file. The same is true for insert or overstrike mode toggled with key Ins (on English keyboard). Therefore there is no need to call these member functions of UltraEdit object several times.
I'm not sure what you want to achieve with the green formatted code lines. After copying content of active file into a new file (for whatever reason) and running there the replaces which nearly delete everything (for whatever reason), the caret is moved in this new file now containing nearly nothing anymore to bottom of file and run a Perl regular expression search upwards to find a start tag. This tag is copied to clipboard 9 and then the new file is closed.
You expect the previous file becomes now active again, but this is not guaranteed in scripting environment. It depends on version of UE/UES and configuration setting
After current tab is closed, move to.
Therefore it is better to determine document index number of active file before opening the new file and work with document array after closing the new file.
Script code (not tested):
Code: Select all
function getActiveDocumentIndex()
{
// There is an active document index property since UE v16.00 / UES v10.00.
if (typeof(UltraEdit.activeDocumentIdx) == "number")
{
return UltraEdit.activeDocumentIdx;
}
// Workaround solution for UE < v16.00 and UES < v10.00.
for (var i = 0; i < UltraEdit.document.length; i++)
{
if (UltraEdit.activeDocument.path == UltraEdit.document[i].path)
{
return i;
}
}
return (-1);
}
if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.perlReOn();
var nActiveDocIndex = getActiveDocumentIndex();
UltraEdit.activeDocument.selectToTop();
UltraEdit.selectClipboard(9);
UltraEdit.activeDocument.copy();
UltraEdit.newFile();
UltraEdit.activeDocument.paste();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
while(UltraEdit.activeDocument.findReplace.replace("(<([a-z][\\w-]*)(?: [^>]+?)? />|<([a-z][\\w-]*)(?: [^>]+?)?/>|<!--|-->)", ""));
while(UltraEdit.activeDocument.findReplace.replace("<([a-z][\\w-]*)(?: [^>]+?)?>[^<]*?</\\1>", ""));
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.findReplace.searchDown=false;
UltraEdit.activeDocument.findReplace.find("(?<=<)([a-z][\\w-]*)");
UltraEdit.activeDocument.copy();
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
UltraEdit.selectClipboard(8);
UltraEdit.document[nActiveDocIndex].cut();
UltraEdit.document[nActiveDocIndex].paste();
UltraEdit.document[nActiveDocIndex].write("</");
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(9);
UltraEdit.document[nActiveDocIndex].paste();
UltraEdit.document[nActiveDocIndex].write(">");
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}