delete component using the keyboard

This commit is contained in:
Maurits Lourens 2021-07-26 23:48:59 +02:00
parent 5421768521
commit 1497f3f680
1 changed files with 12 additions and 2 deletions

View File

@ -103,8 +103,7 @@
} else if (type === "update-prop") {
store.actions.components.updateProp(data.prop, data.value)
} else if (type === "delete-component" && data.id) {
idToDelete = data.id
confirmDeleteDialog.show()
confirmDeleteComponent(data.id)
} else if (type === "preview-loaded") {
// Wait for this event to show the client library if intelligent
// loading is supported
@ -113,8 +112,19 @@
console.warning(`Client sent unknown event type: ${type}`)
}
})
iframe.contentWindow.addEventListener("keydown", event => {
if ((event.key === "Delete" || event.key === "Backspace") && selectedComponentId) {
confirmDeleteComponent(selectedComponentId);
}
})
})
const confirmDeleteComponent = (componentId) => {
idToDelete = componentId
confirmDeleteDialog.show()
}
const deleteComponent = () => {
store.actions.components.delete({ _id: idToDelete })
idToDelete = null