Skip to content

Type Editor


Type Editor / @type-editor/selection-util / selection-from-dom / selectionFromDOM

Function: selectionFromDOM()

ts
function selectionFromDOM(view, origin?): PmSelection;

Defined in: selection-from-dom.ts:24

Converts a DOM selection to a ProseMirror Selection.

This function reads the current browser selection and translates it into a ProseMirror selection that can be used with the editor state. It handles various edge cases including collapsed selections, node selections, and multi-range selections.

Parameters

ParameterTypeDefault valueDescription
viewPmEditorViewundefinedThe editor view containing the DOM and document state
originstringnullOptional string indicating the origin of the selection (e.g., 'pointer')

Returns

PmSelection

A ProseMirror Selection object, or null if the selection is invalid or no focus node exists