Skip to content

Commit

Permalink
fixed flaky layer export.
Browse files Browse the repository at this point in the history
  • Loading branch information
dehmer committed Nov 17, 2023
1 parent 2d2eff9 commit c88dd0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
31 changes: 23 additions & 8 deletions src/renderer/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions src/renderer/model/commands/LayerCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ 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 = {
contentType: 'application/json;vnd=odin',
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
}
Expand Down

0 comments on commit c88dd0e

Please sign in to comment.