Formatting gets lost when using CTRL + Z

When I load a script into codemirror it looks like this.

image

But when I use CTRL + Z to undo something and I use it one time to much then all formatting gets lost and everything is placed one one line. Is there a way to prevent this?

I cant undo this with CTRL + SHIFT + Z … when I try that then all the text is erased.

Is this in CodeMirror 5? Which browser? Can you reproduce it in the editors on the website?

Yes this is codemirror 5, I just used the latest source from GitHub. I also found another post here that had the same problem and fixed it by adding the historyKeymap but I have no idea how to do that. Already was looking in the codemirror manuals but found nothing so far.

The browser is Chrome

I guess it will be something like this

const extraKeys = {
    "F11": function (cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); },
    "Esc": function (cm) { if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false); },
    "Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); },
    "Ctrl-Y": cm => CodeMirror.commands.foldAll(cm),
    "Ctrl-I": cm => CodeMirror.commands.unfoldAll(cm),
    "Ctrl-J": "toMatchingTag"
};

historyKeymap is a version 6 thing. If I ctrl-z beyond the start of the history in the editor on https://codemirror.net, nothing happens.

Any idea how I can find out why this is happening on my side?

Simplify your setup towards the bare minimum and see at which point the problem goes away?