dankito / RichTextEditor

Rich text WYSIWYG editor for Android and JavaFX
Apache License 2.0
92 stars 36 forks source link

How can I highlight and focus a word programmatically in java #39

Open woozI43 opened 4 years ago

woozI43 commented 4 years ago

Im applying a tts functionality on the text editor and I want to highlight and set focus on the word that is speaking. How can I do that programmatically? I know there is a command in the toolbar that highlights the text but I want to know the code.

dankito commented 4 years ago

The only 'highlighting' of text i am aware of is setting the selected text's background color (by default to yellow). Do you mean that?

This can be done by:

editor.javaScriptExecutor.setTextBackgroundColor(<color>)

But the problem here is that it just sets selected text's background color, and i don't know how to select a text programmaticly.

As under the hood RichTextEditor is using a HTML 5 editor (by setting contenteditable to true), you may there find a way to do it: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand