• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Word-based text undo/redo

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know of coding example for word-based text undo? By default, Swing undoes and redoes typed-in text one character at a time, but I'd like to undo and redo based on whole words. This is the way most professional word-processing programs do it.

I have a way of doing word-based undo and redo, but it's so complicated and kludgy that I figure there must be a better way out there.

Thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These might help:
http://jroller.com/santhosh/entry/implementing_undo_redo_in_right
http://jroller.com/santhosh/entry/implementing_undo_redo_in_right1
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't used many professional word-processing programs, I've only used Microsoft Word. (Insert Microsoft joke here if you like.) And it doesn't use word-based undo and redo, it gathers up continuous sets of added or deleted text and undoes and redoes those sets. So if you type "Hello Word" and then backspace and type an "l" before the "d", you have two units that can be undone. Clicking Ctrl-Z changes "Hello World" to "Hello Word" and clicking it again makes the whole thing disappear.

Anyway I wrote a subclass of UndoManager that replicated that behaviour. Here's an excerpt from it:

And here's the (inner) ExpandableEdit class which it uses:
That's just a bleeding chunk of code, it won't compile as is. But it's the basic core of Word-emulating undo and redo.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic