February 8, 2015 at 2:27 am #19829
Meir
Participant
Thank you Stefan!
OK, now my first ever JavaScript macro is complete (bug reports are welcomed) :
/*
This eeJavaScript macro will toggle a selected string through the
sequence of lower case -> capitalize -> uppercase -> lower case again.
If no string is selected, the word where the cursor is will.
The starting state is a function of the "first" and "next" characters.
* If both characters are upper, the string will be converted be lower.
* If only the first character is upper, the string will be converted
to upper.
* If neither the first character nor the next are upper case, the
string will be capitalyzed.
A single character will toggle just between lower and upper case.
*/
s = document.selection.Text;
if( document.selection.IsEmpty ){
document.selection.SelectWord();
s = document.selection.Text;
}
f = s.charCodeAt(0);
n = s.charCodeAt(1);
if( (f >= 0x41 && f <= 0x5a && s.length == 1)
||
(f >= 0x41 && f <= 0x5a && n >= 0x41 && n <= 0x5a)){
document.selection.ChangeCase(eeCaseLowerCase);
}
else if( f >= 0x41 && f <= 0x5a ){
document.selection.ChangeCase(eeCaseUpperCase);
}
else {
document.selection.ChangeCase(eeCaseCapitalize);
}
Regards,
Meir