selectionapi
Read, clear, and set text selection via the Selection API.
Import: @rtorcato/browser-common/selectionapi
Example
import {
isSelectionApiAvailable,
getSelectedText,
clearSelection,
selectElementText,
} from '@rtorcato/browser-common/selectionapi'
if (isSelectionApiAvailable()) {
const text = getSelectedText()
clearSelection()
selectElementText(document.querySelector('#code')!)
}
Exports
isSelectionApiAvailable()— feature checkgetSelection()— the currentSelectionobject, ornullgetSelectedText()— the currently selected text, or''clearSelection()— clears the current selectionselectElementText(element)— selects the text content of an element
See the API reference for full signatures.