@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)
createDoubleClickWordSelector
Create a double-click handler that selects words. Returns a function that should be called on dblclick events.
declare function createDoubleClickWordSelector(): (event: MouseEvent) => void;createTripleClickParagraphSelector
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;expandSelectionToWordBoundaries
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;findWordAt
Find the word at a position and return detailed info
declare function findWordAt(text: string, position: number): WordSelectionResult;findWordBoundaries
Find word boundaries around a position in text Returns [startIndex, endIndex] inclusive start, exclusive end
declare function findWordBoundaries(text: string, position: number): [number, number];getWordAt
Get the word at a position in text
declare function getWordAt(text: string, position: number): string;handleClickForMultiClick
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;isWhitespace
Check if a character is whitespace
declare function isWhitespace(char: string): boolean;isWordCharacter
Check if a character is a word character
declare function isWordCharacter(char: string): boolean;selectParagraphAtCursor
Select the entire paragraph containing the current selection. Looks for the nearest element with [data-paragraph-index] attribute.
declare function selectParagraphAtCursor(): boolean;selectWordAtCursor
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;selectWordInTextNode
Select a word in a specific text node at the given offset
declare function selectWordInTextNode(textNode: Text, offset: number): boolean;Interfaces(1)
WordSelectionResult
Word selection result
interface WordSelectionResult| Member | Type | Summary |
|---|---|---|
| endIndex | number | End index in the text (exclusive) |
| startIndex | number | Start index in the text (inclusive) |
| word | string | The selected word |
Variables(1)
_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;
}