mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 标签名称存在包含关系时重命名标签会出现误修改 Fix https://github.com/siyuan-note/siyuan/issues/5816
This commit is contained in:
parent
8143c58cf5
commit
856b41b6c8
1 changed files with 5 additions and 8 deletions
|
|
@ -157,17 +157,14 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
|||
if ast.NodeDocument == node.Type {
|
||||
if docTagsVal := node.IALAttr("tags"); strings.Contains(docTagsVal, oldLabel) {
|
||||
docTags := strings.Split(docTagsVal, ",")
|
||||
if gulu.Str.Contains(newLabel, docTags) {
|
||||
continue
|
||||
}
|
||||
var tmp []string
|
||||
for i, docTag := range docTags {
|
||||
if !strings.Contains(docTag, oldLabel) {
|
||||
for _, docTag := range docTags {
|
||||
if docTag != oldLabel {
|
||||
tmp = append(tmp, docTag)
|
||||
continue
|
||||
}
|
||||
if newTag := strings.ReplaceAll(docTags[i], oldLabel, newLabel); !gulu.Str.Contains(newTag, tmp) {
|
||||
tmp = append(tmp, newTag)
|
||||
if !gulu.Str.Contains(newLabel, tmp) {
|
||||
tmp = append(tmp, newLabel)
|
||||
}
|
||||
}
|
||||
node.SetIALAttr("tags", strings.Join(tmp, ","))
|
||||
|
|
@ -179,7 +176,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
|||
for _, nodeTag := range nodeTags {
|
||||
nodeLabels := nodeTag.ChildrenByType(ast.NodeText)
|
||||
for _, nodeLabel := range nodeLabels {
|
||||
if bytes.Contains(nodeLabel.Tokens, []byte(oldLabel)) {
|
||||
if bytes.Equal(nodeLabel.Tokens, []byte(oldLabel)) {
|
||||
nodeLabel.Tokens = bytes.ReplaceAll(nodeLabel.Tokens, []byte(oldLabel), []byte(newLabel))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue