Files
outline/shared/editor/plugins/TableColumnResizePlugin.ts
Tom Moor cdc10b4564 fix: Crash when a remote edit arrives during a column resize (#13452)
Every remote change is applied as a full document replacement, which
invalidates the column resize handle while the drag is still active.
Releasing the pointer then resolved position -1 and threw.

Cancel the drag when the handle no longer points at a cell.

Fixes OUTLINE-CLOUD-B3R
2026-08-15 20:25:51 -04:00

35 lines
1.1 KiB
TypeScript

import type { Transaction, EditorState } from "prosemirror-state";
import { Plugin } from "prosemirror-state";
import { columnResizingPluginKey } from "prosemirror-tables";
/**
* A ProseMirror plugin that cancels an in-progress column resize once the drag
* handle no longer points at a cell. The handle is invalidated whenever the
* document is replaced under the pointer, such as by a collaborative edit from
* another user, and resizing with an invalid handle throws.
*/
export class TableColumnResizePlugin extends Plugin {
constructor() {
super({
appendTransaction: (
transactions: readonly Transaction[],
_oldState: EditorState,
newState: EditorState
) => {
if (!transactions.some((transaction) => transaction.docChanged)) {
return undefined;
}
const resizeState = columnResizingPluginKey.getState(newState);
if (!resizeState?.dragging || resizeState.activeHandle > -1) {
return undefined;
}
return newState.tr.setMeta(columnResizingPluginKey, {
setDragging: null,
});
},
});
}
}