diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index f3f80823..e94524c6 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -473,6 +473,27 @@ const MarkdownTextInput = React.forwardRef( divRef.current.style.maxHeight = elementHeight; }, [numberOfLines]); + useEffect(() => { + // update event listeners events objects + const originalAddEventListener = EventTarget.prototype.addEventListener; + EventTarget.prototype.addEventListener = function (eventName, callback) { + if (eventName === 'paste' && typeof callback === 'function') { + originalAddEventListener.call(this, eventName, function (event) { + try { + if (divRef.current && divRef.current.contains(event.target as Node)) { + // pasting returns styled span elements as event.target instead of the contentEditable div. We want to keep the div as the target + Object.defineProperty(event, 'target', {writable: false, value: divRef.current}); + } + callback(event); + // eslint-disable-next-line no-empty + } catch (e) {} + }); + } else { + originalAddEventListener.call(this, eventName, callback); + } + }; + }, []); + return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions