Added the ability to paste one or more Images from the Clipboard (#1876)
Co-authored-by: a3957273 <89583054+a3957273@users.noreply.github.com> Co-authored-by: GCHQ Developer 85297 <95289555+C85297@users.noreply.github.com>
This commit is contained in:
parent
595c90a464
commit
fe69ec5881
@ -151,8 +151,20 @@ class InputWaiter {
|
|||||||
// Event handlers
|
// Event handlers
|
||||||
EditorView.domEventHandlers({
|
EditorView.domEventHandlers({
|
||||||
paste(event, view) {
|
paste(event, view) {
|
||||||
|
const clipboardData = event.clipboardData;
|
||||||
|
const items = clipboardData.items;
|
||||||
|
const files = [];
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const item = items[i];
|
||||||
|
if (item.kind === "file") {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
files.push(file);
|
||||||
|
|
||||||
|
event.preventDefault(); // Prevent the default paste behavior
|
||||||
|
}
|
||||||
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
self.afterPaste(event);
|
self.afterPaste(files);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -914,9 +926,12 @@ class InputWaiter {
|
|||||||
* Handler that fires just after input paste events.
|
* Handler that fires just after input paste events.
|
||||||
* Checks whether the EOL separator or character encoding should be updated.
|
* Checks whether the EOL separator or character encoding should be updated.
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {File[]} files - An array of any files that were included in the paste event
|
||||||
*/
|
*/
|
||||||
afterPaste(e) {
|
afterPaste(files) {
|
||||||
|
if (files.length > 0) {
|
||||||
|
this.loadUIFiles(files);
|
||||||
|
}
|
||||||
// If EOL has been fixed, skip this.
|
// If EOL has been fixed, skip this.
|
||||||
if (this.eolState > 1) return;
|
if (this.eolState > 1) return;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user