Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useTextSelection.md
1---2category: Sensors3---45# useTextSelection67Reactively track user text selection based on [`Window.getSelection`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection).89## Usage1011```vue12<script setup lang="ts">13import { useTextSelection } from '@vueuse/core'1415const state = useTextSelection()16</script>1718<template>19<p>{{ state.text }}</p>20</template>21```2223## Type Declarations2425```ts26export interface UseTextSelectionOptions extends ConfigurableWindow {}27export interface UseTextSelectionReturn {28text: ComputedRef<string>29rects: ComputedRef<DOMRect[]>30ranges: ComputedRef<Range[]>31selection: ShallowRef<Selection | null>32}33/**34* Reactively track user text selection based on [`Window.getSelection`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection).35*36* @see https://vueuse.org/useTextSelection37*38* @__NO_SIDE_EFFECTS__39*/40export declare function useTextSelection(41options?: UseTextSelectionOptions,42): UseTextSelectionReturn43```44