mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 调用 API setBlockAttrs 后推送 Transaction https://github.com/siyuan-note/siyuan/issues/5847
This commit is contained in:
parent
8f3dd9fbf4
commit
8811f329f9
1 changed files with 6 additions and 12 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute"
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
"github.com/88250/lute/lex"
|
"github.com/88250/lute/lex"
|
||||||
|
|
@ -106,8 +105,7 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
||||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||||
}
|
}
|
||||||
|
|
||||||
luteEngine := NewLute()
|
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
oldDom := lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
|
||||||
|
|
||||||
for name, _ := range nameValues {
|
for name, _ := range nameValues {
|
||||||
for i := 0; i < len(name); i++ {
|
for i := 0; i < len(name); i++ {
|
||||||
|
|
@ -131,21 +129,17 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
||||||
IncSync()
|
IncSync()
|
||||||
cache.PutBlockIAL(id, parse.IAL2Map(node.KramdownIAL))
|
cache.PutBlockIAL(id, parse.IAL2Map(node.KramdownIAL))
|
||||||
|
|
||||||
dom := lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
if oldDom == dom {
|
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: id}
|
||||||
return
|
|
||||||
}
|
|
||||||
doOp := &Operation{Action: "update", Data: dom, ID: id}
|
|
||||||
undoOp := &Operation{Action: "update", Data: oldDom, ID: id}
|
|
||||||
trans := []*Transaction{{
|
trans := []*Transaction{{
|
||||||
DoOperations: []*Operation{doOp},
|
DoOperations: []*Operation{doOp},
|
||||||
UndoOperations: []*Operation{undoOp},
|
UndoOperations: []*Operation{},
|
||||||
}}
|
}}
|
||||||
pushBroadcastTransactions(trans)
|
pushBroadcastAttrTransactions(trans)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func pushBroadcastTransactions(transactions []*Transaction) {
|
func pushBroadcastAttrTransactions(transactions []*Transaction) {
|
||||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast, util.PushModeBroadcast)
|
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast, util.PushModeBroadcast)
|
||||||
evt.Data = transactions
|
evt.Data = transactions
|
||||||
util.PushEvent(evt)
|
util.PushEvent(evt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue