On Mon, Sep 23, 2013 at 9:15 AM, Terry Brown <terry_n_br...@yahoo.com>wrote:

I've run in to this many times, the 'insertBefore' example was just the
> most recent.
>

Your complaint is understandable, but I am not likely to consider a fix
now, with 4.11b1 so near.


>
> It seems to me that the API for handling top-level nodes is
> inconveniently inconsistent with the API for handling non-top-level
> nodes.


Maybe, but the underlying vnode methods can't be change now: they are too
important and too fragile.



> What's the simplest way to make it work when invoked on a top level
> node?  For top level nodes, p.parent() == None.
>

Modulo undo and redrawing code:


    current = c.p
    ...
    if c.hoistStack and current == c.hoistStack[-1].p:
        g.warning('can not insert a node before the base of a hoist')
        return
    ...
    parent = current.parent()
    if current.hasBack():
        back = current.getBack()
        p = back.insertAfter()
    elif parent:
        p = parent.insertAsNthChild(0)
    else:
        p = current.insertAfter()
        p.moveToRoot(oldRoot=current)

Yes, this is a bit less elegant than one might hope for, but it's not
nearly bad enough to worry about, imo.  In particular, the call to
p.moveToRoot handles a lot of details not likely to be handled by a virtual
root position.

Again, see c.insertHeadlineBefore for full details.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
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