This Engineering Notebook post summarizes PR #3473: use flat json for cut/copy/paste nodes. This PR is full of unexpected complications and edge cases.
I plan to delay this PR until after Félix releases leoJS. I don't want to distract him, and Leo works well enough without the PR.
Overview of the PR
The PR uses "flat" json when cutting, coping, and pasting nodes.
c.archive creates the json from a node and its descendants when Leo copies or cuts a node.
c.unarchive "patches" a given root vnode so that the root contains the result of the paste operation. A command_name argument tells c.unarchive whether the paste was paste-node, paste-retaining-clones, or paste-as-template.
The PR defines various helper functions and methods. See the PR for details. The PR also creates unit tests for all new and changed code.
This overview seems straightforward, but the unit tests revealed many unexpected complications. The PR contains over 100 commits pushed over a period of three weeks.
What body text wins?
When using paste-retaining-clones, should pasted body text override existing body text? Leo's existing code doesn't do this.
Issue #3485 suggests (for paste-retaining-clones) that pasted body text should override existing body text. But I have my doubts. Why prefer potentially older body text?
Server compatibility
Json as a file format
A new kwarg will tell c.archive whether to write "marks" and "was_cloned" keys. Those keys should not appear in a file format: they would create unnecessary diffs. A new "kind" key will tell checker methods what archive keys to expect.
Summary
I have omitted all mention of the details that have bedeviled me for the past three weeks. Little work remains.
Imo, Leo should always use the c.archive format when cutting, copying, and pasting nodes. Others may disagree.
#3505 suggests that Leo should optionally write .leo files in c.archive format.
Issues #3485, #3505, and PR #3473 have 6.7.5 milestones. However, I'll merge no related code until Félix finishes his work on leoJS.
All questions and comments are welcome.
Edward