script for redo/undo text?

Sean Cole (Pi) sean at pidigital.co.uk
Tue Jul 9 08:01:19 EDT 2019


Hi Nicolas,

After reviewing my code, I don't think it will suffice for your needs. As I
said, mine was more character/word based which would be overkill on a large
document. More suited to a small text field where lot's of changes to
characters or words will happen. That's not the same as with something
like, say, a word-processor.

The likely method for a WP-like unlimited Un/Re-do is to work with chunks.
It's going to be a major memory-whore for large text but the most
practical, easy way.

You need to setup a global array (gFldTxtA) to store the entire field for
each state you want to return to, index-based (1 to n). You'll also need a
script local (sFldTxtCurrIndex) to store your current array index number.
Each time a key is pressed update gFldTxtA[sFldTxtCurrIndex] with the field
content (all of it). (Note: if it gets really large you may have to just
add a char at a time to it). Any time the returnKey, deleteKey, arrowKey,
pasteKey, cutKey, copyKey, backspaceKey or tabKey is pressed you want to
catch this and add 1 to your sFldTxtCurrIndex and store your new field
content into that for safe-keeping.

Now your undo and redo buttons shift through the array updating the
sFldTxtCurrIndex as it goes. Once the user starts typing or adding more
text again, all indices of gFldTxtA after the current index need to be
wiped (in keeping with common practice) and the current index set. If you
want them to undo redo's as well you will need another script local var to
keep track of these - but will get brain-twistingly complex.

Undo/redo truly is one of the biggest implementation, testing and
maintenance headaches for any sized application. It's no wonder it took
until iOS3 for it to be added to iPhones (badly) along with copy/paste
(which can be equally as distressing when you realise the shear mass of
'types' there are). It's easily underestimated and taken for granted.

I hope this helps in some way. All the best.

Sean Cole
Pi Digital


On Tue, 9 Jul 2019 at 10:24, Pi Digital via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Hi Nicolas
>
> It becomes quite the memory hoarder as the document goes on (as you can
> imagine) but I created one that is basically an indexed svc-like array. It
> can be char or word based.
>
> I also created (although it wouldn’t suit your purpose) a very complex
> undo/redo for a number of prototype game show apps that covered anything
> that happened. It twists your brain working out the infinite possibilities
> but is doable. It often just takes a bit of research and planning -
> especially if you are breaking new ground.
>
> I’ll post up a simplified script in a bit.
>
> Sean Cole
> Pi Digital Prod Ltd
>
> > On 9 Jul 2019, at 04:05, Nicolas Cueto via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >
> > Good day eh.
> >
> > To quote a post from "User Experience Stack Exchange
> > <https://ux.stackexchange.com/questions/12629/undo-history-why-limit-it
> >":
> >
> > "<bold> undo/redo is one of the biggest implementation, testing and
> > maintenance headaches </bold>  in any significantly sized application"
> >
> > And yet I ask...
> >
> > Would someone care to volunteer a redo/undo script that works on text in
> a
> > text-field object? ... especially a script that provides (almost) full
> undo
> > history?
> >
> > (Note: Just changes to text. Not to LC objects themselves.)
> >
> > Ta.
> > --
> > Nicolas Cueto
> > _______________________________________________
> > 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
> _______________________________________________
> 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



More information about the use-livecode mailing list