These methods simplified editingFinished_callback. Furthermore, they simplified my thought processes, which probably was an essential precondition for the breakthrough.
Today I'll add similar u.before/afterChangeBody methods. It might be possible to simplify some of Leo's existing commands using those methods, but that remains to be seen.
Nevertheless, it would be perfectly fine to leave Leo's body-changing code unchanged. In other words, u.before/afterChangeBody will primarily be for the use of scripts.
Ahas re undo granularity
Many of Leo's body-changing commands eventually call u.setUndoTypingParams. This is clumsy, and the calling sequenced pretty much require lots of ugly kwargs. However, in most cases (eventually) calling u.setUndoTypingParams is not required. Calling the upcoming u.before/afterChangeBody methods would suffice!
Indeed, u.setUndoTypingParams contains complex logic to handle the so-called "granularity" of changes to body text. This is extremely important when handling the endless changes created as the user types in the body pane. But Aha:
undo granularity does not matter for commands that change body text!
In other words, Leo can, and should, create a new undo "bead" for each text-altering command, regardless of undo granularity. In other words, commands should just call u.before/afterChangeBody, not (circuitously) u.setUndoTypingParams. In other words:
u.setUndoTypingParams is really a callback for onTextChanged events!
This Aha will guide me if I do decide to refactor or eliminate ugly methods such as c.updateBodyPane and LeoBody.onBodyChanged. u.setUndoTypingParams is now deprecated for new commands, and in scripts. But to repeat, there is no real need to avoid u.setUndoTypingParams. Existing code is fine as it is.
Summary
Leo's headline code has collapsed. From now on, the new u.before/afterChangeHeadline methods are the recommended way of handling undo/redo (in headline text) in scripts, and in Leo's core.
Similarly, the upcoming u.before/afterChangeHeadline methods will be the recommended way of handling undo/redo (in body text) in scripts, and in Leo's core.
u.setUndoTypingParams is deprecated for commands involving body text. It is really a too-visible callback for qt onTextChanged events. But there is no need to change Leo's existing body-changing commands.
Leo's undo documentation will be revised to discuss the new undoer methods. This section needs examples, and the new methods will make the examples much simpler and easier to understand.
Edward
P.S. None of this work would have been possible 10 years ago. It would have been out of the question
without Leo's clone-find and git-diff commands, git branches, and pylint. Focusing on eliminating kwargs was also an essential part of the discovery process.