Browse Source

Refactor selection and avoid useless removes

multiple-select
Artur Arseniev 8 years ago
parent
commit
8fa54f9546
  1. 6
      src/commands/index.js
  2. 6
      src/editor/model/Editor.js

6
src/commands/index.js

@ -132,10 +132,11 @@ module.exports = () => {
const selAll = [...ed.getSelectedAll()];
const toolbarStyle = ed.Canvas.getToolbarEl().style;
const nativeDrag = event && event.type == 'dragstart';
const defComOptions = { preserveSelected: 1 };
const hideTlb = () => {
toolbarStyle.display = 'none';
em.stopDefault();
em.stopDefault(defComOptions);
};
if (!sel || !sel.get('draggable')) {
@ -155,7 +156,8 @@ module.exports = () => {
};
const onEnd = (e, opts) => {
em.runDefault();
em.runDefault(defComOptions);
selAll.forEach(sel => sel.set('status', 'selected'));
ed.select(selAll);
sel.emitUpdate();
dragger && dragger.blur();

6
src/editor/model/Editor.js

@ -1,4 +1,4 @@
import { isUndefined, defaults, isArray } from 'underscore';
import { isUndefined, defaults, isArray, contains } from 'underscore';
import { getModel } from 'utils/mixins';
const deps = [
@ -236,7 +236,9 @@ module.exports = Backbone.Model.extend({
const multiple = isArray(el);
const els = multiple ? el : [el];
const selected = this.get('selected');
multiple && selected.remove(selected.models);
// Don't remove alredy selected components
multiple && selected.remove(selected.filter(sel => !contains(els, sel)));
els.forEach(el => {
const model = getModel(el, $);

Loading…
Cancel
Save