R
fn

useTextSelection

v0.0.15testeddemo

Reactively track the user's text selection via `Window.getSelection`.

Example

ts
const { text, rects, ranges, selection } = useTextSelection();
watch(text, (value) => console.log('selected:', value));

Demo

Loading demo…

Signature

ts
export function useTextSelection(
  options: UseTextSelectionOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseTextSelectionOptionsOptions (custom `window`, `document`)

Returns

UseTextSelectionReturnReactive `text`, `rects`, `ranges`, and the raw `selection`