Skip to content

Commit

Permalink
enchance event function + add explanation comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Feb 9, 2024
1 parent 611f16c commit a941f3a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,14 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
// 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) {}
});
Expand Down

0 comments on commit a941f3a

Please sign in to comment.