Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/needs-selection-overwrite-adjustment

parse-change/needs-selection-overwrite-adjustment

Functions

FunctionDescription

needsSelectionOverwriteAdjustment

Checks if the change needs adjustment to handle typing over selection edge cases.

When typing over a selection, there's an edge case: if the typed character matches the character at the start or end of the selection, the diff algorithm might detect a change that's smaller than the actual selection. This is because the diff sees matching characters and doesn't include them in the change range.

For example, typing "t" over the selection "test" might be detected as just replacing "est" because the first "t" matches.

This function detects when such adjustment is needed by checking:

  • There's an active range selection (from < to)
  • The change is zero-width (start === endB), indicating a replacement
  • The selection is a text selection

See

  • shouldAdjustChangeStartToSelection for start adjustment logic
  • shouldAdjustChangeEndToSelection for end adjustment logic