Rev dae5c2f fixed a subtle bug in cff command.  

The heart of the original code was:

for p in clones:
    p2 = p.clone()
    p2.moveToLastChildOf(found)

where the 'found' node is the top-level node created by the cff command. In 
certain cases, when p is already a clone, the call to:

p2.moveToLastChildOf(found)

improperly adjusted the position of *found*, with the result that 
c.positionExists(found) returns False. Nothing too serious happens, but Leo 
selects the root position instead of found.  Annoying.

This is likely a bug in a low-level position method called by 
p.moveToLastChildOf.  It may not be easy to fix.

Happily, there is a safe and elegant solution. Indeed, p.clone is defined 
as follows:

def clone(self):
    p = self
    p2 = p.copy()
    p2._linkAfter(p) 
    return p2

Do you see what's coming?  Instead of linking the clone after the original 
node, and then laboriously (and maybe incorrectly) moving the node again, 
we can create the clone *in the desired place* as follows:

for p in clones:
    # Create the clone directly as a child of found.
    p2 = p.copy()
    n = found.numberOfChildren()
    p2._linkAsNthChild(found, n, adjust=False)

This is a beautiful pattern.  The basis of p.clone() is simply p.copy()! 

The new code uses the low-level _linkAsNthChild method to create the clone 
in the desired place without moving it. The adjust=False argument 
suppresses the adjustment that caused the problem.

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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to