Browse Source

Improve Component.move method

pull/4427/head
Artur Arseniev 4 years ago
parent
commit
734889c24f
  1. 2
      package.json
  2. 16
      src/dom_components/model/Component.js

2
package.json

@ -72,7 +72,7 @@
}, },
"lint-staged": { "lint-staged": {
"{src,test}/**/*.(t|j)s": [ "{src,test}/**/*.(t|j)s": [
"npm run lint -- --fix", "eslint --ext .ts,.js --fix",
"prettier --single-quote --print-width 120 --arrow-parens avoid --write", "prettier --single-quote --print-width 120 --arrow-parens avoid --write",
"git add" "git add"
] ]

16
src/dom_components/model/Component.js

@ -1703,8 +1703,20 @@ export default class Component extends StyleableModel {
* editor.getSelected().move(dest, { at: 0 }); * editor.getSelected().move(dest, { at: 0 });
*/ */
move(component, opts = {}) { move(component, opts = {}) {
this.remove({ temporary: 1 }); if (component) {
component && component.append(this, opts); const { at } = opts;
const index = this.index();
const sameParent = component === this.parent();
const sameIndex = index === at || index === at - 1;
if (!sameParent || !sameIndex) {
if (sameParent && at && at > index) {
opts.at = at - 1;
}
this.remove({ temporary: 1 });
component.append(this, opts);
}
}
return this; return this;
} }

Loading…
Cancel
Save