Skip to main content

@rtorcato/browser-common / selectionapi

selectionapi

Functions

isSelectionApiAvailable()

isSelectionApiAvailable(): boolean

Defined in: selectionapi/index.ts:9

Checks if the Selection API is available in the current environment.

Example

import { isSelectionApiAvailable } from '@rtorcato/browser-common/selectionapi'
if (isSelectionApiAvailable()) readSelection()

Returns

boolean


getSelection()

getSelection(): Selection | null

Defined in: selectionapi/index.ts:21

Gets the current Selection object, if available.

Example

import { getSelection } from '@rtorcato/browser-common/selectionapi'
const sel = getSelection()

Returns

Selection | null


getSelectedText()

getSelectedText(): string

Defined in: selectionapi/index.ts:34

Gets the currently selected text, if any.

Example

import { getSelectedText } from '@rtorcato/browser-common/selectionapi'
const text = getSelectedText()

Returns

string


clearSelection()

clearSelection(): void

Defined in: selectionapi/index.ts:47

Clears the current selection, if any.

Example

import { clearSelection } from '@rtorcato/browser-common/selectionapi'
clearSelection()

Returns

void


selectElementText()

selectElementText(element): void

Defined in: selectionapi/index.ts:61

Selects the text content of a given element.

Example

import { selectElementText } from '@rtorcato/browser-common/selectionapi'
selectElementText(document.querySelector('#code')!)

Parameters

element

Element

The element whose text content to select.

Returns

void