Skip to content

Instantly share code, notes, and snippets.

View hrdwdmrbl's full-sized avatar
👨‍🎨
Creating

Marc Beaupre hrdwdmrbl

👨‍🎨
Creating
View GitHub Profile
@hrdwdmrbl
hrdwdmrbl / changedDescendants.ts
Last active December 22, 2025 21:37 — forked from BrianHung/changedDescendants.ts
prosemirror changed nodes / part of document by transaction
/**
* Helper for iterating through the nodes in a document that changed compared
* to the given previous document. Useful for avoiding duplicate work on each transaction.
* Source: https://github.com/ProseMirror/prosemirror-tables/blob/master/src/fixtables.js
*/
import type { Node as PMNode } from "prosemirror-model"
export function changedDescendants(old: PMNode, cur: PMNode, offset: number, f: (node: PMNode, pos: number) => void) {
let oldSize = old.childCount, curSize = cur.childCount
outer: for (let i = 0, j = 0; i < curSize; i++) {