Files
outline/shared/editor/lib/closeHistory.ts
T
Tom Moor 03fe74710c fix: Undo/redo events duplicated (#12525)
* fix: Undo/redo events duplicated

* fix: Guard history use
Prevent cross polination of editors

* Remove unused check
2026-05-29 20:04:11 -04:00

25 lines
765 B
TypeScript

import {
closeHistory as pmCloseHistory,
redoDepth,
undoDepth,
} from "prosemirror-history";
import type { EditorView } from "prosemirror-view";
import { yUndoPluginKey } from "y-prosemirror";
/**
* 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));
}
const yUndoState = yUndoPluginKey.getState(view.state);
yUndoState?.undoManager?.stopCapturing();
}