grassator / insert-text-at-cursor

Fast crossbrowser insertion of text at cursor position in a textarea / input
MIT License
73 stars 7 forks source link

Support draft-js editor #11

Open FSou1 opened 4 years ago

FSou1 commented 4 years ago

Greetings,

I've been using your package for inserting text into default textarea/input components and it works great.

Unfortunately, it doesn't work well at sites that use the draft-js editor (e.g. reddit or facebook).

Here is a workaround that works for draft-js.

Is there a chance to support this editor?

This is the minimum valuable code that inserts a text at cursor with draft-js:

function addTextToDraftJs(element, text) {
    var textEvent = document.createEvent('TextEvent');
    textEvent.initTextEvent ('textInput', true, true, null, text);                    
    element.dispatchEvent(textEvent);
}

addTextToDraftJs(document.activeElement, 'it works');

Thx.

grassator commented 4 years ago

Hello and thank you for creating an issue.

I would like to avoid having code that is there to fix compatibility with specific products. If it is possible to detect support for this way of inputting text in a browser, which seems doable, it could be used as the preferred method in those browsers. I'm happy to merge and release a new version if you (or somebody else) can make a corresponding pull request.

rahulbansal16 commented 2 months ago

Is there a way to insert text into the content editable divs?