home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Script by Will Hains
-
- // Wrap selection with { ... } - also works for an insertion caret
-
- var editor = getActiveEditor();
- if (editor)
- {
- //Get current selection
- var selection = editor.getSelection();
-
- var startLine = selection.startLineIndex;
- var startChar = selection.startCharIndex;
- var endLine = selection.endLineIndex;
- var endChar = selection.endCharIndex;
-
- //Create string of tabs to selection indent level
- var indentLevel = editor.getIndentLevel(selection.startLineIndex);
- var tabString = "";
- for(var x = 0; x < indentLevel; x++) {
- tabString += "\t";
- }
-
- //Adjust indexes for fully selected lines
- if(startChar == 0 & endChar == 0) {
- startChar = indentLevel;
- endLine--;
- endChar = 32000;
- editor.select(
- startLine, startChar,
- endLine, endChar
- );
- selection = editor.getSelection();
- var startLine = selection.startLineIndex;
- var startChar = selection.startCharIndex;
- var endLine = selection.endLineIndex;
- var endChar = selection.endCharIndex;
- }
-
- //Insert after selection
- var afterSelection = "\n" + tabString + "*/";
- editor.insert(
- endLine, endChar,
- afterSelection
- );
-
- //Insert before selection
- var beforeSelection = "/**\n" + tabString;
- editor.insert(
- startLine, startChar,
- beforeSelection
- );
-
- //Adjust startLine & endLine to reflect change
- startLine++;
- endLine++;
-
- //Indent selection between braces
- for(var x = startLine; x <= endLine; x++) {
- editor.insert(x, 0, "*");
- }
-
- //Adjust startChar & endChar to reflect change
- startChar = indentLevel + 1;
- endChar++;
-
- //Re-select the original selection
- editor.select(
- startLine, startChar,
- endLine, endChar
- );
-
- editor.setActive();
-
- }
-
- !!/Script
-