Disable CTRL-Z (undo) for the very first change

I am using CM6 for forms. The problem I have is that if a user presses CTRL-Z after the initial setting of the value, the whole content disappears. This is formally OK – the editor goes to the previous state, which is before it was set in the first place. But… it’s not what a user expects.

I read here in the forums that there is no way to “reset” the history – you create a new state. Which is fine, but it doesn’t help me prevent undoing the very first change, which is setting the editor to what should be the “initial” history state.

Is there any way to do it?

If you create the new state with the content already in it, instead of firing a separate transaction that sets it, undo won’t delete it.

Ah! How do you create a state with contents already in it?
And, can you create a new state and assign it to an existing view? Or do you have to create a new view?
Sorry, I couldn’t figure it out.

I spent quite a lot of effort on the docs, often reading them helps: EditorStateConfig and EditorView.setState.

Marinj, I think the API is awesomely documented, and it makes total 10000% sense once you know how everything works. Sorry if I didn’t find those calls – there is a lot of documentation, and it’s not always obvious what is what in the whole API.

Thanks for the info and the hints.

1 Like

No wonder you were cranky… I did it, and it all worked. No more undo-weirdness. It was easy. Sorry.

You can also annotate your transaction with an AddToHistory.of(false), can be any change.