Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/get-preferred-diff-position

parse-change/get-preferred-diff-position

Functions

FunctionDescription

getPreferredDiffPosition

Determines the preferred position and side for diff calculation.

The diff algorithm needs to know where the user's cursor was to make better decisions about how to align changes. This function determines the preferred position based on recent keypress activity:

  • After Backspace: Prefers anchoring to the end (selection.to) since backspace deletes backwards from the cursor position
  • Otherwise: Prefers anchoring to the start (selection.from) which is the default for insertions and other changes

The preferred side ('start' or 'end') affects how ambiguous changes are resolved in the diff algorithm.

See

findDiff for how these values are used