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
| Parameter | Type | Default value | Description |
|---|---|---|---|
view | PmEditorView | undefined | The editor view containing the DOM and document state |
origin | string | null | Optional 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