Я пытаюсь выделить текст всякий раз, когда пользователь говорит этот текст громко. Я хочу продолжать слушать «намерения», которые пользователь говорит, чтобы увидеть, соответствуют ли они тексту. Если они это сделают, то это слово должно быть выделено, тогда window.getSelection()
должно равняться innerHtml
следующего интервала в документе.
Я попытался добавить +1 к идентификатору элемента, так как у меня естьпоследовательно генерируется идентификатор элемента, т. е. 'word1, word2, word3 и т. д.' '
highlightOnRead=(doc,cursor,intent)=>{
console.log("inside highlight on read")
console.log("intents",intent)
console.log("cursor",cursor.anchorNode.parentNode.id) //we only need the word
console.log("cursor plus 1",doc[cursor+1])
let elem = document.getElementById(cursor.anchorNode.parentNode.id)
if(intent.includes(" ")){
let intents = intent.split(" ")
intent = intents.pop()
}
while (intent !== 'exit'){
if(intent === elem.innerHTML.toLowerCase()){
elem.style.backgroundColor = 'yellow';
//move the cursor to the next element in the div
}else{
console.log("the intent does not match:","elem:",elem.innerHTML,"intent", intent)
}
}
};
// here is my loaded div where I am calling the function
<div id="docbod"className="documentText"
onMouseUp={(e, props, state)=>{
// if(this.props.readAlongHighlightState===true){ }
console.log("intent",this.props.intent)
let doc = document.getElementById("docbod")
if(this.props.readAlongHighlightState===true){
this.highlightOnRead(doc,window.getSelection(),this.props.intent)
}
}
}
value={this.props.documentText}
rows="5"
cols="50"> </div>
I need `windows.getSelection()` to move to the next word in the document so that I can compare it to see if it matches the intent.