Type Editor / @type-editor/dom-change-util / parse-change/find-diff
parse-change/find-diff
Functions
| Function | Description |
|---|---|
Finds the difference between two fragments and returns the positions of the change. This is the core diff algorithm for detecting what changed between the old document and the parsed DOM content. It uses ProseMirror's built-in diff methods and then applies sophisticated adjustments to handle edge cases. Algorithm Steps:
Preferred Position Handling: When preferredPos is between the diff boundaries, the algorithm tries to move the boundaries to include the cursor position. This ensures changes appear to happen at the cursor rather than at arbitrary matching text positions. For example, if typing "a" in "bat" where cursor is after "b", prefer detecting the change as "b|at" → "ba|at" rather than "ba|t" → "ba|at". Surrogate Pair Handling: UTF-16 surrogate pairs (used for emoji and other non-BMP characters) must not be split. When adjusting boundaries, if we land in the middle of a surrogate pair, adjust by one position to keep the pair intact. See
Remarks Includes special handling for Unicode surrogate pairs (e.g., emoji) |