Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/looks-like-backspace / looksLikeBackspace

Function: looksLikeBackspace()

ts
function looksLikeBackspace(old, start, end, $newStart, $newEnd): boolean;

Defined in: parse-change/looks-like-backspace.ts:33

Determines if a change looks like a backspace operation (joining or deleting blocks).

This function performs a sophisticated analysis to detect if a change resulted from a backspace operation. Backspace can either delete an entire block or join two blocks together. The detection helps determine if the change should be delegated to the Backspace key handler instead of being processed as a regular DOM change.

Detection Logic:

  1. Content must have shrunk: The old content range must be larger than the new range
  2. Valid end position: The new end position must be at or after the block boundary
  3. Block deletion: If not in a textblock, check if an entire block was removed
  4. Block join: If in a textblock, verify:
    • Start is at the end of a textblock
    • Next textblock exists and was joined
    • Content after join point matches

The function uses internal helpers to navigate block boundaries and verify that the structure matches a backspace operation pattern.

Parameters

ParameterTypeDescription
oldNode_2The old (before change) document
startnumberStart position of the change in the old document
endnumberEnd position of the change in the old document
$newStartResolvedPosResolved start position in the new (after change) document
$newEndResolvedPosResolved end position in the new (after change) document

Returns

boolean

True if the change pattern matches a backspace operation (either block deletion or block join), false otherwise