mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-24 09:16:09 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
7c1f49e862
3 changed files with 47 additions and 0 deletions
|
|
@ -1777,3 +1777,48 @@ func (box *Box) removeSort(ids []string) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (box *Box) addMinSort(parentPath, id string) {
|
||||
docs, _, err := ListDocTree(box.ID, parentPath, util.SortModeUnassigned, false, false, 1)
|
||||
if nil != err {
|
||||
logging.LogErrorf("list doc tree failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
sortVal := 0
|
||||
if 0 < len(docs) {
|
||||
sortVal = docs[0].Sort - 1
|
||||
}
|
||||
|
||||
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
||||
if err = os.MkdirAll(confDir, 0755); nil != err {
|
||||
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 nil != err {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
fullSortIDs[id] = sortVal
|
||||
|
||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ 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 err = indexWriteJSONQueue(newTree); nil != err {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ func ListItem2Doc(srcListItemID, 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 err = indexWriteJSONQueue(newTree); nil != err {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue