Skip to content

Type Editor


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:

  1. An anchor node exists in the selection
  2. The anchor node is within the editor DOM
  3. 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

ParameterTypeDescription
viewPmEditorViewThe editor view to check

Returns

boolean

True if a valid selection exists within the editor