mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve dragging of headings or list items to the doc tree https://github.com/siyuan-note/siyuan/issues/13170
This commit is contained in:
parent
8bc3186976
commit
b6cd6930c7
4 changed files with 121 additions and 19 deletions
|
|
@ -273,7 +273,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
|
|||
return
|
||||
}
|
||||
|
||||
func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID, newTargetPath string, err error) {
|
||||
func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (srcRootBlockID, newTargetPath string, err error) {
|
||||
srcTree, _ := LoadTreeByBlockID(srcHeadingID)
|
||||
if nil == srcTree {
|
||||
err = ErrBlockNotFound
|
||||
|
|
@ -305,15 +305,33 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
moveToRoot := "/" == targetPath
|
||||
toHP := path.Join("/", headingText)
|
||||
toFolder := "/"
|
||||
|
||||
if !moveToRoot {
|
||||
toBlock := treenode.GetBlockTreeRootByPath(targetBoxID, targetPath)
|
||||
if nil == toBlock {
|
||||
if "" != previousPath {
|
||||
previousDoc := treenode.GetBlockTreeRootByPath(targetBoxID, previousPath)
|
||||
if nil == previousDoc {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
toHP = path.Join(toBlock.HPath, headingText)
|
||||
toFolder = path.Join(path.Dir(targetPath), toBlock.ID)
|
||||
parentPath := path.Dir(previousPath)
|
||||
if "/" != parentPath {
|
||||
parentPath = strings.TrimSuffix(parentPath, "/") + ".sy"
|
||||
parentDoc := treenode.GetBlockTreeRootByPath(targetBoxID, parentPath)
|
||||
if nil == parentDoc {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
toHP = path.Join(parentDoc.HPath, headingText)
|
||||
toFolder = path.Join(path.Dir(parentPath), parentDoc.ID)
|
||||
}
|
||||
} else {
|
||||
if !moveToRoot {
|
||||
parentDoc := treenode.GetBlockTreeRootByPath(targetBoxID, targetPath)
|
||||
if nil == parentDoc {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
toHP = path.Join(parentDoc.HPath, headingText)
|
||||
toFolder = path.Join(path.Dir(targetPath), parentDoc.ID)
|
||||
}
|
||||
}
|
||||
|
||||
newTargetPath = path.Join(toFolder, srcHeadingID+".sy")
|
||||
|
|
@ -375,7 +393,11 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
newTree.Box, newTree.Path = targetBoxID, newTargetPath
|
||||
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
newTree.Root.Spec = "1"
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
if "" != previousPath {
|
||||
box.addSort(strings.TrimSuffix(path.Base(previousPath), ".sy"), newTree.ID)
|
||||
} else {
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
}
|
||||
if err = indexWriteTreeUpsertQueue(newTree); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue