Что выглядит немного более простым решением.
document.addEventListener('selectionchange', () => {
const selection = window.getSelection();
const matchingRE = new RegExp(`^.{0,${selection.focusOffset}}\\s+(\\w+)`);
const clickedWord = (matchingRE.exec(selectiaon.focusNode.textContent) || ['']).pop();
});
Я тестирую