While working on issue #3435 
<https://github.com/leo-editor/leo-editor/issues/3435>, I see that 
*u.saveTree* can't possibly work! About a dozen commands and methods call 
u.saveTree indirectly. Undo and redo for these may be dangerous!


This Engineering Notebook post discusses what to do about this situation.


*tl;dr:* See the summary.


*The problem*


A cff shows that about a dozen commands and script helpers call 
*u.beforeChangeTree* and *u.afterChangeTree*. Both these methods call 
*u.saveTree(p)*.


Alas, *u.saveTree has no chance of working*. As a result, Leo's undo logic 
is dangerously flawed in about a dozen places.


The section *<< about u.saveTree >> *discusses* u.createVnodeUndoInfo*, 
u.saveTree's helper. These comments do not describe u.createVnodeUndoInfo 
correctly. Worse, u.createVnodeUndoInfo itself has no chance of solving the 
original problem! Details omitted. 


*Solutions*


Imo, the following commands should *not *be undoable: *refresh-from-disk*, 
*read-at-auto-nodes*, r*ead-at-file-nodes*, and *read-at-shadow-nodes*. 
These commands are "one-way" updates. Rewriting their undo code would be 
fraught. Bugs in the undo/redo logic could be devastating.


Various commands and methods create a single new node. Their undo logic can 
mimic that of undo/redo insert-node. Undoing these commands would delete 
the newly-created node. Redo would undo the delete.


The *abbrev.expand_tree *method might be a unique case. I'm not yet sure 
what to do.


*Summary*


- We must retire u.saveTree, u.beforeChangeTree, and u.afterChangeTree.

- Several commands should *not* be undoable.

- Commands that insert a single node can use the undo/redo logic of 
insert-node.


All of your comments are welcome.


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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/d6c73820-9ac1-4669-8778-02351f588825n%40googlegroups.com.

Reply via email to