No need to apologize! Leo can do so many things that it's hard to find
information, or even know there is something to look for. I looked in
LeoDocs.leo (you can open it from the Help menu). Search for _Undoably
changing body text_ (I originally just searched for _undo_). It says
To undo a single change to body text::
command = 'my-command-name'
b = c.undoer.beforeChangeNodeContents(p, oldYScroll=ypos)
# Change p's body text.
c.undoer.afterChangeNodeContents(p,
command=command, bunch=b, dirtyVnodeList=[])
Someone else can correct me, but I don't think that the exact value of the
string *command* matters. Your script will probably have a command name,
though, so might as well use it.
On Friday, November 4, 2022 at 8:17:01 AM UTC-4 Israel Hands wrote:
> Many thanks for such prompt and helpful advice. A significant part of what
> makes Leo so great. I'm off to try Luka's and Edward's solutions. Sorry to
> be so slow tbp1, but how do I set up undo?
>
> Thanks again from momentarily sunny Wales.
>
> IH
>
> On Friday, 4 November 2022 at 12:01:10 UTC [email protected] wrote:
>
>> 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/92f3c9ea-ad0b-4e23-bfdd-ba98a7fb212bn%40googlegroups.com.