It would be nice to have access to the dirty state of the editor.
I see there is code for this in vscode but not in monaco, yet it is a useful feature.
The "monarch" page of the website approximates dirty state by just marking dirty = true when a change is made in the editor, but if changes are made then undone, there is no built-in way to have a correct dirty status.
There is model.getAlternativeVersionId():
Get the alternative version id of the model. This alternative version id is not always incremented, it will return the same values in the case of undo-redo.
So to implement a dirty indicator for example:
lastSavedVersionId = model.getAlternativeVersionId()lastSavedVersionId = model.getAlternativeVersionId()model.onDidChangeContent(...)), you can determine fileIsDirty = (lastSavedVersionId !== model.getAlternativeVersionId())
Most helpful comment
There is
model.getAlternativeVersionId():So to implement a dirty indicator for example:
lastSavedVersionId = model.getAlternativeVersionId()lastSavedVersionId = model.getAlternativeVersionId()model.onDidChangeContent(...)), you can determinefileIsDirty = (lastSavedVersionId !== model.getAlternativeVersionId())