On Friday, July 5, 2013 6:07:04 PM UTC-5, Edward K. Ream wrote:
 

> Happily, there is a simple strategy that sidesteps all the difficulties:
>
> Step 1.  Verify, *before* making any changes to the outline, that all the 
> positions passed to p.deletePositionsInList *initially* make sense.
>
> Step 2. Treat each position as a "request" to delete *some* vnode from the 
> children array in the *position's* parent vnode.
>

And here is the corresponding code, with traces and asserts removed:

    def deletePositionsInList (self,aList,callback=None):
    
        c = self

        # Verify all positions *before* altering the tree.
        aList2 = [p for p in aList if c.positionExists(p)]

        # Delete p.v, **if possible** for all positions p in aList2.
        if callback:
            for p in aList2:
                callback(p)
        else:
            for p in aList2:
                v = p.v
                parent_v = p.stack[-1][0] if p.stack else c.hiddenRootNode
                if v in parent_v.children:
                    childIndex = parent_v.children.index(v)
                    v._cutLink(childIndex,parent_v)

A slight complication: the code must call the low-level v._cutLink method 
to properly remove v from parent_v.children.

This code passes the unit test that revealed the fatal problems with all 
previous versions.

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 http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to