Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/is-mark-change / isMarkChange

Function: isMarkChange()

ts
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:

  1. Compares marks on the first child of each fragment
  2. Calculates which marks were added and which were removed
  3. If exactly one mark was added OR one was removed, it's a mark change
  4. 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

ParameterTypeDescription
curFragmentThe current (new) fragment after the change
prevFragmentThe previous (old) fragment before the change

Returns

MarkChangeInfo

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