insert-text-at-cursor icon indicating copy to clipboard operation
insert-text-at-cursor copied to clipboard

Support draft-js editor

Open FSou1 opened this issue 5 years ago • 2 comments

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.

FSou1 avatar May 30 '20 16:05 FSou1

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.

grassator avatar Jun 05 '20 13:06 grassator