From c88dd0e0cf1eb9297428d2506b8e24ea8b63b1ad Mon Sep 17 00:00:00 2001 From: dehmer Date: Fri, 17 Nov 2023 11:24:03 +0100 Subject: [PATCH] fixed flaky layer export. --- src/renderer/Clipboard.js | 31 +++++++++++++++----- src/renderer/model/commands/LayerCommands.js | 6 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/renderer/Clipboard.js b/src/renderer/Clipboard.js index 9d7ee8be..4368e62b 100644 --- a/src/renderer/Clipboard.js +++ b/src/renderer/Clipboard.js @@ -9,13 +9,16 @@ const canCopy = id => ID.isMarkerId(id) || ID.isTileServiceId(id) -export const writeEntries = async (entries) => { +/** + * @async implicit + */ +export const writeEntries = entries => { const clipboardObject = { contentType: CONTENT_TYPE, entries } - navigator.clipboard.writeText(JSON.stringify(clipboardObject)) + return navigator.clipboard.writeText(JSON.stringify(clipboardObject)) } export const readEntries = async () => { @@ -58,30 +61,42 @@ Clipboard.doCopy = async (store, selected) => { return keys } +/** + * @async implicit + */ Clipboard.doDelete = (store, keys) => { - store.delete(keys) + return store.delete(keys) } -Clipboard.prototype.copy = async function () { +/** + * @async implicit + */ +Clipboard.prototype.copy = function () { const selected = this.selection.selected() - Clipboard.doCopy(this.store, selected) + return Clipboard.doCopy(this.store, selected) } Clipboard.prototype.cut = async function () { const selected = this.selection.selected() const keys = await Clipboard.doCopy(this.store, selected) - Clipboard.doDelete(this.store, keys) + return Clipboard.doDelete(this.store, keys) } +/** + * @async implicit + */ Clipboard.prototype.paste = async function () { const entries = await readEntries() if (!entries) return const defaultLayerId = await this.store.defaultLayerId() const tuples = await clone(defaultLayerId, entries) - this.store.insert(tuples) + return this.store.insert(tuples) } +/** + * @async implicit + */ Clipboard.prototype.delete = function () { const selected = this.selection.selected() - this.store.delete(selected) + return this.store.delete(selected) } diff --git a/src/renderer/model/commands/LayerCommands.js b/src/renderer/model/commands/LayerCommands.js index cca2f0a0..76f6d7ec 100644 --- a/src/renderer/model/commands/LayerCommands.js +++ b/src/renderer/model/commands/LayerCommands.js @@ -56,9 +56,6 @@ const ExportLayer = function (services) { Object.assign(ExportLayer.prototype, EventEmitter.prototype) ExportLayer.prototype.execute = async function () { - const layerId = this.selected()[0] - const layer = await this.store.value(layerId) - await this.clipboard.copy() const entries = await readEntries() const content = { @@ -66,8 +63,11 @@ ExportLayer.prototype.execute = async function () { entries } + const layerId = this.selected()[0] + const layer = await this.store.value(layerId) ipcRenderer.send('EXPORT_LAYER', layer.name, content) } + ExportLayer.prototype.enabled = function () { return this.selected().length === 1 }