Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UI powered text manipulation
# perform actions on a selected block of text
import editor
import ui
sel = editor.get_selection()
text = editor.get_text()
if sel[0]-sel[1]:
text = text[sel[0]:sel[1]]
def indent(sender):
txt=sender.superview['textPreview'].text
lines = txt.splitlines()
txt = '\t'+'\n\t'.join(lines)
sender.superview['textPreview'].text = txt
def reload(sender):
sender.superview['textPreview'].text = text
def save(sender):
newtext = sender.superview['textPreview'].text
editor.replace_text(sel[0],sel[1],newtext)
v = ui.load_view('textmanipui')
v['textPreview'].text = text
v['buttonInd'].action = indent
v['buttonReload'].action = reload
sv = ui.ButtonItem()
sv.title = 'Save'
sv.action = save
v.right_button_items = [sv]
v.present('sheet')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.