Skip to content

Commit

Permalink
Fix paste event listeners (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek authored Mar 25, 2024
1 parent 70d8efd commit 1613bc3
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,6 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
[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) {
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);
});
} else {
originalAddEventListener.call(this, eventName, callback);
}
};
}, []);

useEffect(() => {
if (!divRef.current) {
return;
Expand Down

0 comments on commit 1613bc3

Please sign in to comment.