On Apr 26, 7:57 pm, "Edward K. Ream" <[EMAIL PROTECTED]> wrote:
> To handle this, Leo will need code such as:
>
> def insertAsNthChild(self,parent):
> p = self
> p._unlink()
> parent = p._adjustPositionAfterUnlink(parent)
> p._linkAsNthChild(parent)
A nice simplification was possible. We adjust the position *before*
unlinking. Here is some actual code:
def moveToNthChildOf (self,parent,n):
"""Move a position to the nth child of parent."""
p = self # Do NOT copy the position!
parent._adjustPositionBeforeUnlink(p)
p._unlink()
p._linkAsNthChild(parent,n)
return p
Using p._adjustPositionBeforeUnlink removes a constraint from
p_unlink, and allows p._adjustPositionBeforeUnlink to be defined very
simply as follows:
def _adjustPositionBeforeUnlink (self,p2):
'''Adjust position p before unlinking p2.'''
p = self ; sib = p.copy()
while sib.hasBack():
sib.moveToBack()
if sib == p2:
p._childIndex -= 1
break
This is so much clearer than comparing stacks, but its effect is
precisely the same.
This new code was pushed to the sax-graph branch earlier.
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
-~----------~----~----~----~------~----~------~--~---