Thanks, Thomas, I like these little scripts :-) It can study the api bit by bit, like, I didn't use undoer before
On Sunday, February 4, 2024 at 4:50:15 AM UTC+8 [email protected] wrote: > Converting to Title Case means to make the first letter of every word in a > string capitalized, and all the other letters made lowercase. It can be > handy if you copy an all-capital string from somewhere else but you don't > like all-caps and want to convert it to title case. I couldn't find a > built-in Leo command to do this. > > Maybe it's there somewhere, but here's a little script to do the job. It > uses the title() method of strings. You can put it into myLeoSettings.leo > as a command, button, or menu item. > > """Convert selection or body to title case.""" > w = c.frame.body.wrapper > p = c.p > s = p.b > u = c.undoer > > start, end = w.getSelectionRange() > use_entire = start == end # no selection, convert entire body > > undoType = 'title-case-body-selection' > undoData = u.beforeChangeNodeContents(p) > > if use_entire: > p.b = s.title() > else: > sel = s[start:end] > head, tail = s[:start], s[end:] > p.b = head + sel.title() + tail > > c.setChanged() > p.setDirty() > u.afterChangeNodeContents(p, undoType, undoData) > c.redraw() > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/7cc49cf0-27d7-481b-8d6a-1ff209aea697n%40googlegroups.com.
