home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Misc / swapCharacters.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  1.1 KB  |  37 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: swapCharacters~swaps the beginning and ending characters in a selection. 
  6. @EndTool: 
  7. @Summary: swapCharacters~swaps the beginning and ending characters  
  8. */
  9.  
  10. function DoCommand()
  11. {
  12.   var editor = getActiveEditor();
  13.   if (editor)
  14.   {
  15.     var selection = editor.getSelection();
  16.     
  17.     // Get the beginning and ending characters
  18.     var beginChar = editor.copy(selection.startLineIndex, selection.startCharIndex, 
  19.       selection.startLineIndex, selection.startCharIndex + 1);
  20.     var endChar = editor.copy(selection.endLineIndex, selection.endCharIndex - 1, 
  21.       selection.endLineIndex, selection.endCharIndex);
  22.       
  23.     if (beginChar && endChar)
  24.     {
  25.       // Swap
  26.       editor.replace(beginChar, selection.endLineIndex, selection.endCharIndex - 1, 
  27.         selection.endLineIndex, selection.endCharIndex);
  28.       editor.replace(endChar, selection.startLineIndex, selection.startCharIndex, 
  29.         selection.startLineIndex, selection.startCharIndex + 1);
  30.     }
  31.       
  32.     editor.setActive("Swap Characters");
  33.   }
  34. }
  35.  
  36. !!/Script
  37.