Leo has commands to capitalize, upcase, and lowercase the body text or
selections of the body text. I could not find a command to convert to
title case (first letter of every word capitalized). So here is a script
to do so.
The script does not take into account any tricky edge cases - it just uses
the Python string.title() method. The command is undoable.
"""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/77c83fa1-e0f6-4cb1-af0a-c8f26c50439dn%40googlegroups.com.