Files
outline/shared/editor/lib/chainTransactions.ts
T
Tom Moor ce845b89e9 fix: Correct logic errors in shared utilities (#14904)
* fix: Correct logic errors in shared utilities

* fix: Restore per-column cells in getCellsInRow and convert every attachment url

The g flag made the attachment regex skip every second match, and removing
duplicate cells broke callers that index getCellsInRow by column.

* test: Cover uppercase attachment URLs

* revert: Remove uncertain fixes
2026-12-05 12:48:21 -05:00

28 lines
984 B
TypeScript

import type { Command, Transaction } from "prosemirror-state";
/**
* Chain multiple commands into a single command and collects state as it goes.
*
* When a view is available the state for the next command is read from the
* view after each dispatch, as the view may have applied further transactions
* (e.g. from plugin views) that a locally derived state would not include.
*
* @param commands The commands to chain
* @returns The chained command
*/
export function chainTransactions(
...commands: (Command | undefined)[]
): Command {
return (state, dispatch, view): boolean => {
const dispatcher = (tr: Transaction): void => {
const before = view?.state;
dispatch?.(tr);
state = view && view.state !== before ? view.state : state.apply(tr);
};
const list = [...commands];
const last = list.pop();
list.forEach((command) => command?.(state, dispatcher, view));
return last !== undefined && last(state, dispatch, view);
};
}