mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +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
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue