Manipulating undo state in codemirror
So, I'm using CodeMirror and I would like to omit some changes from the state undo
. Specifically, I have a situation where I want one keystroke
- Replace part of mirrored text AND
- Automatic indentation of fresh area
Doing this would naively mean that when a key is pressed, the press undo
will leave the mirror containing the new text unindented. I would like one to undo
be able to restore the original text rather than go to the irreplaceable version of the replaced text.
The only API-supporting approach seems to .getHistory
be making a call before indentation followed by a call .setHistory
immediately afterwards, but the docs imply that this is a bad idea. In particular, the consequences of this are undefined if the contents of the mirror have changed between calls .getHistory
and .setHistory
, which is the whole point in this situation.
There is a flag in the text markingsaddToHistory
, but it is only available for marking, not for arbitrary changes such as indentation.
Is there a good way to do what I am looking for here?
source to share
Changes made within one operation will result in only one history event.
If the organization for a single operation is not viable, the change start field (set as an argument replaceRange
and replaceSelection
), and in other cases a little more inconvenient by registering an event handler beforeChange
) determines the type of event-event combination that CodeMirror performs. If you assign a source that starts with an asterisk ( *
), subsequent changes to the same source will be merged. If the start begins with a character +
, subsequent changes with the same origin will be merged when they occur within options.historyEventDelay
milliseconds.
source to share