🎨 改进文档树拖拽形成子文档时的层级校验 Fix https://github.com/siyuan-note/siyuan/issues/6434

This commit is contained in:
Liang Ding 2022-10-31 22:42:30 +08:00
parent beb5005125
commit f988805c93
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 27 additions and 5 deletions

View file

@ -21,6 +21,7 @@ import (
"net"
"os"
"path"
"path/filepath"
"strings"
"time"
@ -138,3 +139,23 @@ func TimeFromID(id string) (ret string) {
ret = id[:14]
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
}