Implementing UNDO

Mike Kerner MikeKerner at roadrunner.com
Fri May 21 16:09:22 EDT 2021


fyi, for posterity, here is the link to the wiki for levure's undo manager
helper
https://github.com/trevordevore/levure/wiki/helper-undo_manager

On Fri, May 21, 2021 at 2:34 PM David Epstein via use-livecode <
use-livecode at lists.runrev.com> wrote:

> LC’s built in undo does not appear to undo anything done by something I
> have scripted.
> My approach is to use a global array variable “u” to store information
> needed to undo the most recent action.  On each action, an “undoInit” puts
> empty into u, after (if necessary) cleaning up anything u’s values indicate
> is left over from the prior action (e.g., actually deleting an object that
> had been only “pseudo-deleted” (hidden) so as to make the user’s choice of
> deletion undoable).  Then the appropriate new values are loaded into u.
> The main elements I use are
>
> # u["cardID"] = short id of the card where the undoable action was taken
> # u["stackName"] = short name of the stack where the undoable action was
> taken
> # u["changed"], list of objects being changed, each line has:
> propName,objectID
> # u[propName,objectID] holds prior value of that property of that object
> (one key/value for each line of u["changed"]
> # u["removed"], list of objectID,cardID,stackName for objects being
> pseudo-removed
> # u["added"], list of objectID,cardID,stackName for objects being added
> # u["cardsRemoved"], list of cards being pseudo-removed, each line has:
> cardID,cardNumber
> # u["cardsAdded"], list of cards being added, each line has:
> cardID,cardNumber
>
> The “Undo” command makes sure we’re on card id u[“cardID”] of stack
> u[“stackName”}, then checks for non-empty values of
> u[“changed”],u[“removed”],u[“added”],u{“cardsRemoved”], and
> u[“cardsAdded”], and uses values stored in u to restore the prior state of
> things, while reloading u with values reporting the state of things now
> being reversed.
>
> For text, I load u[“changed”] with “htmlText”,<myFieldID>, and load
> u[“htmlText”,<myFieldID>] with the htmlText of that field before the latest
> editing.
>
> David Epstein
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."



More information about the use-livecode mailing list