mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20: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 ast.NodeDocument == node.Type {
|
||||||
if docTagsVal := node.IALAttr("tags"); strings.Contains(docTagsVal, oldLabel) {
|
if docTagsVal := node.IALAttr("tags"); strings.Contains(docTagsVal, oldLabel) {
|
||||||
docTags := strings.Split(docTagsVal, ",")
|
docTags := strings.Split(docTagsVal, ",")
|
||||||
if gulu.Str.Contains(newLabel, docTags) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var tmp []string
|
var tmp []string
|
||||||
for i, docTag := range docTags {
|
for _, docTag := range docTags {
|
||||||
if !strings.Contains(docTag, oldLabel) {
|
if docTag != oldLabel {
|
||||||
tmp = append(tmp, docTag)
|
tmp = append(tmp, docTag)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if newTag := strings.ReplaceAll(docTags[i], oldLabel, newLabel); !gulu.Str.Contains(newTag, tmp) {
|
if !gulu.Str.Contains(newLabel, tmp) {
|
||||||
tmp = append(tmp, newTag)
|
tmp = append(tmp, newLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.SetIALAttr("tags", strings.Join(tmp, ","))
|
node.SetIALAttr("tags", strings.Join(tmp, ","))
|
||||||
|
|
@ -179,7 +176,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
||||||
for _, nodeTag := range nodeTags {
|
for _, nodeTag := range nodeTags {
|
||||||
nodeLabels := nodeTag.ChildrenByType(ast.NodeText)
|
nodeLabels := nodeTag.ChildrenByType(ast.NodeText)
|
||||||
for _, nodeLabel := range nodeLabels {
|
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))
|
nodeLabel.Tokens = bytes.ReplaceAll(nodeLabel.Tokens, []byte(oldLabel), []byte(newLabel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue