How to Get Selected Text in Rich Text Editor?

Hello everyone,

I need help with interacting with selected text within the rich text editor on the WeWeb platform. What I want is for the user to be able to select a fragment of the text and then send that fragment to ChatGPT.

Could someone guide me on how to implement this functionality? I am looking for the best way to capture the text selection and send the selected content to an integration with ChatGPT.

Here is an image example of what I am looking to achieve:

@aurelie
@Joyce

@weweb-team

We don’t have any answers.

Hey @saulo260 :wave:

You can achieve that with custom code. You’ll need to use the getSelection() method.
There is a few ways to trigger that. You can listen to new selection, mouseup event, or keyup.

Let me point you to @GeovanyNocodeBR new video about just that! It’s not in english but you can follow through what he does :slight_smile:

Hi @jptrinh

Yes, @GeovanyNocodeBR answered my question yesterday in a community here in Brazil and made an incredible tutorial that solved my challenge! I am very grateful to him.

Unfortunately, there are still other posts in the community that weren’t as lucky as I was and remain unanswered for quite some time, even with many views:

It would be very helpful for the community if the Weweb team could share a tutorial on rich text, addressing how to insert text at the cursor position and how to replace paragraphs with another paragraph suggested by ChatGPT. These are basic functionalities for anyone looking to develop text, chat, and copywriting platforms that use artificial intelligence, like ChatGPT.

I emphasize the importance of this due to the increasing demand for applications integrated with ChatGPT.

Would it be possible for the Weweb team to produce a tutorial?

Also, I want to highlight the great contribution of the Weweb team with this incredible platform that has achieved so much.

Thank you very much!

Thank you for the mentions @jptrinh e @saulo260