WYSYWYG中的撤消和重做在SWT中的contentEditable不起作用

时间:2021-02-06 22:23:19

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

我正在通过将body标签的contentEditable属性设置为true来使用SWT进行WYSYWYG HTML5编辑器。

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 ?

当我执行一些像document.execCommand('bold')这样的命令时,它运行得很好。但是当我尝试使用document.execCommand('undo')撤消操作时,没有任何反应。我不知道是否必须设置任何撤销管理器或做类似的事情。你能帮我吗 ?

2 个解决方案

#1


1  

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

这似乎是谷歌搜索将揭示的常见问题。以下站点具有良好的兼容性表和测试演示。

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.

撤消/重做在IE中不起作用。问题是,右边的textarea中的更改也会添加到Undo / Redo堆栈中。最终版本中没有textarea,因此没有必要解决问题。

#2


1  

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

根据这个quirksmode表,undo / redo适用于所有主流浏览器,但它有这样的说明:

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.

撤消可以在Safari中使用,但是如果你经常进行撤消/重做,它就会崩溃。解决了3.如果你在可编辑区域进行自己的更改,撤消/重做继续在Mozilla和Safari中工作(虽然它忽略了你的自定义更改),但在IE和Opera中它停止工作。

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

我不知道SWT会如何影响这一点,但最好使用它

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

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

ExecCommand一直非常错误,我对SWT知之甚少,但我希望这对你有所帮助。

#1


1  

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

这似乎是谷歌搜索将揭示的常见问题。以下站点具有良好的兼容性表和测试演示。

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.

撤消/重做在IE中不起作用。问题是,右边的textarea中的更改也会添加到Undo / Redo堆栈中。最终版本中没有textarea,因此没有必要解决问题。

#2


1  

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

根据这个quirksmode表,undo / redo适用于所有主流浏览器,但它有这样的说明:

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.

撤消可以在Safari中使用,但是如果你经常进行撤消/重做,它就会崩溃。解决了3.如果你在可编辑区域进行自己的更改,撤消/重做继续在Mozilla和Safari中工作(虽然它忽略了你的自定义更改),但在IE和Opera中它停止工作。

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

我不知道SWT会如何影响这一点,但最好使用它

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

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

ExecCommand一直非常错误,我对SWT知之甚少,但我希望这对你有所帮助。