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'; import { isArray } from 'underscore';
export default { export default {
run(ed, sender, opts = {}) { run(ed, s, opts = {}) {
const toSelect = []; const toSelect = [];
let components = opts.component || ed.getSelectedAll(); let components = opts.component || ed.getSelectedAll();
components = isArray(components) ? [...components] : [components]; components = isArray(components) ? [...components] : [components];
// It's important to deselect components first otherwise, components.filter(Boolean).forEach(component => {
// with undo, the component will be set with the wrong `collection` if (!component.get('removable')) {
ed.select(null); toSelect.push(component);
components.forEach(component => {
if (!component || !component.get('removable')) {
return this.em.logWarning('The element is not removable', { return this.em.logWarning('The element is not removable', {
component component,
}); });
} }
component.remove(); component.remove();
component.collection && toSelect.push(component);
}); });
toSelect.length && ed.select(toSelect); ed.select(toSelect);
return components; return components;
} },
}; };

Loading…
Cancel
Save