readonly textmarkers and history management


I noticed in the programming API doc that readonly textmarkers clear the history state but I didn’t figure out why it’s done this way.

As workaround I currently copy the state of the history object before setting the new readonly textmarkers and then restore the copy after Codemirror instance’s history has been cleared.

It seems to work this way but I don’t know if there are possible side effects…
According to you could it create problems ?

Undoing only works if the document is exactly in the state it was in when the change was made. With readonly spans, we can no longer guarantee that (undoing an event that touched a readonly span won’t put the document back where it used to be). So if you make two changes, then set the changed text readonly, and try to undo them again, the document is likely to get corrupted on the second undo.

We could write some code that preserves as much history as it can in this situation, only cutting the history off at the first event that actually touches a readonly span, but that seemed too unpredictable, expensive, and messy at the time. (And I think I still feel that way.)