From 2f302533668d10961bbb8abd9a5056d582fbaf32 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 11 Dec 2024 23:00:04 +0800 Subject: [PATCH] :art: Improve heading/li-doc converting https://github.com/siyuan-note/siyuan/issues/13225 --- kernel/model/heading.go | 7 +++++++ kernel/model/listitem.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/kernel/model/heading.go b/kernel/model/heading.go index 85219079d..f5ecd7ffa 100644 --- a/kernel/model/heading.go +++ b/kernel/model/heading.go @@ -22,6 +22,7 @@ import ( "path" "path/filepath" "strings" + "sync" "github.com/88250/gulu" "github.com/88250/lute/ast" @@ -117,12 +118,16 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) { return } +var docConvertLock = sync.Mutex{} + func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath string, err error) { if !ast.IsNodeIDPattern(srcID) || !ast.IsNodeIDPattern(targetID) { return } FlushTxQueue() + docConvertLock.Lock() + defer docConvertLock.Unlock() srcTree, _ := LoadTreeByBlockID(srcID) if nil == srcTree { @@ -277,6 +282,8 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (srcRootBlockID, newTargetPath string, err error) { FlushTxQueue() + docConvertLock.Lock() + defer docConvertLock.Unlock() srcTree, _ := LoadTreeByBlockID(srcHeadingID) if nil == srcTree { diff --git a/kernel/model/listitem.go b/kernel/model/listitem.go index e2f97b27b..8e2acb59e 100644 --- a/kernel/model/listitem.go +++ b/kernel/model/listitem.go @@ -29,6 +29,8 @@ import ( func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (srcRootBlockID, newTargetPath string, err error) { FlushTxQueue() + docConvertLock.Lock() + defer docConvertLock.Unlock() srcTree, _ := LoadTreeByBlockID(srcListItemID) if nil == srcTree {