Type Editor / @type-editor/selection-util / has-selection / hasSelection
Function: hasSelection()
ts
function hasSelection(view): boolean;Defined in: has-selection.ts:20
Checks if the editor contains a valid DOM selection.
This function verifies that:
- An anchor node exists in the selection
- The anchor node is within the editor DOM
- For non-editable views, the focus node is also within the editor DOM
Text nodes (nodeType === 3) are checked via their parent element. This is wrapped in a try-catch because Firefox throws 'permission denied' errors when accessing properties of nodes in generated CSS elements.
Parameters
| Parameter | Type | Description |
|---|---|---|
view | PmEditorView | The editor view to check |
Returns
boolean
True if a valid selection exists within the editor