Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve dragging of headings or list items to the doc tree https://github.com/siyuan-note/siyuan/issues/13170

Daniel11640f777aef
diff --git a/kernel/model/file.go b/kernel/model/file.go
index e2ad3c25b2..34b23320ec 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -2175,7 +2175,7 @@ func (box *Box) addMinSort(parentPath, id string) {
}
}
-func (box *Box) addSort(previousID, id string) {
+func (box *Box) addSort(previousPath, id string) {
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
if err := os.MkdirAll(confDir, 0755); err != nil {
logging.LogErrorf("create conf dir failed: %s", err)
@@ -2196,17 +2196,25 @@ func (box *Box) addSort(previousID, id string) {
}
}
+ parentPath := path.Dir(previousPath)
+ docs, _, err := ListDocTree(box.ID, parentPath, util.SortModeUnassigned, false, false, Conf.FileTree.MaxListCount)
+ if err != nil {
+ logging.LogErrorf("list doc tree failed: %s", err)
+ return
+ }
+
+ previousID := util.GetTreeID(previousPath)
sortVal := 0
- previousSortVal, ok := fullSortIDs[previousID]
- if !ok {
+ for _, doc := range docs {
+ fullSortIDs[doc.ID] = sortVal
+ if doc.ID == previousID {
+ sortVal++
+ fullSortIDs[id] = sortVal
+ }
sortVal++
- } else {
- sortVal = previousSortVal + 1
}
- fullSortIDs[id] = sortVal
-
- data, err := gulu.JSON.MarshalJSON(fullSortIDs)
+ data, err = gulu.JSON.MarshalJSON(fullSortIDs)
if err != nil {
logging.LogErrorf("marshal sort conf failed: %s", err)
return
diff --git a/kernel/model/heading.go b/kernel/model/heading.go
index 5c4f8cdda1..f0675beabc 100644
--- a/kernel/model/heading.go
+++ b/kernel/model/heading.go
@@ -394,7 +394,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (sr
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
newTree.Root.Spec = "1"
if "" != previousPath {
- box.addSort(util.GetTreeID(previousPath), newTree.ID)
+ box.addSort(previousPath, newTree.ID)
} else {
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
}
diff --git a/kernel/model/listitem.go b/kernel/model/listitem.go
index 7cc87f34cd..5c23ed43d5 100644
--- a/kernel/model/listitem.go
+++ b/kernel/model/listitem.go
@@ -128,7 +128,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
newTree.Root.Spec = "1"
if "" != previousPath {
- box.addSort(util.GetTreeID(previousPath), newTree.ID)
+ box.addSort(previousPath, newTree.ID)
} else {
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
}