SHARE
TWEET

Untitled

a guest Apr 28th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Non-matching words
  2. var excludeWords = ["a","an","and","for","or","as","at", "of"];
  3.  
  4. /*
  5. Choose between:
  6. eeCaseLowerCase
  7. eeCaseUpperCase
  8. eeCaseCapitalize
  9. */
  10. var convertTo = eeCaseCapitalize;
  11.  
  12. function coords() {
  13.     return {
  14.     x: document.selection.GetActivePointX(eePosLogical),
  15.     y: document.selection.GetActivePointY(eePosLogical)
  16.     };
  17. }
  18. function contains(arr,str) {
  19.     for (var i = 0; i < arr.length; i++) {
  20.         if (arr[i] == str)
  21.             return true;
  22.     }
  23.     return false;
  24. }
  25. var matchNonwhitespace = new RegExp("\\S");
  26.  
  27. var left = {
  28.     x: document.selection.GetTopPointX(eePosLogical),
  29.     y: document.selection.GetTopPointY(eePosLogical)
  30. };
  31. var selected = {
  32.     x: document.selection.GetBottomPointX(eePosLogical),
  33.     y: document.selection.GetBottomPointY(eePosLogical)
  34. };
  35.  
  36. if (left.x > 1) {
  37.     document.selection.SetActivePoint(eePosLogical, left.x, left.y);
  38.     document.selection.SetActivePoint(eePosLogical, left.x-1, left.y, true);
  39.     if (document.selection.Text != " ") {
  40.         document.selection.WordRight();
  41.         left = coords();
  42.     }
  43. }
  44.  
  45. while (left.y < selected.y || left.x < selected.x) {
  46.     document.selection.SetActivePoint(eePosLogical, left.x, left.y);
  47.  
  48.     document.selection.WordRight(true);
  49.     var right = coords();
  50.  
  51.     if (matchNonwhitespace.test(document.selection.Text)) {
  52.         if (document.selection.Text.slice(-1) == " ") {
  53.             right = coords();
  54.             document.selection.SetActivePoint(eePosLogical, left.x,left.y);
  55.             document.selection.SetActivePoint(eePosLogical, right.x-1,right.y,true);
  56.         }
  57.        
  58.         if (!contains(excludeWords, document.selection.Text))
  59.             document.selection.ChangeCase( convertTo );
  60.     }
  61.  
  62.     left = right;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top