Skip to content

Type Editor


Type Editor / @type-editor/dom-change-util / parse-change/should-create-type-over-change / shouldCreateTypeOverChange

Function: shouldCreateTypeOverChange()

ts
function shouldCreateTypeOverChange(typeOver, selection, view, parse): boolean;

Defined in: parse-change/should-create-type-over-change.ts:29

Checks if a change should be created for typing over a selection.

When typing with a selection active, the editor should replace the selected content. However, sometimes no DOM change is detected (perhaps because the browser hasn't yet processed the change). This function detects if we're in that situation and should create a synthetic change.

The conditions checked are:

  • typeOver flag is set (indicates user is typing to replace selection)
  • Selection is a text selection (not a node selection)
  • Selection is not empty (something is selected)
  • Selection is within a single parent node
  • Editor is not in composition mode (not using IME)
  • Parsed selection is collapsed or undefined (no range in parsed content)

Parameters

ParameterTypeDescription
typeOverbooleanWhether typing over mode is active (user started typing with selection)
selectionPmSelectionCurrent editor selection state
viewPmEditorViewThe editor view containing composition state
parseParseBetweenResultParsed document information from the DOM

Returns

boolean

True if a synthetic change should be created to replace the selection, false if the change should be processed normally