More conventional undo behaviour?

I just started using CodeMirror and I noticed the undo behaviour is based on grouping events after an idle delay. For example if I start typing a lot of text (quickly), make a typo and press Ctrl+Z it will delete all of the text that I typed.

Other editors tend to make Ctrl+Z either delete one character at a time (for example this forum) or one word at a time (VS Code, Mousepad etc.). The former behaviour can be achieved in CodeMirror by setting newGroupDelay to a small value such as 50. But I was wondering if undoing by word is possible?

Nobody else has complained about this so I might be weird for using Ctrl+Z instead of ‘backspace’ to delete things, but as the behaviour is different to most text editors, it would be useful to override it.

Thanks

I don’t think there is anything like a consensus on that. This forum seems to rely on the browser’s native behavior, which for (tried Firefox and Chrome Linux) seems to undo all text typed together in one go. Google Docs seems to use a similar system to CodeMirror.

Would an option that allows you to specify a function taking two changesets (the current history event and the new changes) and allows you to determine whether they should be combined work for you?

That approach sounds great. So I could choose not to combine if the user is adding whitespace to a non-whitespace string.

I also use Chrome on Linux (109.0.5414.74, Xfce/Manjaro) and I definitely get one character undo if I press Ctrl+Z, so it is inconsistent even with the same browser I guess!

This patch adds such a configuration option.

2 Likes