Files
Tom Moor 5ee3f1a5d9 perf: Refactor y-prosemirror loading (#13521)
* wip

* perf: Refactor y-prosemirror loading
2026-08-21 20:49:29 -04:00

24 lines
699 B
TypeScript

import {
closeHistory as pmCloseHistory,
redoDepth,
undoDepth,
} from "prosemirror-history";
import type { EditorView } from "prosemirror-view";
import { stopCapturingUndo } from "./multiplayer";
/**
* Closes the current history item so that subsequent changes start a new undo
* group. Dispatches a closeHistory transaction when prosemirror-history is
* mounted and, when multiplayer is enabled, stops capturing on the Yjs undo
* manager.
*
* @param view The editor view.
*/
export function closeHistory(view: EditorView): void {
if (undoDepth(view.state) > 0 || redoDepth(view.state) > 0) {
view.dispatch(pmCloseHistory(view.state.tr));
}
stopCapturingUndo(view.state);
}