Question

I know that I can implement multiple undo using the TextUndo widget. But that doesn't do the redo function.

How can I implement both multiple undo and multiple redo?

Was it helpful?

Solution

The text widget supports a full undo/redo functionality. You just have to turn it on; since not all uses of text want that sort of thing, it's off by default. To turn it on, you just need to set the boolean -undo widget option to true. It's as simple as that (though the way you write it might be a little different in languages other than Tcl, e.g., it's undo in Tkinter).

However, PerlTk seems to make a confused mess of it all. For some reason, the Tk::Text widget doesn't support undo/redo (Why? The machinery is in there, poking through.) and the Tk::TextUndo widget doesn't have the redo capability exposed (Why on earth would that be omitted?) These are all limitations in PerlTk, not Tk itself. In that case, your best bet might be the Tk::Text::SuperText class, though to me that's very odd as it's just doing what I consider to be core Tk functionality.

Or maybe it's just the CPAN documentation that's out of date.

OTHER TIPS

Problem is that the '' binding is assigned twice, for the virtual event '<>' (to implement emacs-like pasting) and to the virtual event '<>'. A normal Tk::Text does not have the undo functionality, so having the C-y binding here makes sense. Unfortunately this binding clashes when using a Tk::TextUndo.

You have the following possibilities:

  • use the other bindings for Redo (e.g. the F12 binding, see Tk::MainWindow source code for a complete list, or the "Redo" entry in the popup menu)
  • remove the C-y binding for <<Paste>> globally, e.g. by using: $mw->eventDelete('<<Paste>>', '<Control-Key-y>');

I am not sure how this can be resolved best in the Perl/Tk source itself. Simplest would be to remove the emacs key binding for '<>' here, but then emacs users could be unhappy. I am open to suggestions...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top