Skip to content

Commit

Permalink
Remove try catch from paste event listener handler (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid authored Feb 15, 2024
1 parent 3af92e8 commit 5443eb1
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,11 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
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) {}
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);
Expand Down

0 comments on commit 5443eb1

Please sign in to comment.