diff --git a/src/commands/view/ComponentDelete.js b/src/commands/view/ComponentDelete.js index b9591728b..fca34a6d3 100644 --- a/src/commands/view/ComponentDelete.js +++ b/src/commands/view/ComponentDelete.js @@ -1,27 +1,23 @@ import { isArray } from 'underscore'; export default { - run(ed, sender, opts = {}) { + run(ed, s, opts = {}) { const toSelect = []; let components = opts.component || ed.getSelectedAll(); components = isArray(components) ? [...components] : [components]; - // It's important to deselect components first otherwise, - // with undo, the component will be set with the wrong `collection` - ed.select(null); - - components.forEach(component => { - if (!component || !component.get('removable')) { + components.filter(Boolean).forEach(component => { + if (!component.get('removable')) { + toSelect.push(component); return this.em.logWarning('The element is not removable', { - component + component, }); } component.remove(); - component.collection && toSelect.push(component); }); - toSelect.length && ed.select(toSelect); + ed.select(toSelect); return components; - } + }, };