Browse Source

Improve component delete command

pull/4214/head
Artur Arseniev 4 years ago
parent
commit
6872013669
  1. 18
      src/commands/view/ComponentDelete.js

18
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;
}
},
};

Loading…
Cancel
Save