mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 改进文档树拖拽形成子文档时的层级校验 Fix https://github.com/siyuan-note/siyuan/issues/6434
This commit is contained in:
parent
beb5005125
commit
f988805c93
2 changed files with 27 additions and 5 deletions
|
|
@ -992,11 +992,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if depth := strings.Count(toPath, "/"); 6 < depth && !Conf.FileTree.AllowCreateDeeper {
|
|
||||||
err = errors.New(Conf.Language(118))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fromDir := strings.TrimSuffix(fromPath, ".sy")
|
fromDir := strings.TrimSuffix(fromPath, ".sy")
|
||||||
if strings.HasPrefix(toPath, fromDir) {
|
if strings.HasPrefix(toPath, fromDir) {
|
||||||
err = errors.New(Conf.Language(87))
|
err = errors.New(Conf.Language(87))
|
||||||
|
|
@ -1016,6 +1011,12 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
childDepth := util.GetChildDocDepth(filepath.Join(util.DataDir, fromBoxID, fromPath))
|
||||||
|
if depth := strings.Count(toPath, "/") + childDepth; 6 < depth && !Conf.FileTree.AllowCreateDeeper {
|
||||||
|
err = errors.New(Conf.Language(118))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
toBox := Conf.Box(toBoxID)
|
toBox := Conf.Box(toBoxID)
|
||||||
if nil == toBox {
|
if nil == toBox {
|
||||||
err = errors.New(Conf.Language(0))
|
err = errors.New(Conf.Language(0))
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -138,3 +139,23 @@ func TimeFromID(id string) (ret string) {
|
||||||
ret = id[:14]
|
ret = id[:14]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetChildDocDepth(treeAbsPath string) (ret int) {
|
||||||
|
dir := strings.TrimSuffix(treeAbsPath, ".sy")
|
||||||
|
if !gulu.File.IsDir(dir) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
baseDepth := strings.Count(filepath.ToSlash(treeAbsPath), "/")
|
||||||
|
depth := 1
|
||||||
|
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
p := filepath.ToSlash(path)
|
||||||
|
currentDepth := strings.Count(p, "/")
|
||||||
|
if depth < currentDepth {
|
||||||
|
depth = currentDepth
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
ret = depth - baseDepth
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue