What is a proper way to delete a position?

31 views
Skip to first unread message

Alexey Tikhonov

unread,
Dec 7, 2020, 2:11:39 AM12/7/20
to leo-editor
Hello!

I'm trying to make a script which would replace a selected node in the outline with the node's "shell copy". The new node should have the same header and body as the original one with all children cloned. After creating the new node the original position should be deleted - and that does not work. Could you, please, give me a hint where an error is?

The script looks like this:

# Replaces a node with its shell copy -
# a node with the copied header/body and cloned children
shell_copy = p.insertBefore()
shell_copy.h = p.h
shell_copy.b = p.b

# Preserve the order of the children:
child_no = 0
for child in p.children():
    c.dragCloneToNthChildOf(child, shell_copy, child_no)
    child_no = child_no + 1

# Keep it tidy
shell_copy.contract()

#Delete the old node
p.doDelete() # Does not delete the position. Wrong method?

# Select the newly created position
c.redraw(shell_copy)

Alexey

Edward K. Ream

unread,
Dec 7, 2020, 6:36:27 AM12/7/20
to leo-editor
On Mon, Dec 7, 2020 at 1:11 AM Alexey Tikhonov <tickli...@gmail.com> wrote:
Hello!

I'm trying to make a script which would replace a selected node in the outline with the node's "shell copy". The new node should have the same header and body as the original one with all children cloned. After creating the new node the original position should be deleted - and that does not work. Could you, please, give me a hint where an error is?

My guess is that the culprit is:

shell_copy = p.insertBefore()

Oops. This invalidates position p!

Instead, the safe way is to create the new node after p. Now position p remains valid.

Edward

Alexey Tikhonov

unread,
Dec 7, 2020, 11:03:01 AM12/7/20
to leo-e...@googlegroups.com
Thanks!

пн, 7 дек. 2020 г., 18:36 Edward K. Ream <edre...@gmail.com>:
--
You received this message because you are subscribed to a topic in the Google Groups "leo-editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leo-editor/oAaO_35AfC8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAMF8tS1eyprTAoHYzG9A1XXUUL8yFsfVXJ_w-W7jC84seKVW_Q%40mail.gmail.com.

Edward K. Ream

unread,
Dec 7, 2020, 2:28:00 PM12/7/20
to leo-editor


On Mon, Dec 7, 2020 at 10:03 AM Alexey Tikhonov <tickli...@gmail.com> wrote:
Thanks!

You're welcome. Happy scripting.

Edward
Reply all
Reply to author
Forward
0 new messages