Type Editor / @type-editor/dom-change-util / parse-change/is-mark-change / isMarkChange
Function: isMarkChange()
function isMarkChange(cur, prev): MarkChangeInfo;Defined in: parse-change/is-mark-change.ts:34
Determines whether one fragment could be created from another by adding or removing a single mark type. Used to optimize mark changes.
This is an optimization for detecting when a change is just adding or removing formatting (like bold or italic) without changing the actual text content. When detected, the change can be applied as a mark operation instead of a full content replacement, which is more efficient and maintains better edit history.
The detection process:
- Compares marks on the first child of each fragment
- Calculates which marks were added and which were removed
- If exactly one mark was added OR one was removed, it's a mark change
- Applies the mark operation to all children and verifies it recreates the current fragment
Returns null if:
- Either fragment is empty
- More than one mark changed
- Both marks were added and removed
- Applying the mark change doesn't recreate the current fragment
Parameters
| Parameter | Type | Description |
|---|---|---|
cur | Fragment | The current (new) fragment after the change |
prev | Fragment | The previous (old) fragment before the change |
Returns
Mark change information containing the mark and operation type, or null if this isn't a simple mark change
See
MarkChangeInfo for return type structure