New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-core/utils/textSelection

Text Selection Utilities

Utilities for word-level and paragraph-level text selection. Used for double-click (word) and triple-click (paragraph) selection.

Functions(12)

Create a double-click handler that selects words. Returns a function that should be called on dblclick events.

declare function createDoubleClickWordSelector(): (event: MouseEvent) => void;
fn

createTripleClickParagraphSelector

packages/core/src/utils/textSelection.ts:440

Create a triple-click handler that selects paragraphs. This uses our custom click counting since browsers have inconsistent triple-click.

declare function createTripleClickParagraphSelector(): (event: MouseEvent) => void;
fn

expandSelectionToWordBoundaries

packages/core/src/utils/textSelection.ts:248

Expand the current selection to word boundaries. If there's a collapsed selection (cursor), selects the word at cursor. If there's an existing selection, expands to include complete words.

declare function expandSelectionToWordBoundaries(): boolean;

Find the word at a position and return detailed info

declare function findWordAt(text: string, position: number): WordSelectionResult;

Find word boundaries around a position in text Returns [startIndex, endIndex] inclusive start, exclusive end

declare function findWordBoundaries(text: string, position: number): [number, number];

Get the word at a position in text

declare function getWordAt(text: string, position: number): string;

Handle click event for multi-click detection. Call this in your click handler. Returns the click count (1 = single, 2 = double, 3 = triple).

declare function handleClickForMultiClick(event: MouseEvent): number;

Check if a character is whitespace

declare function isWhitespace(char: string): boolean;

Check if a character is a word character

declare function isWordCharacter(char: string): boolean;

Select the entire paragraph containing the current selection. Looks for the nearest element with [data-paragraph-index] attribute.

declare function selectParagraphAtCursor(): boolean;

Select a word at the current cursor position using the browser's native APIs. This works reliably across different browsers and handles contentEditable well.

declare function selectWordAtCursor(): boolean;

Select a word in a specific text node at the given offset

declare function selectWordInTextNode(textNode: Text, offset: number): boolean;

Interfaces(1)

Word selection result

interface WordSelectionResult
MemberTypeSummary
endIndexnumberEnd index in the text (exclusive)
startIndexnumberStart index in the text (inclusive)
wordstringThe selected word

Variables(1)

const

_default

_default: {
    isWordCharacter: typeof isWordCharacter;
    isWhitespace: typeof isWhitespace;
    findWordBoundaries: typeof findWordBoundaries;
    getWordAt: typeof getWordAt;
    findWordAt: typeof findWordAt;
    selectWordAtCursor: typeof selectWordAtCursor;
    selectWordInTextNode: typeof selectWordInTextNode;
    expandSelectionToWordBoundaries: typeof expandSelectionToWordBoundaries;
    selectParagraphAtCursor: typeof selectParagraphAtCursor;
    handleClickForMultiClick: typeof handleClickForMultiClick;
    createDoubleClickWordSelector: typeof createDoubleClickWordSelector;
    createTripleClickParagraphSelector: typeof createTripleClickParagraphSelector;
}