Skip to content
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

fixes flaky layer export #35

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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