mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 03:08:13 +08:00
Add drag-and-drop and copy-paste file importing/opening throughout the UI (#2012)
* Add file importing by dragging and dropping throughout the UI * Disable comment-profiling-changes.yaml * Fix CI
This commit is contained in:
@@ -92,11 +92,9 @@ export function createDocumentState(editor: Editor) {
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerDelayedZoomCanvasToFitAll, () => {
|
||||
// TODO: This is horribly hacky
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 0);
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 1);
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 10);
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 50);
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 100);
|
||||
[0, 1, 10, 50, 100, 200, 300, 400, 500].forEach((delay) => {
|
||||
setTimeout(() => editor.handle.zoomCanvasToFitAll(), delay);
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -65,17 +65,22 @@ export function createPortfolioState(editor: Editor) {
|
||||
editor.handle.openDocumentFile(data.filename, data.content);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerImport, async () => {
|
||||
const data = await upload("image/*", "data");
|
||||
const data = await upload("image/*", "both");
|
||||
|
||||
if (data.type.includes("svg")) {
|
||||
const svg = new TextDecoder().decode(data.content);
|
||||
editor.handle.pasteSvg(svg);
|
||||
|
||||
const svg = new TextDecoder().decode(data.content.data);
|
||||
editor.handle.pasteSvg(data.filename, svg);
|
||||
return;
|
||||
}
|
||||
|
||||
const imageData = await extractPixelData(new Blob([data.content], { type: data.type }));
|
||||
editor.handle.pasteImage(new Uint8Array(imageData.data), imageData.width, imageData.height);
|
||||
// In case the user accidentally uploads a Graphite file, open it instead of failing to import it
|
||||
if (data.filename.endsWith(".graphite")) {
|
||||
editor.handle.openDocumentFile(data.filename, data.content.text);
|
||||
return;
|
||||
}
|
||||
|
||||
const imageData = await extractPixelData(new Blob([data.content.data], { type: data.type }));
|
||||
editor.handle.pasteImage(data.filename, new Uint8Array(imageData.data), imageData.width, imageData.height);
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerDownloadTextFile, (triggerFileDownload) => {
|
||||
downloadFileText(triggerFileDownload.name, triggerFileDownload.document);
|
||||
|
||||
Reference in New Issue
Block a user