[script] Switch case

Ask questions about how to create a script or swap scripts with other users.
Post Reply
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

[script] Switch case

Post by pjj »

I thought about asking for this feature, but then I said to myself: Hey, why not make a script? And so I've done one:

Code: Select all

/*
  switches circularly between lower case-UPPER CASE-Name Case (like in MS Word)
*/

var s = Document.SelText;
if (s != "") {
  var ss = Document.SelStart;
  var sl = Document.SelLength;

  if (s == Lowercase(s)) {
    Document.InsertText(Uppercase(s));
  } else if (s == Uppercase(s)) {
    Document.InsertText(Namecase(s));
  } else {
    Document.InsertText(Lowercase(s));
  }
  if (Document.IsColumnModeActive() != true) {
    Document.SelStart = ss;
    Document.SelLength = sl;
  }
} else {
  ShowMessage("Select some text first!");
}
It acts exactly like in MS Word: it switches case of a selection in a circular way: lower case --> UPPER CASE --> Name Case, and it (obviously) preserves selection -- but not in Column Mode. It works with word wrap on, too.

Rickard,
would it be possible that SelLength work on Column Mode, too? I mean that it would bring back selection as it was before deselecting. Otherwise I think one would have to use SetSelection(), but how to get all four coordinates? Perhaps you could add a new function GetSelection(), that would return, umm, an array with the four coordinates?
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Post Reply