mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 01:50:12 +01:00
🎨 插入块接口加入 nextID 参数 https://github.com/siyuan-note/siyuan/issues/6199
This commit is contained in:
parent
d15c7c5e4c
commit
2a4f533574
3 changed files with 33 additions and 5 deletions
|
|
@ -708,11 +708,15 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
if nil == block {
|
||||
block = treenode.GetBlockTree(operation.PreviousID)
|
||||
if nil == block {
|
||||
msg := fmt.Sprintf("not found previous block [id=%s]", operation.PreviousID)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.PreviousID}
|
||||
block = treenode.GetBlockTree(operation.NextID)
|
||||
}
|
||||
}
|
||||
if nil == block {
|
||||
msg := fmt.Sprintf("not found next block [id=%s]", operation.NextID)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.NextID}
|
||||
}
|
||||
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: block.ID}
|
||||
|
|
@ -780,8 +784,20 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
var node *ast.Node
|
||||
nextID := operation.NextID
|
||||
previousID := operation.PreviousID
|
||||
if "" != previousID {
|
||||
if "" != nextID {
|
||||
node = treenode.GetNodeInTree(tree, nextID)
|
||||
if nil == node {
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", nextID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: nextID}
|
||||
}
|
||||
|
||||
if ast.NodeList == insertedNode.Type && nil != node.Parent && ast.NodeList == node.Parent.Type {
|
||||
insertedNode = insertedNode.FirstChild
|
||||
}
|
||||
node.InsertBefore(insertedNode)
|
||||
} else if "" != previousID {
|
||||
node = treenode.GetNodeInTree(tree, previousID)
|
||||
if nil == node {
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
|
|
@ -973,6 +989,7 @@ type Operation struct {
|
|||
ID string `json:"id"`
|
||||
ParentID string `json:"parentID"`
|
||||
PreviousID string `json:"previousID"`
|
||||
NextID string `json:"nextID"`
|
||||
RetData interface{} `json:"retData"`
|
||||
|
||||
discard bool // 用于标识是否在事务合并中丢弃
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue