From 305bd9dfb0bc9ecf9d08fc7556c7938e26a9446f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 6 Sep 2025 08:28:54 +0800 Subject: [PATCH] :art: Improve duplicating doc/av https://github.com/siyuan-note/siyuan/issues/15786 --- app/src/util/functions.ts | 4 ++++ kernel/model/attribute_view.go | 4 +++- kernel/model/tree.go | 7 +++++-- kernel/util/misc.go | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/util/functions.ts b/app/src/util/functions.ts index 69625368c..5dc9ab840 100644 --- a/app/src/util/functions.ts +++ b/app/src/util/functions.ts @@ -104,6 +104,10 @@ export const objEquals = (a: any, b: any): boolean => { }; export const duplicateNameAddOne = (name:string) => { + if (!name) { + return ""; + } + const nameMatch = name.match(/^(.*) \((\d+)\)$/); if (nameMatch) { name = `${nameMatch[1]} (${parseInt(nameMatch[2]) + 1})`; diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 1747d8250..c6d6ec5fd 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1094,7 +1094,9 @@ func DuplicateDatabaseBlock(avID string) (newAvID, newBlockID string, err error) return } - newAv.Name = oldAv.Name + " (Duplicated " + time.Now().Format("2006-01-02 15:04:05") + ")" + if "" != newAv.Name { + newAv.Name = oldAv.Name + " (Duplicated " + time.Now().Format("2006-01-02 15:04:05") + ")" + } for _, keyValues := range newAv.KeyValues { if nil != keyValues.Key.Relation && keyValues.Key.Relation.IsTwoWay { diff --git a/kernel/model/tree.go b/kernel/model/tree.go index 742538d03..cf2ee944e 100644 --- a/kernel/model/tree.go +++ b/kernel/model/tree.go @@ -43,7 +43,7 @@ import ( func resetTree(tree *parse.Tree, titleSuffix string, removeAvBinding bool) { tree.ID = ast.NewNodeID() tree.Root.ID = tree.ID - + title := tree.Root.IALAttr("title") if "" != titleSuffix { if t, parseErr := time.Parse("20060102150405", util.TimeFromID(tree.ID)); nil == parseErr { titleSuffix += " " + t.Format("2006-01-02 15:04:05") @@ -52,9 +52,12 @@ func resetTree(tree *parse.Tree, titleSuffix string, removeAvBinding bool) { } titleSuffix = "(" + titleSuffix + ")" titleSuffix = " " + titleSuffix + if Conf.language(16) == title { + titleSuffix = "" + } } tree.Root.SetIALAttr("id", tree.ID) - tree.Root.SetIALAttr("title", tree.Root.IALAttr("title")+titleSuffix) + tree.Root.SetIALAttr("title", title+titleSuffix) tree.Root.RemoveIALAttr("scroll") p := path.Join(path.Dir(tree.Path), tree.ID) + ".sy" tree.Path = p diff --git a/kernel/util/misc.go b/kernel/util/misc.go index c1708465e..870633ac5 100644 --- a/kernel/util/misc.go +++ b/kernel/util/misc.go @@ -34,6 +34,10 @@ func init() { } func GetDuplicateName(master string) (ret string) { + if "" == master { + return + } + ret = master + " (1)" r := regexp.MustCompile("^(.*) \\((\\d+)\\)$") m := r.FindStringSubmatch(master)