Skip to content

Commit

Permalink
Disables monaco editor paste handling when files are pasted.
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Jun 21, 2023
1 parent 3635deb commit 0f4ec9b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/content-script-main/EditorWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ function getGithubTheme(): Theme {
}
}

const oldAddEventListener = HTMLTextAreaElement.prototype.addEventListener;
HTMLTextAreaElement.prototype.addEventListener = function (
type: string,
listener: any,
...args: any[]
) {
if (type === "paste") {
return (oldAddEventListener as any).apply(this, [
type,
function (e: ClipboardEvent, ...args: any[]) {
if (
e.clipboardData &&
e.clipboardData.files.length > 0 &&
(e.currentTarget as any)?.className ===
"inputarea monaco-mouse-cursor-text"
) {
// Disable monaco paste handler for files, as GitHub handles this already
return;
}
listener(e, ...args);
},
...args,
]);
}

return (oldAddEventListener as Function).apply(this, [
type,
listener,
...args,
]);
};

export class EditorWrapper {
public static wrap(
textArea: HTMLTextAreaElement,
Expand Down

1 comment on commit 0f4ec9b

@texastoland
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something's wrong with your action for publishing:
https://github.com/hediet/browser-ext-github-monaco/actions/runs/5336523629/jobs/9671333311.

Please sign in to comment.