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") { } else if (type === "update-prop") {
store.actions.components.updateProp(data.prop, data.value) store.actions.components.updateProp(data.prop, data.value)
} else if (type === "delete-component" && data.id) { } else if (type === "delete-component" && data.id) {
idToDelete = data.id confirmDeleteComponent(data.id)
confirmDeleteDialog.show()
} else if (type === "preview-loaded") { } else if (type === "preview-loaded") {
// Wait for this event to show the client library if intelligent // Wait for this event to show the client library if intelligent
// loading is supported // loading is supported
@ -113,7 +112,18 @@
console.warning(`Client sent unknown event type: ${type}`) 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 = () => { const deleteComponent = () => {
store.actions.components.delete({ _id: idToDelete }) store.actions.components.delete({ _id: idToDelete })