On Mar 16, 10:08 am, "Edward K. Ream" <[email protected]> wrote:
> > Oh, wait, no, I still have the same problem.
> > (I declared it working after I hit the script button and it worked --
> > forgetting that I was actually testing the undo part :)
>
> I'll look at this asap and report what I find.
The following script probably does something akin to what you want::
u = c.undoer ; current = c.p
undoType = "Break up long headline"
u.beforeChangeGroup(current,undoType)
n = 0
for p in c.allNodes_iter():
split = p.h.split(" ", 1)
if len(split) > 1:
b = u.beforeChangeNodeContents(p)
before,after = split
p.setHeadString(before)
print(p.h)
u.afterChangeNodeContents(p,undoType,b)
while after:
n += 1
split = after.split(" ", 1)
if len(split) > 1: h,after = split
else: h,after = after,None
b = u.beforeInsertNode(p)
child = p.insertAsLastChild()
child.setHeadString(h)
u.afterInsertNode(child,undoType,b)
u.afterChangeGroup(current,undoType,reportFlag=True)
print('%s nodes changed' % n)
c.redraw()
This was tricky, and took me awhile. As you can see, there are three
pairs of before/after undoer calls. It's important to get them
properly nested, and to do the proper kind of undo. The other
significant change was the use of current rather than c.p. Current
doesn't change, but c.p can and probably will change.
Undo now appears to work correctly.
HTH.
Edward
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---