Outline modifications that do not invalidate positions are:

   1.  appending nodes at the end of children with for example:
   p1 = p.insertAsLastChild()
   # now p is still valid
   
   2. deleting the last child

But for your use case I would probably use v nodes directly.

import time
def cloneToSiblingTodayNode(p):
    """
    Clone the node identified by p and move that clone to a child of a
    sibling "@day %Y-%m-%d" node. If the @day node doesn't exist yet,
    create it. If p already has a clone as a child of @day, then do nothing.
    
    The position pointing at the original node is returned as output
    (warning:  actually the first child of the parent of p is returned...the
     assumption is that will be the same node as pointed to by the original 
p).
    """
    today = "@day " +  time.strftime("%Y-%m-%d", time.gmtime())
    day = next(iter(c.find_h(today)), None)
    if not day:
        day = p.parent().insertAsLastChild()
        day.h = today
    vday = day.v
    if p.v not in vday.children:
        vday.children.insert(0, p.v)
        p.v.parents.append(vday)
    # position p should be valid as is
    p

After making outline changes using vnodes at the end you should call 
c.redraw()




-- 
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/5900a3d4-ad7a-4b0c-b8f0-491d85a63db4%40googlegroups.com.

Reply via email to