From a941f3a1156ccd07fe685d756459572d6feb156a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Fri, 9 Feb 2024 16:57:56 +0100 Subject: [PATCH] enchance event function + add explanation comment --- src/MarkdownTextInput.web.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index da7090fa..e94524c6 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -477,15 +477,14 @@ const MarkdownTextInput = React.forwardRef( // update event listeners events objects const originalAddEventListener = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function (eventName, callback) { - if (eventName === 'paste') { + 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}); } - if (typeof callback === 'function') { - callback(event); - } + callback(event); // eslint-disable-next-line no-empty } catch (e) {} });