@@ -465,9 +465,9 @@ export default function makeTreeDraggable(treeEl, options = {}) {
465465 hp . insertAfter ( maskTree2 , startTreeEl )
466466 }
467467 //
468- store . targetPath = options . getPathByBranchEl ( placeholder )
469- let pathChanged = isPathChanged ( )
470- store . targetPathNotEqualToStartPath = pathChanged
468+ store . placeholderPath = options . getPathByBranchEl ( placeholder )
469+ store . targetPath = getTargetPath ( )
470+ let pathChanged = targetTreeEl === startTreeEl && store . targetPath . toString ( ) !== store . startPath . toString ( )
471471 store . pathChangePrevented = false
472472 if ( options . beforeDrop && options . beforeDrop ( pathChanged , store , dhOptions ) === false ) {
473473 pathChanged = false
@@ -493,23 +493,33 @@ export default function makeTreeDraggable(treeEl, options = {}) {
493493 startTreeEl . style . display = 'block'
494494 }
495495 }
496- //
497- function isPathChanged ( ) {
498- const { startTree, targetTree, startPath, targetPath} = store
499- if ( startTree === targetTree && startPath . length === targetPath . length ) {
500- if ( startPath . toString ( ) === targetPath . toString ( ) ) {
501- return false
502- } else {
503- // downward same-level move, the end of targetPath is 1 more than real value
504- // 同级向下移动时, targetPath的末位比真实值大1
505- const t = startPath . slice ( 0 )
506- t [ t . length - 1 ] ++
507- if ( t . toString ( ) === targetPath . toString ( ) ) {
508- return false
496+ function getTargetPath ( ) {
497+ // example
498+ // startPath placeholderPath
499+ // [0] [1]
500+ // [0] [1, 0]
501+ // [3, 1] [3, 3]
502+ // [3, 1] [3, 3, 5]
503+ // above targetPaths should be [0], [0, 0] [3, 2] [3, 2, 5]
504+ const { startTree, targetTree, startPath, placeholderPath} = store
505+ const targetPath = placeholderPath . slice ( 0 )
506+ if ( options . cloneWhenDrag !== true ) {
507+ if ( startTree === targetTree ) {
508+ if ( startPath . length <= targetPath . length ) {
509+ const sw = startPath . slice ( 0 , startPath . length - 1 ) // without end
510+ const tw = targetPath . slice ( 0 , sw . length ) // same length with sw
511+ if ( sw . toString ( ) === tw . toString ( ) ) {
512+ const endIndex = sw . length
513+ if ( startPath [ endIndex ] < targetPath [ endIndex ] ) {
514+ targetPath [ endIndex ] -= 1
515+ } else if ( startPath [ endIndex ] === targetPath [ endIndex ] ) {
516+ // position not changed
517+ }
518+ }
509519 }
510520 }
511521 }
512- return true
522+ return targetPath
513523 }
514524 } ,
515525 } )
0 commit comments