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/CAMF8tS3sABQFoKDss2JqdhqrdwyS3fJnzXe03sb%2BBZH-O52mZA%40mail.gmail.com.

Reply via email to