Kaynağa Gözat

:art: Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204

Daniel 1 yıl önce
ebeveyn
işleme
21aabc216d
1 değiştirilmiş dosya ile 17 ekleme ve 6 silme
  1. 17 6
      kernel/model/virutalref.go

+ 17 - 6
kernel/model/virutalref.go

@@ -56,15 +56,15 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
 			return ast.WalkContinue
 		})
 		content := buf.String()
-		ret = putBlockVirtualRefKeywords(content, root.ID, root.IALAttr("title"))
+		ret = putBlockVirtualRefKeywords(content, root)
 		return
 	}
 	ret = val.([]string)
 	return
 }
 
-func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []string) {
-	keywords := getVirtualRefKeywords(docTitle)
+func putBlockVirtualRefKeywords(blockContent string, root *ast.Node) (ret []string) {
+	keywords := getVirtualRefKeywords(root)
 	if 1 > len(keywords) {
 		return
 	}
@@ -94,7 +94,7 @@ func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []s
 	}
 
 	ret = gulu.Str.RemoveDuplicatedElem(ret)
-	virtualBlockRefCache.SetWithTTL(blockID, ret, 1, 10*time.Minute)
+	virtualBlockRefCache.SetWithTTL(root.ID, ret, 1, 10*time.Minute)
 	return
 }
 
@@ -174,7 +174,7 @@ func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeyword
 	return false
 }
 
-func getVirtualRefKeywords(docName string) (ret []string) {
+func getVirtualRefKeywords(root *ast.Node) (ret []string) {
 	if !Conf.Editor.VirtualBlockRef {
 		return
 	}
@@ -225,7 +225,18 @@ func getVirtualRefKeywords(docName string) (ret []string) {
 	}
 
 	// 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537
-	ret = gulu.Str.ExcludeElem(ret, []string{docName})
+	// Virtual references exclude the name and aliases from the current document https://github.com/siyuan-note/siyuan/issues/9204
+	title := root.IALAttr("title")
+	ret = gulu.Str.ExcludeElem(ret, []string{title})
+	if name := root.IALAttr("name"); "" != name {
+		ret = gulu.Str.ExcludeElem(ret, []string{name})
+	}
+	if alias := root.IALAttr("alias"); "" != alias {
+		for _, a := range strings.Split(alias, ",") {
+			ret = gulu.Str.ExcludeElem(ret, []string{a})
+		}
+	}
+
 	ret = prepareMarkKeywords(ret)
 	return
 }