Is dirty flag available in codemirror?

We are using code mirror version 5.49.2. Does code mirror have an api or a flag to check if the code in the editor is dirty or in other words, if the user has edited the code in the editor? I am not looking at the ‘change’ event listener, which I understand will launch everytime there is a change, while what i am looking at is, if there is an api which can be called when required, to find out if the code is dirty.
Thanks in advance.

Look at the changeGeneration and isClean methods.

Thanks for the reply. Will check

@marijn is there something similar in v6?

No, but documents are structure-sharing persistent values, and comparing them is optimized to make use of this, so if you just want to check whether a the current document is the same as some previous one, keep a reference to that previous state.doc, and compare with cleanDoc.eq(state.doc) later.

1 Like

Thanks for your reply. I just want to be able to decide whether to save changes on blur event (via rest API)