Skip to content

Instantly share code, notes, and snippets.

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):
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
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment