undo removing textmarking

I have this codemirror textarea where a user types in a SQL statement. When the user presses the “Run query” button the query gets run. When the query fails (for example because of a typo) I textmark the query red, when query is correct I textmark the query green. When the user continues typing/correcting/adding to the query I remove the green/red textmark. But when the user undos (CTRL-Z) I also want the textmarking to reappear. How can I accomplish this?

I use the following code to add a green/red marker:

editor.markText(CodeMirror.Pos(0,0),CodeMirror.Pos(editor.lastLine(),Infinity),{className: colorClass, addToHistory: true});

when the marked text becomes dirty (changes) I use this code to remove the marker:

var ranges=editor.getAllMarks();
for (var i=0;i<ranges.length;i++) ranges[i].clear();

gr Jan

This isn’t something that CodeMirror will take care of, but you could, when clearing the marker, store its position, associated with editor.changeGeneration, and when you later get a "change" event that moves the editor back to that state (editor.isClean(generation)), restore the marker.

I’m having trouble figuring out how that might work.

Let’s say every time I want to clear a marker, I call editor.changeGeneration to get an ID.
Then I save the marker info along with the generation ID. So I end up with a bunch of IDs and marks something like this: {8:mark1Data, 12:mark2Data, 17:mark3Data}

Then I add a listener on the “change” event. Is there anything in the change event that would tell me which generation id I should check?

Or would I have to go through all the generations I have saved (8, 12, 17) and check each one with isClean? If there’s no way to determine which one to check, then perhaps I should save the marks in a stack, and only check the last one that was cleared (and pop it off the stack if it is added back).

Actually after playing with this some more, I don’t think this will work for me; I might need to provide my own undo/redo functionality instead of relying on that provided by CodeMirror.