Skip to content

Type Editor


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

Function: getPreferredDiffPosition()

ts
function getPreferredDiffPosition(view): {
  preferredPos: number;
  preferredSide: "start" | "end";
};

Defined in: parse-change/get-preferred-diff-position.ts:29

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.

Parameters

ParameterTypeDescription
viewPmEditorViewThe editor view containing input state and current selection

Returns

ts
{
  preferredPos: number;
  preferredSide: "start" | "end";
}

Object containing: - preferredPos: The document position to anchor the diff from - preferredSide: Whether to prefer 'start' or 'end' alignment

NameTypeDefined in
preferredPosnumberparse-change/get-preferred-diff-position.ts:29
preferredSide"start" | "end"parse-change/get-preferred-diff-position.ts:29

See

findDiff for how these values are used