-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Added the ability to paste one or more Images from the Clipboard #1876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
c33d2c1
f758e5e
4eb0c2f
fcb7c45
d6b7672
5f73f3f
7d4d826
01918e5
45e675c
70dac18
06736cb
eae520a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,18 @@ class InputWaiter { | |
| // Event handlers | ||
| EditorView.domEventHandlers({ | ||
| paste(event, view) { | ||
| const clipboardData = event.clipboardData || window.clipboardData; | ||
| const items = clipboardData.items; | ||
| event.target.files = []; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like bad practice to me to add a custom attribute to an external type. Couldn't we create this list as a local variable, and update the signature of |
||
| for (let i = 0; i < items.length; i++) { | ||
| const item = items[i]; | ||
| if (item.type.indexOf("image") !== -1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good if we could support all file types, rather than just images. Could you not instead check |
||
| const file = item.getAsFile(); | ||
| event.target.files.push(file); | ||
|
|
||
| event.preventDefault(); // Prevent the default paste behavior | ||
| } | ||
| } | ||
| setTimeout(() => { | ||
| self.afterPaste(event); | ||
| }); | ||
|
|
@@ -917,6 +929,9 @@ class InputWaiter { | |
| * @param {event} e | ||
| */ | ||
| afterPaste(e) { | ||
| if (e.target.files.length > 0) { | ||
| this.loadUIFiles(e.target.files); | ||
| } | ||
| // If EOL has been fixed, skip this. | ||
| if (this.eolState > 1) return; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t-martine what is the purpose of
window.clipboardDatahere? I cannot find any documentation for that property.ClipboardEvent.clipboardDatais baseline widely available, so I would have thought it is fine to just use that: https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboardData#browser_compatibilityThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was meant for backwards compatibility with IE11 but I agree to remove it since IE is officially out of support for a while now.
https://stackoverflow.com/questions/56063191/javascript-code-for-copy-to-clipboard-wont-work-in-internet-explorer-11