Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo and Redo in WYSYWYG contentEditable in SWT doesn't work

I'm doing a WYSYWYG HTML5 editor With SWT by setting the contentEditable attribute of the body tag to true.

When I'm executing some commands like document.execCommand('bold'), it works perfectly. But when I try to undo an operation with document.execCommand('undo') nothing happens. I don't know if I have to set any undo manager or to do something like that. Can you help me please ?

like image 736
Jbprod Avatar asked Jul 20 '12 12:07

Jbprod


2 Answers

This appears to be a common problem as Google search will reveal. The following site has a good compatibility table and demo for testing.

  • Table: http://www.quirksmode.org/dom/execCommand.html
  • Demo: http://www.quirksmode.org/dom/execCommand/

They also have the following statement on the demo page:

Undo/Redo doesn't work in IE. The problem is that the changes in the textarea to the right are also added to the Undo/Redo stack. There will be no textarea in the final version, so it's not necessary to solve the problem.

like image 59
JSuar Avatar answered Oct 04 '22 14:10

JSuar


According to this quirksmode table, undo/redo works in all major browsers, but it has this note:

Undo works in Safari, but if you do Undo/Redo too often, it crashes. Solved in 3. If you make your own changes in the editable area, Undo/Redo continues to work in Mozilla and Safari (though it ignores your custom changes), but in IE and Opera it stops working.

I don't know how SWT might affect this, but it might be better to use

document.execCommand("undo", "", null)

ExecCommand has always been very buggy, and I don't know much about SWT, but I hope this helps you.

like image 25
rvighne Avatar answered Oct 04 '22 16:10

rvighne