mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 重命名父标签误修改子标签 https://github.com/siyuan-note/siyuan/issues/7498
This commit is contained in:
parent
ac3b54a538
commit
7c11b2ec9b
1 changed files with 5 additions and 7 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/emirpasic/gods/sets/hashset"
|
"github.com/emirpasic/gods/sets/hashset"
|
||||||
"github.com/facette/natsort"
|
"github.com/facette/natsort"
|
||||||
|
|
@ -155,12 +154,11 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
||||||
docTags := strings.Split(docTagsVal, ",")
|
docTags := strings.Split(docTagsVal, ",")
|
||||||
var tmp []string
|
var tmp []string
|
||||||
for _, docTag := range docTags {
|
for _, docTag := range docTags {
|
||||||
if docTag != oldLabel {
|
if strings.HasPrefix(docTag, oldLabel+"/") || docTag == oldLabel {
|
||||||
|
docTag = strings.Replace(docTag, oldLabel, newLabel, 1)
|
||||||
|
tmp = append(tmp, docTag)
|
||||||
|
} else {
|
||||||
tmp = append(tmp, docTag)
|
tmp = append(tmp, docTag)
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !gulu.Str.Contains(newLabel, tmp) {
|
|
||||||
tmp = append(tmp, newLabel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.SetIALAttr("tags", strings.Join(tmp, ","))
|
node.SetIALAttr("tags", strings.Join(tmp, ","))
|
||||||
|
|
@ -172,7 +170,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
||||||
for _, nodeTag := range nodeTags {
|
for _, nodeTag := range nodeTags {
|
||||||
if nodeTag.IsTextMarkType("tag") {
|
if nodeTag.IsTextMarkType("tag") {
|
||||||
if strings.HasPrefix(nodeTag.TextMarkTextContent, oldLabel+"/") || nodeTag.TextMarkTextContent == oldLabel {
|
if strings.HasPrefix(nodeTag.TextMarkTextContent, oldLabel+"/") || nodeTag.TextMarkTextContent == oldLabel {
|
||||||
nodeTag.TextMarkTextContent = strings.ReplaceAll(nodeTag.TextMarkTextContent, oldLabel, newLabel)
|
nodeTag.TextMarkTextContent = strings.Replace(nodeTag.TextMarkTextContent, oldLabel, newLabel, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue