I was able to achieve this using a Compartment
import { Compartment } from '@codemirror/state';
export const historyCompartment = new Compartment();
export function setup() {
return [
// ...other initial extensions
historyCompartment.of(history())
];
}
export function someAction(view: EditorView) {
// Clear history
view.dispatch({
effects: [historyCompartment.reconfigure([])],
});
// Add history back
view.dispatch({
effects: [historyCompartment.reconfigure([history()])],
});
}