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

This commit is contained in:
Daniel 2024-11-22 22:36:19 +08:00
parent 8bc3186976
commit b6cd6930c7
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 121 additions and 19 deletions

View file

@ -2163,3 +2163,45 @@ func (box *Box) addMinSort(parentPath, id string) {
return
}
}
func (box *Box) addSort(previousID, 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)
return
}
confPath := filepath.Join(confDir, "sort.json")
fullSortIDs := map[string]int{}
var data []byte
if filelock.IsExist(confPath) {
data, err := filelock.ReadFile(confPath)
if err != nil {
logging.LogErrorf("read sort conf failed: %s", err)
return
}
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); err != nil {
logging.LogErrorf("unmarshal sort conf failed: %s", err)
}
}
sortVal := 0
previousSortVal, ok := fullSortIDs[previousID]
if !ok {
sortVal++
} else {
sortVal = previousSortVal + 1
}
fullSortIDs[id] = sortVal
data, err := gulu.JSON.MarshalJSON(fullSortIDs)
if err != nil {
logging.LogErrorf("marshal sort conf failed: %s", err)
return
}
if err = filelock.WriteFile(confPath, data); err != nil {
logging.LogErrorf("write sort conf failed: %s", err)
return
}
}