Last active
April 7, 2023 09:39
-
-
Save MakotoE/d74d75ade47f57c1c9396488bada8347 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Words to exclude | |
var excludeWords = ['a', 'an', 'and', 'for', 'or', 'as', 'at', 'of']; | |
/* | |
Choose between: | |
eeCaseLowerCase | |
eeCaseUpperCase | |
eeCaseCapitalize | |
*/ | |
var convertTo = eeCaseCapitalize; | |
function coords() { | |
return { | |
x: document.selection.GetActivePointX(eePosLogical), | |
y: document.selection.GetActivePointY(eePosLogical), | |
}; | |
} | |
function includes(arr, find) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] === find) { | |
return true; | |
} | |
} | |
return false; | |
} | |
var matchNonwhitespace = new RegExp('\\S'); | |
var left = { | |
x: document.selection.GetTopPointX(eePosLogical), | |
y: document.selection.GetTopPointY(eePosLogical), | |
}; | |
var selected = { | |
x: document.selection.GetBottomPointX(eePosLogical), | |
y: document.selection.GetBottomPointY(eePosLogical), | |
}; | |
if (left.x > 1) { | |
document.selection.SetActivePoint(eePosLogical, left.x, left.y); | |
document.selection.SetActivePoint(eePosLogical, left.x - 1, left.y, true); | |
if (document.selection.Text !== ' ') { | |
document.selection.WordRight(); | |
left = coords(); | |
} | |
} | |
while (left.y < selected.y || left.x < selected.x) { | |
document.selection.SetActivePoint(eePosLogical, left.x, left.y); | |
document.selection.WordRight(true); | |
var right = coords(); | |
if (includes(['’', '\''], document.selection.Text)) { // Skip apostrophe | |
document.selection.WordRight(true); | |
right = coords(); | |
} else if (matchNonwhitespace.test(document.selection.Text)) { | |
if (document.selection.Text.slice(-1) === ' ') { | |
right = coords(); | |
document.selection.SetActivePoint(eePosLogical, left.x, left.y); | |
document.selection.SetActivePoint(eePosLogical, right.x - 1, right.y, true); | |
} | |
if (!includes(excludeWords, document.selection.Text)) { | |
document.selection.ChangeCase( convertTo ); | |
} | |
} | |
left = right; | |
} | |
document.selection.CharRight(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That worked very well. That you very much for this.