Yesterday marked an important milestone in the never-ending effort to 
simplify Leo's code base. Leo now has a new pattern that makes implementing 
undo/redo straightforward. 

I won't show the new pattern here, because of the new limitations on syntax 
coloring in this group. However, the first comment of #1413 
<https://github.com/leo-editor/leo-editor/issues/1413#issue-509567534> 
shows the pattern. Please take a look. The indent-region and 
unindent-region commands in the ekr-undo branch show this pattern in actual 
use.

*Discussion*

For the first time ever, it is now straightforward to define Leo commands 
*without* using either c.updateBodyPane or LeoBody.onBodyChanged. I now see 
clearly that these methods are evil. They have no easily stated purpose. 
They create unnecessary linkages between commands that should be entirely 
self-contained. They are faux helpers.

*Thank you Vitalije*

None of this would have happened without Vitalije's criticism of Leo's 
code. His suggestions:

1) Eliminate kwargs where possible.
2) Duplicate code to avoid unwanted dependencies and faux helpers.

Even with these hints firmly in mind, it took several days to see the way 
forward. Such was the mess that the old undo code was in.

*Summary*

The new undo pattern is a big milestone for Leo:

- Each command is fully responsible for its actions.
- It's now dead easy to understand what the code is doing.
  - No need to understand faux helpers.
  - Everything is explicit.
- The new u.before/afterChangeBody methods do all the undo/redo grunt work.

The new pattern lengthens the code for each command, but the advantages 
just stated are overwhelming.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/125a4137-8130-4ad9-92fa-d9c8d249b31dn%40googlegroups.com.

Reply via email to