Don't forget to set up for undo. On Friday, November 4, 2022 at 6:48:50 AM UTC-4 Edward K. Ream wrote:
> On Fri, Nov 4, 2022 at 3:25 AM Luka <[email protected]> wrote: > > There are plenty of ways to do it in LEO but this is how I do it. >> >> Create a @button node with script, select text in body, and run: >> >> @language python >> >> #get selected text from body >> w = c.frame.body.wrapper >> s = w.getSelectedText() >> start,end=w.getSelectionRange() >> b=p.b >> >> #do something >> s=s.replace('\n','\\\\\n') >> >> #insert edited text back >> p.b=b[:start]+s+b[end:] >> c.redraw() >> > > Thanks, Luka, for this tip. > > Leo itself typically expands the selection to include entire lines. Like > this (tested) code: > > w = c.frame.body.wrapper > s = w.getAllText() > i, j = w.getSelectionRange() > start, junk = g.getLine(s, i) > junk, end = g.getLine(s, j) > > Edward > -- 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/d2f7c53d-0f68-4562-b9d5-29c2f6129ddfn%40googlegroups.com.
