Browse Source

Add `core:component-delete` command

pull/1035/head
Artur Arseniev 9 years ago
parent
commit
396047a9eb
  1. 22
      src/commands/index.js
  2. 8
      src/commands/view/SelectComponent.js

22
src/commands/index.js

@ -112,15 +112,7 @@ module.exports = () => {
defaultCommands['tlb-delete'] = {
run(ed) {
var sel = ed.getSelected();
if (!sel || !sel.get('removable')) {
console.warn('The element is not removable');
return;
}
ed.select(null);
sel.destroy();
return ed.runCommand('core:component-delete');
}
};
@ -235,6 +227,18 @@ module.exports = () => {
coll.add(clp.clone(), { at });
}
};
defaultCommands['core:component-delete'] = (ed, sender, opts = {}) => {
let component = opts.component || ed.getSelected();
if (!component || !component.get('removable')) {
console.warn('The element is not removable');
return;
}
ed.select(null);
component.destroy();
return component;
};
if (c.em) c.model = c.em.get('Canvas');

8
src/commands/view/SelectComponent.js

@ -70,13 +70,7 @@ module.exports = {
if (key == 8 || key == 46) {
if (!focused) e.preventDefault();
if (comp && !focused) {
if (!comp.get('removable')) return;
comp.set('status', '');
comp.destroy();
this.hideBadge();
this.clean();
this.hideHighlighter();
this.editorModel.set('selectedComponent', null);
this.editor.runCommand('core:component-delete');
}
}
},

Loading…
Cancel
Save