getTextSelection

Category Browser

Gets the range of text selected by the user or the current position of the caret, based on window.getSelection.

Demo

You can select any text on the page.

Selected Text

No text selected

Selected rects
[]

Usage

import { getTextSelection } from '@sv-use/core';
 
const selection = getTextSelection();

Type Definitions

import { type ConfigurableWindow } from '../__internal__/configurable.js';
import type { AutoCleanup, CleanupFunction } from '../__internal__/types.js';
interface GetTextSelectionOptions extends ConfigurableWindow, AutoCleanup {
}
type GetTextSelectionReturn = {
    readonly text: string;
    readonly rects: DOMRect[];
    readonly ranges: Range[];
    current: Selection | null;
    cleanup: CleanupFunction;
};
/**
 * Gets the range of text selected by the user or the current position of the caret.
 * @param options Additional options to customize the behavior.
 * @see https://svelte-librarian.github.io/sv-use/docs/core/browser/get-text-selection
 */
export declare function getTextSelection(options?: GetTextSelectionOptions): GetTextSelectionReturn;
export {};

Sources