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 mands 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 ?
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 mands 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 ?
- 2 Does this help stackoverflow./a/5062713/903454 – 5hahiL Commented Nov 24, 2012 at 10:50
2 Answers
Reset to default 1This appears to be a mon problem as Google search will reveal. The following site has a good patibility table and demo for testing.
- Table: http://www.quirksmode/dom/execCommand.html
- Demo: http://www.quirksmode/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.
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.