Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
05e459a911
2 changed files with 22 additions and 11 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/lex"
|
||||
|
@ -105,6 +106,9 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
}
|
||||
|
||||
luteEngine := NewLute()
|
||||
oldDom := lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
|
||||
for name, _ := range nameValues {
|
||||
for i := 0; i < len(name); i++ {
|
||||
if !lex.IsASCIILetterNumHyphen(name[i]) {
|
||||
|
@ -126,9 +130,27 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
}
|
||||
IncSync()
|
||||
cache.PutBlockIAL(id, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
dom := lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
if oldDom == dom {
|
||||
return
|
||||
}
|
||||
doOp := &Operation{Action: "update", Data: dom, ID: id}
|
||||
undoOp := &Operation{Action: "update", Data: oldDom, ID: id}
|
||||
trans := []*Transaction{{
|
||||
DoOperations: []*Operation{doOp},
|
||||
UndoOperations: []*Operation{undoOp},
|
||||
}}
|
||||
pushBroadcastTransactions(trans)
|
||||
return
|
||||
}
|
||||
|
||||
func pushBroadcastTransactions(transactions []*Transaction) {
|
||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast, util.PushModeBroadcast)
|
||||
evt.Data = transactions
|
||||
util.PushEvent(evt)
|
||||
}
|
||||
|
||||
func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
|
|
|
@ -904,17 +904,6 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
treenode.MoveFoldHeading(updatedNode, oldNode)
|
||||
}
|
||||
|
||||
// 挂件移动或设置大小后属性丢失 https://github.com/siyuan-note/siyuan/issues/4885
|
||||
// 这里需要把旧节点的属性复制到新节点上,避免属性丢失
|
||||
oldIAL := parse.IAL2Map(oldNode.KramdownIAL)
|
||||
newIAL := parse.IAL2Map(updatedNode.KramdownIAL)
|
||||
for oldIALKey, oldIALVal := range oldIAL {
|
||||
if strings.HasPrefix(oldIALKey, "custom-") {
|
||||
newIAL[oldIALKey] = oldIALVal
|
||||
}
|
||||
}
|
||||
updatedNode.KramdownIAL = parse.Map2IAL(newIAL)
|
||||
|
||||
cache.PutBlockIAL(updatedNode.ID, parse.IAL2Map(updatedNode.KramdownIAL))
|
||||
|
||||
// 替换为新节点
|
||||
|
|
Loading…
Add table
Reference in a new issue