Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/should-adjust-change-start-to-selection / shouldAdjustChangeStartToSelection

Function: shouldAdjustChangeStartToSelection()

ts
function shouldAdjustChangeStartToSelection(
  change,
  selection,
  parseFrom,
): boolean;

Defined in: parse-change/should-adjust-change-start-to-selection.ts:28

Checks if change start should be adjusted to selection start.

When typing at the start of a selection, if the typed character matches the character at the selection start, the diff algorithm might place the change start after that matching character. This function detects that case.

The adjustment is needed when:

  • The detected change starts after the selection start
  • But is very close (within 2 positions) to the selection start
  • And the selection start is within the parsed range

The threshold of 2 positions handles multi-byte characters and ensures we don't over-adjust.

Parameters

ParameterTypeDescription
changeDocumentChangeThe detected document change
selectionPmSelectionCurrent editor selection state
parseFromnumberStart position of the parsed range in the document. Used to verify selection is within parsed content.

Returns

boolean

True if the change start should be adjusted to match selection.from, false if no adjustment is needed