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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/36d3b601-43a5-4c97-9b5e-994753dd33edn%40googlegroups.com.

Reply via email to