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.

Returns

boolean

Example

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

getSelection()

getSelection(): Selection | null

Defined in: selectionapi/index.ts:21

Gets the current Selection object, if available.

Returns

Selection | null

Example

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

getSelectedText()

getSelectedText(): string

Defined in: selectionapi/index.ts:34

Gets the currently selected text, if any.

Returns

string

Example

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

clearSelection()

clearSelection(): void

Defined in: selectionapi/index.ts:47

Clears the current selection, if any.

Returns

void

Example

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

selectElementText()

selectElementText(element): void

Defined in: selectionapi/index.ts:61

Selects the text content of a given element.

Parameters

element

Element

The element whose text content to select.

Returns

void

Example

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