UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

13 lines (12 loc) 331 B
export function getWordAtCursor(text, cursorPosition) { const wordPattern = /[a-zA-Z0-9_]/; let start = cursorPosition; while (start > 0 && wordPattern.test(text[start - 1])) { start--; } return { word: text.substring(start, cursorPosition), start, end: cursorPosition, }; }