Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/should-adjust-change-end-to-selection / shouldAdjustChangeEndToSelection

Function: shouldAdjustChangeEndToSelection()

ts
function shouldAdjustChangeEndToSelection(change, selection, parseTo): boolean;

Defined in: parse-change/should-adjust-change-end-to-selection.ts:29

Checks if change end should be adjusted to selection end.

Similar to start adjustment, when typing at the end of a selection, if the typed character matches the character at the selection end, the diff algorithm might place the change end before that matching character. This function detects that case.

The adjustment is needed when:

  • The detected change ends before the selection end
  • But is very close (within 2 positions) to the selection end
  • And the selection end is within the parsed range

When this condition is met, both endA and endB of the change are adjusted to match the selection boundary.

Parameters

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

Returns

boolean

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