Ver código fonte

fix(tree): prepareMoveTo bug

vian 5 anos atrás
pai
commit
0c27ea6bb4
2 arquivos alterados com 11 adições e 3 exclusões
  1. 1 1
      tree/package.json
  2. 10 2
      tree/src/tree.ts

+ 1 - 1
tree/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "@sc/tree",
   "name": "@sc/tree",
-  "version": "1.0.11",
+  "version": "1.0.12",
   "description": "a template for npm package coding",
   "description": "a template for npm package coding",
   "main": "./dist/index.cjs.js",
   "main": "./dist/index.cjs.js",
   "module": "./dist/index.esm.js",
   "module": "./dist/index.esm.js",

+ 10 - 2
tree/src/tree.ts

@@ -561,7 +561,10 @@ export class Tree {
     if (next) {
     if (next) {
       prev = next.getCtx().prev();
       prev = next.getCtx().prev();
     } else {
     } else {
-      prev = parent ? parent.getCtx().lastChild() : null;
+      const roots = this.getRoots();
+      prev = parent
+        ? parent.getCtx().lastChild()
+        : roots[roots.length - 1] || null;
     }
     }
     const baseSeq = prev ? prev.seq + 1 : this.seqStartIndex;
     const baseSeq = prev ? prev.seq + 1 : this.seqStartIndex;
     updateData.push(
     updateData.push(
@@ -574,7 +577,12 @@ export class Tree {
       }))
       }))
     );
     );
     const curBaseSeq = baseSeq + nodes.length;
     const curBaseSeq = baseSeq + nodes.length;
-    const nextBrothers = prev ? prev.getCtx().nextBrothers() : [];
+    // eslint-disable-next-line no-nested-ternary
+    const nextBrothers = prev
+      ? prev.getCtx().nextBrothers()
+      : next
+      ? [next, ...next.getCtx().nextBrothers()]
+      : [];
     updateData.push(
     updateData.push(
       ...nextBrothers.map((node, index) => ({
       ...nextBrothers.map((node, index) => ({
         ID: node.ID,
         ID: node.ID,