如何将元素修改正确集成到CKEditor 4中的撤消/重做堆栈中?

如何将元素修改正确集成到CKEditor 4中的撤消/重做堆栈中?,ckeditor,Ckeditor,我正在尝试为CKEditor实现我自己的图像插件替换。我在上从教程中启动了一个实现 现在,唯一可编辑的属性是src 在下面的代码中,$.imagebrowser.openPopup(callback)在用户做出选择后打开一个弹出窗口,并使用图像的新src属性调用callback 这在插入和编辑方面都很好,但在撤销/重做集成中存在一个问题。双击对src属性的修改在其他修改发生(如键入文本)之前是不可撤消的。然后src属性的修改似乎被正确地集成到undo/redo堆栈中,我可以撤销并重做它 知道我做

我正在尝试为CKEditor实现我自己的图像插件替换。我在上从教程中启动了一个实现

现在,唯一可编辑的属性是
src

在下面的代码中,
$.imagebrowser.openPopup(callback)
在用户做出选择后打开一个弹出窗口,并使用图像的新src属性调用callback

这在插入和编辑方面都很好,但在撤销/重做集成中存在一个问题。双击对src属性的修改在其他修改发生(如键入文本)之前是不可撤消的。然后src属性的修改似乎被正确地集成到undo/redo堆栈中,我可以撤销并重做它

知道我做错了什么吗

CKEDITOR.plugins.add( 'customimage', {

    // Register the icons. They must match command names.
    icons: 'customimage',

    // The plugin initialization logic goes inside this method.
    init: function( editor) {
        editor.on( 'doubleclick', function( event ) {
            if(event.data.element.getName() == "img") {
                $.imagebrowser.openPopup(function(src) {
                    event.data.element.setAttribute("src", src);
                });
            }
        });

        editor.addCommand( 'insertCustomimage', {
            allowedContent: ['img[!src,alt]{width,height,float,margin}'],
            // Define the function that will be fired when the command is executed.
            exec: function() {
                $.imagebrowser.openPopup(function(src) {
                    editor.insertHtml('<img src="' + src + '" style="width: 400px; height: auto; float: left; margin: 10px 10px;">');
                });
            }
        });

        // Create the toolbar button that executes the above command.
        editor.ui.addButton( 'Customimage', {
            label: 'Image',
            command: 'insertCustomimage',
            toolbar: 'insert'
        });
    }
});
CKEDITOR.plugins.add('customimage'{
//注册图标。它们必须与命令名匹配。
图标:“自定义图像”,
//插件初始化逻辑在这个方法中。
init:函数(编辑器){
编辑器打开('doubleclick',函数(事件){
if(event.data.element.getName()=“img”){
$.imagebrowser.openPopup(函数(src){
event.data.element.setAttribute(“src”,src);
});
}
});
editor.addCommand('insertCustomimage'{
allowedContent:['img[!src,alt]{width,height,float,margin}',
//定义执行命令时将激发的函数。
exec:function(){
$.imagebrowser.openPopup(函数(src){
编者:insertHtml(“”);
});
}
});
//创建执行上述命令的工具栏按钮。
editor.ui.addButton('Customimage'{
标签:“图像”,
命令:“insertCustomimage”,
工具栏:“插入”
});
}
});

我不确定这是您想要的,但您可以制作快照:

editor.fire( 'saveSnapshot' );
这将向撤消/重做堆栈添加一个状态。 此命令应添加到此行之前:

event.data.element.setAttribute("src", src);

函数的editor.insertHtml()中包含了这一点。但是,如果您正在编辑标签,您需要手动执行此操作

难道不起作用吗?请接受,如果我回答了,如果没有告诉我你在找什么。或者什么是de错误消息?@spons不,它不起作用。不过,你在这里提供了一个有趣的信息,谢谢。然而,我需要更多的时间来进一步调查这一点,目前我还没有。但别担心,我不会让问题和答案如此腐烂。