draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

How to get editor innerText and manipulate?

Open Maijied opened this issue 8 years ago • 6 comments

I need those code to get innerText and manipulate them for make it better.. if anyone know about this please help me.....

Maijied avatar Feb 19 '18 19:02 Maijied

Hi @Maijied - can you give an example of what you want to do? I need more info to help you.

flarnie avatar Feb 20 '18 15:02 flarnie

Some helpful methods: ContentState.getPlainText() -> https://draftjs.org/docs/api-reference-content-state.html#getplaintext

ContentState.createFromText() -> https://draftjs.org/docs/api-reference-content-state.html#createfromtext

You could read the "innerText" of the editor using getPlainText, change the text, and then create a new updated contentState using createFromText and then pass the updated contentState to your Draft.js editor.

flarnie avatar Feb 20 '18 15:02 flarnie

@flarnie how i'll copy editor innerText by a button. Like Copy To Clipboard method. Thanks in advance.

Maijied avatar Feb 20 '18 22:02 Maijied

And basically i work in draft.js for making a editor where editor automatically check #Bangla spell by calling API and suggest 2 gram data(Text).

Maijied avatar Feb 20 '18 23:02 Maijied

I think this should demonstrate how you can do it:

https://jsfiddle.net/m6z0xn4r/452/

This demonstrates -

  • how to copy the current selection to the clipboard
  • how to set the selection in the Draft editor
  • how to get the text of the editor

I hope you can use the example to do what you need, let me know if there is more to your question.

flarnie avatar Feb 21 '18 16:02 flarnie

After press the enter button ,text line get a new div .That's why i cant implement my spell checker api for underline the false words . How i get all text or by which div? and push those words back to the same div? @flarnie

Maijied avatar Feb 24 '18 20:02 Maijied