UltraEdit v25.20.0.88 has no command to collapse/expand folds of a specific folding level. But what you want can be achieved with a script or macro.
Script solution:
Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
// Bookmark current line in active file.
UltraEdit.activeDocument.toggleBookmark();
// Move caret to top of the active file.
UltraEdit.activeDocument.top();
// Define the parameters for the case-sensitive Perl regular expression
// Find used below to find beginning of a function block at second level.
UltraEdit.perlReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
{
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
/* Search in a loop for lines
+ starting with two horizontal tabs or 8 normal spaces
+ and next having
- character { or
- the word function, one or more characters and finally { or
- a word character, one or more characters left to word
function, one or more characters and finally {.
Execute on each found line matching the search criteria the command
to toggle visibility, i.e. collapse or expand the function block.
*/
while(UltraEdit.activeDocument.findReplace.find("^(?:\\t{2}| {8})(?:(?:function\\b|\\w.+\\bfunction\\b).+)?{"))
{
UltraEdit.activeDocument.hideOrShowLines();
}
// Move caret back to bookmarked line. If this line is inside a collapsed
// function block, the entire function block is expanded by UltraEdit.
UltraEdit.activeDocument.gotoBookmark(-1);
UltraEdit.activeDocument.toggleBookmark();
}
Please read the comments and adapt
(?:\\t{2}| {8}) on using not two horizontal tabs or 2x4 spaces to indent the functions to fold/unfold. There is no scripting command to explicitly fold a block and also no command to explicitly unfold a block. There is also no property with information if current line is first line of a currently folded block. So the script toggles the folding of all function blocks on indentation level 2 on execution.
Macro solution:
Code: Select all
InsertMode
ColumnModeOff
ToggleBookmark
Top
PerlReOn
Loop 0
Find MatchCase RegExp "^(?:\t{2}| {8})(?:(?:function\b|\w.+\bfunction\b).+)?{"
IfFound
HideShowSelection
Else
ExitLoop
EndIf
EndLoop
GotoBookMark -1
ToggleBookmark
The macro does exactly the same as the script.
Further I recommend opening the
Function List which shows not only a list of functions in active file (or all files of a project), but marks always also the function on which code the caret is current positioned.
PS: I tested the script and macro with my own test file created quickly from
FileNameFunctions.js because I did not want to copy out the code from your screenshot. So I just can hope the script/macro works also for your JavaScript files.