Codemirror 自动完成和自动关闭括号不会触发更改事件

Codemirror autocomplete and auto closing brackets doesnt trigger change event

我有以下问题。我已经为节点 js 编写了一个服务器和客户端脚本,用作实时协作代码编辑。 2 个或更多人可以在 CodeMirror 编辑器的同一个实例中编码。在我启用自动完成功能和自动关闭括号之前,它工作完美,但在我完成之后它搞砸了工作。当您使用自动完成列表或括号或标签将由模块而不是您手动关闭时,它不会被识别为更改。我检查了 CodeMirror 实例返回的对象,它不包含自动完成的更改。它甚至不是节点 js 的严格问题,因为如果你想说,通过 ajax 将更改发送到服务器并保存在文件中,它不会发生,因为它不存在于更改对象中。任何人都有类似的问题,可以提供帮助吗?

客户代码:

    var appCM = CodeMirror.fromTextArea(document.getElementById('app-cm'), {
        mode: 'text/html',
        theme: "monokai",
        styleActiveLine: true,
        lineNumbers: true,
        matchBrackets: true,
        indentUnit: 4,
        indentWithTabs: true,
        autoCloseTags: true,
        autoCloseBrackets: true,
        matchTags: false,
        extraKeys: {
            "Ctrl-Space": "autocomplete",
            "Ctrl-Q": function(appCM) {
                appCM.foldCode(appCM.getCursor());
            }
        },
        foldGutter: true,
        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
        readOnly: access
    });

        appCM.on('change', function(i, op) {
            socket.emit('change', op);
        });

        socket.on('change', function(data) {
            appCM.replaceRange(data.text, data.from, data.to);
        });

服务器代码:

socket.on('change', function(op) {
    if(op.origin === '+input' || op.origin === 'paste' || op.origin === '+delete') {
        clients.forEach(function(client) {
            if(client !== socket)
                client.emit('change', op);
        });
    };
});

您正在明确过滤掉来源不是 input/paste/delete 之一的更改。你为什么要那样做?如果您希望对等点保持同步,则需要传播所有更改。