🎨 Improve floating window backlink https://github.com/siyuan-note/siyuan/issues/13371
This commit is contained in:
parent
553891defb
commit
04a4a90721
4 changed files with 22 additions and 11 deletions
|
@ -412,7 +412,7 @@ func getRefIDs(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
refIDs, refTexts, defIDs := model.GetBlockRefs(id)
|
||||
refIDs, refTexts, defIDs := model.GetBlockRefs(id, true)
|
||||
ret.Data = map[string][]string{
|
||||
"refIDs": refIDs,
|
||||
"refTexts": refTexts,
|
||||
|
|
|
@ -91,6 +91,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
|
|||
}
|
||||
|
||||
ret.RefIDs, _ = sql.QueryRefIDsByDefID(blockID, false)
|
||||
buildBacklinkListItemRefs(&ret.RefIDs)
|
||||
ret.RefCount = len(ret.RefIDs) // 填充块引计数
|
||||
|
||||
// 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545
|
||||
|
@ -316,7 +317,7 @@ func getNodeRefText0(node *ast.Node, maxLen int) string {
|
|||
return ret
|
||||
}
|
||||
|
||||
func GetBlockRefs(defID string) (refIDs, refTexts, defIDs []string) {
|
||||
func GetBlockRefs(defID string, isBacklink bool) (refIDs, refTexts, defIDs []string) {
|
||||
refIDs = []string{}
|
||||
refTexts = []string{}
|
||||
defIDs = []string{}
|
||||
|
@ -332,6 +333,10 @@ func GetBlockRefs(defID string) (refIDs, refTexts, defIDs []string) {
|
|||
} else {
|
||||
defIDs = append(defIDs, defID)
|
||||
}
|
||||
|
||||
if isBacklink {
|
||||
buildBacklinkListItemRefs(&refIDs)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -548,3 +553,17 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bo
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func buildBacklinkListItemRefs(refIDs *[]string) {
|
||||
refBts := treenode.GetBlockTrees(*refIDs)
|
||||
for i, refID := range *refIDs {
|
||||
if bt := refBts[refID]; nil != bt {
|
||||
if "p" == bt.Type {
|
||||
if parent := treenode.GetBlockTree(bt.ParentID); nil != parent && "i" == parent.Type {
|
||||
// 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
|
||||
(*refIDs)[i] = parent.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -634,14 +634,6 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
|
|||
}
|
||||
}
|
||||
|
||||
if isBacklink { // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
|
||||
if ast.NodeParagraph == node.Type {
|
||||
if nil != node.Parent && ast.NodeListItem == node.Parent.Type {
|
||||
node = node.Parent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
located := false
|
||||
isDoc := ast.NodeDocument == node.Type
|
||||
isHeading := ast.NodeHeading == node.Type
|
||||
|
|
|
@ -157,7 +157,7 @@ func refreshRefCount(rootID, blockID string) {
|
|||
for _, count := range refCounts {
|
||||
rootRefCount += count
|
||||
}
|
||||
refIDs, _, _ := GetBlockRefs(blockID)
|
||||
refIDs, _, _ := GetBlockRefs(blockID, false)
|
||||
util.PushSetDefRefCount(rootID, blockID, refIDs, refCount, rootRefCount)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue