  startIndex--;
                }
                return startIndex;
            };

            // Replace current word with selected suggestion
            const replaceCurrentWord = (newWord) => {
                const currentValue = textarea.value;
                const cursorPos = textarea.selectionStart;
                const startIndex = findIndexOfCurrentWord();

                const newValue = currentValue.substring(0, startIndex + 1) +
                                newWord +
                   