home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Smartkeys / hilightDelimiter.script < prev   
Encoding:
Text File  |  2001-06-19  |  1.7 KB  |  65 lines

  1. !!Script
  2.  
  3. /**
  4. @Tool: hilightDelimiter~selects the matching opening delimiter. 
  5. Defined for all file types. To activate type a closing delimiter
  6. or place the caret after a closing delimiter and type a tab.
  7. @EndTool: 
  8. @Summary: hilightDelimiter~hilight matching opening delimitor 
  9. */
  10.  
  11. function DoCommand()
  12. {
  13.     var path = File.getToolsPath() + "\\Smartkeys\\hilightDelimiter.script";
  14.     Application.registerSmartKeyHandler("*", "}\t", path, 
  15.         "Hilight: }<tab> with hilight of matching delimiter");
  16.     Application.registerSmartKeyHandler("*", "]\t", path, 
  17.         "Hilight: ]<tab> with hilight of matching delimiter");
  18.     Application.registerSmartKeyHandler("*", ")\t", path, 
  19.         "Hilight: )<tab> with hilight of matching delimiter");
  20. }
  21.  
  22. function OnEvent(editor,lineBuffer)
  23. {
  24.     var range = editor.getSelection();
  25.     var origIndex=range.startLineIndex;
  26.     
  27.     range.startCharIndex -= 1;
  28.     
  29.     var delimiterRange = editor.findMatchingDelimiter(range);
  30.     if (delimiterRange) 
  31.     {          
  32.         editor.select(delimiterRange);   
  33.         
  34.         // Scroll if needed
  35.         var lineIndex = -1;
  36.         if (!editor.lineVisible(delimiterRange.startLineIndex))
  37.         {
  38.             lineIndex = editor.getScrollPosition();
  39.             editor.scrollTo(delimiterRange.startLineIndex - 5);
  40.             wait(500, true);   
  41.         }
  42.         else
  43.         {
  44.             wait(100, true);
  45.         }
  46.         
  47.         // we scroll first, and the re-position cursor, otherwise
  48.         // the cursor will be out of place
  49.         if (lineIndex > -1)
  50.         {
  51.             // scroll back
  52.             editor.scrollTo(lineIndex);
  53.         }        
  54.         // so that we are not highlighting the original close brace
  55.         range.startCharIndex += 1;
  56.         // essentially unhighlight here
  57.         editor.select(range);
  58.     }
  59.     return true; // Ignore the tab
  60. }
  61.  
  62.  
  63. !!/Script
  64.  
  65.