On Sunday, November 8, 2020 at 8:08:19 AM UTC-6, Edward K. Ream wrote: > Work has gone surprisingly well. PR 1725 <https://github.com/leo-editor/leo-editor/pull/1725> gives the full details.
Yesterday was a very good day for Leo... *Breakthrough: Tracking headline changes for undo* qtree.endEditLabel now just closes the headline editor calling w.closeEditor! This in turn fires a callback, editingFinished_callback. This callback is very similar to the old qtree.onHeadChanged method, which no longer exists! Why did I never think of this before? Probably because I was fixated on the base LeoTree.onHeadChanged method. But when using the qt gui there is never any need ever to call qtree.onHeadChanged directly! Aside: I'm dithering about whether to *prevent* scripts from calling qtree.onHeadChanged. If a script called g.app.gui.onHeadChanged, it would in fact be calling LeoTree.onHeadChanged. But I doubt that would matter. *Simplifying undo* > The key to eliminating kwargs was to create new u.before/afterChangeHeadline methods. These are specialized to headlines, thereby reducing the complexity of u.before/afterChangeNodeContents. 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 <http://leoeditor.com/scripting-miscellany.html#making-operations-undoable> 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. *Many *clone-find commands were needed to reveal the Aha's discussed above. Even more clone-find commands were needed to untangle the relationships between c.updateBodyPane, LeoBody.onBodyChanged, and u.setUndoTypingParams. I'll discuss a new pattern involving clone-find in another thread. EKR -- 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/77a50088-0425-4bff-b977-c5b56af722d9o%40googlegroups.com.