🎨 文档转换标题触发状态异常

This commit is contained in:
Liang Ding 2023-02-05 18:01:33 +08:00
parent a6ec16065a
commit f59add1e61
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D

View File

@ -26,6 +26,7 @@ import (
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
"github.com/88250/lute/parse" "github.com/88250/lute/parse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache" "github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/treenode"
@ -118,7 +119,9 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
return return
} }
os.Remove(subDir) // 移除空文件夹不会有副作用 if removeErr := os.Remove(subDir); nil != removeErr { // 移除空文件夹不会有副作用
logging.LogWarnf("remove empty dir [%s] failed: %s", subDir, removeErr)
}
} }
targetTree, _ := loadTreeByBlockID(targetID) targetTree, _ := loadTreeByBlockID(targetID)
@ -160,9 +163,9 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
tags := strings.Split(tagIAL, ",") tags := strings.Split(tagIAL, ",")
srcTree.Root.RemoveIALAttr("tags") srcTree.Root.RemoveIALAttr("tags")
heading := &ast.Node{ID: srcTree.Root.ID, Type: ast.NodeHeading, HeadingLevel: headingLevel, KramdownIAL: srcTree.Root.KramdownIAL} heading := &ast.Node{ID: srcTree.Root.ID, Type: ast.NodeHeading, HeadingLevel: headingLevel, KramdownIAL: srcTree.Root.KramdownIAL}
heading.SetIALAttr("updated", util.CurrentTimeSecondsStr())
heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(srcTree.Root.IALAttr("title"))}) heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(srcTree.Root.IALAttr("title"))})
heading.Box = targetTree.Box heading.Box, heading.Path = targetTree.Box, targetTree.Path
heading.Path = targetTree.Path
if "" != tagIAL && 0 < len(tags) { if "" != tagIAL && 0 < len(tags) {
// 带标签的文档块转换为标题块时将标签移动到标题块下方 https://github.com/siyuan-note/siyuan/issues/6550 // 带标签的文档块转换为标题块时将标签移动到标题块下方 https://github.com/siyuan-note/siyuan/issues/6550
@ -221,12 +224,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
contentPivot.Unlink() contentPivot.Unlink()
} }
srcTreeBox, srcTreePath = srcTree.Box, srcTree.Path srcTreeBox, srcTreePath = srcTree.Box, srcTree.Path // 返回旧的文档块位置,前端后续会删除旧的文档块
srcTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
if err = indexWriteJSONQueue(srcTree); nil != err {
return
}
targetTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr()) targetTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
err = indexWriteJSONQueue(targetTree) err = indexWriteJSONQueue(targetTree)
IncSync() IncSync()