Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-01-11 12:22:59 +08:00
commit 58c257960b
8 changed files with 95 additions and 57 deletions

View File

@ -316,13 +316,18 @@ const bindProviderEvent = () => {
concurrentReqs = 16; concurrentReqs = 16;
} }
(providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString(); (providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString();
let endpoint = (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value;
endpoint = endpoint.trim().replace("http://http(s)://", "https://");
if (!endpoint.startsWith("http")) {
endpoint = "http://" + endpoint;
}
const s3 = { const s3 = {
endpoint: (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value, endpoint: endpoint,
accessKey: (providerPanelElement.querySelector("#accessKey") as HTMLInputElement).value, accessKey: (providerPanelElement.querySelector("#accessKey") as HTMLInputElement).value.trim(),
secretKey: (providerPanelElement.querySelector("#secretKey") as HTMLInputElement).value, secretKey: (providerPanelElement.querySelector("#secretKey") as HTMLInputElement).value.trim(),
bucket: (providerPanelElement.querySelector("#bucket") as HTMLInputElement).value, bucket: (providerPanelElement.querySelector("#bucket") as HTMLInputElement).value.trim(),
pathStyle: (providerPanelElement.querySelector("#pathStyle") as HTMLInputElement).value === "true", pathStyle: (providerPanelElement.querySelector("#pathStyle") as HTMLInputElement).value === "true",
region: (providerPanelElement.querySelector("#region") as HTMLInputElement).value, region: (providerPanelElement.querySelector("#region") as HTMLInputElement).value.trim(),
skipTlsVerify: (providerPanelElement.querySelector("#s3SkipTlsVerify") as HTMLInputElement).value === "true", skipTlsVerify: (providerPanelElement.querySelector("#s3SkipTlsVerify") as HTMLInputElement).value === "true",
timeout: timeout, timeout: timeout,
concurrentReqs: concurrentReqs, concurrentReqs: concurrentReqs,
@ -346,10 +351,15 @@ const bindProviderEvent = () => {
concurrentReqs = 16; concurrentReqs = 16;
} }
(providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString(); (providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString();
let endpoint = (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value;
endpoint = endpoint.trim().replace("http://http(s)://", "https://");
if (!endpoint.startsWith("http")) {
endpoint = "http://" + endpoint;
}
const webdav = { const webdav = {
endpoint: (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value, endpoint: endpoint,
username: (providerPanelElement.querySelector("#username") as HTMLInputElement).value, username: (providerPanelElement.querySelector("#username") as HTMLInputElement).value.trim(),
password: (providerPanelElement.querySelector("#password") as HTMLInputElement).value, password: (providerPanelElement.querySelector("#password") as HTMLInputElement).value.trim(),
skipTlsVerify: (providerPanelElement.querySelector("#webdavSkipTlsVerify") as HTMLInputElement).value === "true", skipTlsVerify: (providerPanelElement.querySelector("#webdavSkipTlsVerify") as HTMLInputElement).value === "true",
timeout: timeout, timeout: timeout,
concurrentReqs: concurrentReqs, concurrentReqs: concurrentReqs,

View File

@ -438,11 +438,12 @@ func getRefIDs(c *gin.Context) {
} }
id := arg["id"].(string) id := arg["id"].(string)
refIDs, refTexts, defIDs := model.GetBlockRefs(id, true) refIDs, refTexts, defIDs, originalRefBlockIDs := model.GetBlockRefs(id, true)
ret.Data = map[string][]string{ ret.Data = map[string]any{
"refIDs": refIDs, "refIDs": refIDs,
"refTexts": refTexts, "refTexts": refTexts,
"defIDs": defIDs, "defIDs": defIDs,
"originalRefBlockIDs": originalRefBlockIDs,
} }
} }

View File

@ -78,7 +78,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highli
refs := sql.QueryRefsByDefID(defID, containChildren) refs := sql.QueryRefsByDefID(defID, containChildren)
refs = removeDuplicatedRefs(refs) refs = removeDuplicatedRefs(refs)
linkRefs, _, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keywords) linkRefs, _, excludeBacklinkIDs, originalRefBlockIDs := buildLinkRefs(rootID, refs, keywords)
tmpMentions, mentionKeywords := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen) tmpMentions, mentionKeywords := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen)
luteEngine := util.NewLute() luteEngine := util.NewLute()
var mentions []*Block var mentions []*Block
@ -106,7 +106,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highli
var refTree *parse.Tree var refTree *parse.Tree
trees := filesys.LoadTrees(mentionBlockIDs) trees := filesys.LoadTrees(mentionBlockIDs)
for id, tree := range trees { for id, tree := range trees {
backlink := buildBacklink(id, tree, mentionKeywords, highlight, luteEngine) backlink := buildBacklink(id, tree, originalRefBlockIDs, mentionKeywords, highlight, luteEngine)
if nil != backlink { if nil != backlink {
ret = append(ret, backlink) ret = append(ret, backlink)
} }
@ -148,7 +148,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight
} }
refs = removeDuplicatedRefs(refs) refs = removeDuplicatedRefs(refs)
linkRefs, _, _ := buildLinkRefs(rootID, refs, keywords) linkRefs, _, _, originalRefBlockIDs := buildLinkRefs(rootID, refs, keywords)
refTree, err := LoadTreeByBlockID(refTreeID) refTree, err := LoadTreeByBlockID(refTreeID)
if err != nil { if err != nil {
logging.LogWarnf("load ref tree [%s] failed: %s", refTreeID, err) logging.LogWarnf("load ref tree [%s] failed: %s", refTreeID, err)
@ -157,7 +157,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight
luteEngine := util.NewLute() luteEngine := util.NewLute()
for _, linkRef := range linkRefs { for _, linkRef := range linkRefs {
backlink := buildBacklink(linkRef.ID, refTree, keywords, highlight, luteEngine) backlink := buildBacklink(linkRef.ID, refTree, originalRefBlockIDs, keywords, highlight, luteEngine)
if nil != backlink { if nil != backlink {
ret = append(ret, backlink) ret = append(ret, backlink)
} }
@ -198,13 +198,13 @@ func sortBacklinks(backlinks []*Backlink, tree *parse.Tree) {
}) })
} }
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlight bool, luteEngine *lute.Lute) (ret *Backlink) { func buildBacklink(refID string, refTree *parse.Tree, originalRefBlockIDs map[string]string, keywords []string, highlight bool, luteEngine *lute.Lute) (ret *Backlink) {
node := treenode.GetNodeInTree(refTree, refID) node := treenode.GetNodeInTree(refTree, refID)
if nil == node { if nil == node {
return return
} }
renderNodes, expand := getBacklinkRenderNodes(node) renderNodes, expand := getBacklinkRenderNodes(node, originalRefBlockIDs)
if highlight && 0 < len(keywords) { if highlight && 0 < len(keywords) {
for _, renderNode := range renderNodes { for _, renderNode := range renderNodes {
@ -244,7 +244,7 @@ func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlig
return return
} }
func getBacklinkRenderNodes(n *ast.Node) (ret []*ast.Node, expand bool) { func getBacklinkRenderNodes(n *ast.Node, originalRefBlockIDs map[string]string) (ret []*ast.Node, expand bool) {
expand = true expand = true
if ast.NodeListItem == n.Type { if ast.NodeListItem == n.Type {
if nil == n.FirstChild { if nil == n.FirstChild {
@ -257,13 +257,19 @@ func getBacklinkRenderNodes(n *ast.Node) (ret []*ast.Node, expand bool) {
} }
if c != n.LastChild { // 存在子列表 if c != n.LastChild { // 存在子列表
for liFirstBlockSpan := c.FirstChild; nil != liFirstBlockSpan; liFirstBlockSpan = liFirstBlockSpan.Next { for ; nil != c; c = c.Next {
if treenode.IsBlockRef(liFirstBlockSpan) { if originalRefBlockIDs[n.ID] != c.ID {
continue continue
} }
if "" != strings.TrimSpace(liFirstBlockSpan.Text()) {
expand = false for liFirstBlockSpan := c.FirstChild; nil != liFirstBlockSpan; liFirstBlockSpan = liFirstBlockSpan.Next {
break if treenode.IsBlockRef(liFirstBlockSpan) {
continue
}
if "" != strings.TrimSpace(liFirstBlockSpan.Text()) {
expand = false
break
}
} }
} }
} }
@ -313,7 +319,7 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
refs := sql.QueryRefsByDefID(id, containChildren) refs := sql.QueryRefsByDefID(id, containChildren)
refs = removeDuplicatedRefs(refs) refs = removeDuplicatedRefs(refs)
linkRefs, linkRefsCount, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keywords) linkRefs, linkRefsCount, excludeBacklinkIDs, _ := buildLinkRefs(rootID, refs, keywords)
tmpBacklinks := toFlatTree(linkRefs, 0, "backlink", nil) tmpBacklinks := toFlatTree(linkRefs, 0, "backlink", nil)
for _, l := range tmpBacklinks { for _, l := range tmpBacklinks {
l.Blocks = nil l.Blocks = nil
@ -509,7 +515,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild
return return
} }
func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []*Block, refsCount int, excludeBacklinkIDs *hashset.Set) { func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []*Block, refsCount int, excludeBacklinkIDs *hashset.Set, originalRefBlockIDs map[string]string) {
// 为了减少查询,组装好 IDs 后一次查出 // 为了减少查询,组装好 IDs 后一次查出
defSQLBlockIDs, refSQLBlockIDs := map[string]bool{}, map[string]bool{} defSQLBlockIDs, refSQLBlockIDs := map[string]bool{}, map[string]bool{}
var queryBlockIDs []string var queryBlockIDs []string
@ -582,19 +588,18 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
sqlParagraphParents := sql.GetBlocks(paragraphParentIDs) sqlParagraphParents := sql.GetBlocks(paragraphParentIDs)
paragraphParents := fromSQLBlocks(&sqlParagraphParents, "", 12) paragraphParents := fromSQLBlocks(&sqlParagraphParents, "", 12)
originalRefBlockIDs = map[string]string{}
processedParagraphs := hashset.New() processedParagraphs := hashset.New()
for _, p := range paragraphParents { for _, parent := range paragraphParents {
// 改进标题下方块和列表项子块引用时的反链定位 https://github.com/siyuan-note/siyuan/issues/7484 if "NodeListItem" == parent.Type || "NodeBlockquote" == parent.Type || "NodeSuperBlock" == parent.Type {
if "NodeListItem" == p.Type { if refBlock := parentRefParagraphs[parent.ID]; nil != refBlock {
refBlock := parentRefParagraphs[p.ID] processedParagraphs.Add(parent.ID)
if nil != refBlock && p.FContent == refBlock.Content { // 使用内容判断是否是列表项下第一个子块 originalRefBlockIDs[parent.ID] = refBlock.ID
// 如果是列表项下第一个子块,则后续会通过列表项传递或关联处理,所以这里就不处理这个段落了 if !matchBacklinkKeyword(parent, keywords) {
processedParagraphs.Add(p.ID)
if !matchBacklinkKeyword(p, keywords) {
refsCount-- refsCount--
continue continue
} }
ret = append(ret, p) ret = append(ret, parent)
} }
} }
} }

View File

@ -91,7 +91,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
} }
ret.RefIDs, _ = sql.QueryRefIDsByDefID(blockID, Conf.Editor.BacklinkContainChildren) ret.RefIDs, _ = sql.QueryRefIDsByDefID(blockID, Conf.Editor.BacklinkContainChildren)
buildBacklinkListItemRefs(&ret.RefIDs) buildBacklinkListItemRefs(&ret.RefIDs, &map[string]string{})
ret.RefCount = len(ret.RefIDs) // 填充块引计数 ret.RefCount = len(ret.RefIDs) // 填充块引计数
// 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545 // 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545
@ -320,10 +320,11 @@ func getNodeRefText0(node *ast.Node, maxLen int, removeLineBreak bool) string {
return ret return ret
} }
func GetBlockRefs(defID string, isBacklink bool) (refIDs, refTexts, defIDs []string) { func GetBlockRefs(defID string, isBacklink bool) (refIDs, refTexts, defIDs []string, originalRefIDs map[string]string) {
refIDs = []string{} refIDs = []string{}
refTexts = []string{} refTexts = []string{}
defIDs = []string{} defIDs = []string{}
originalRefIDs = map[string]string{}
bt := treenode.GetBlockTree(defID) bt := treenode.GetBlockTree(defID)
if nil == bt { if nil == bt {
return return
@ -338,7 +339,7 @@ func GetBlockRefs(defID string, isBacklink bool) (refIDs, refTexts, defIDs []str
} }
if isBacklink { if isBacklink {
buildBacklinkListItemRefs(&refIDs) buildBacklinkListItemRefs(&refIDs, &originalRefIDs)
} }
return return
} }
@ -557,16 +558,19 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bo
return return
} }
func buildBacklinkListItemRefs(refIDs *[]string) { func buildBacklinkListItemRefs(refIDs *[]string, originalRefIDs *map[string]string) {
refBts := treenode.GetBlockTrees(*refIDs) refBts := treenode.GetBlockTrees(*refIDs)
for i, refID := range *refIDs { for i, refID := range *refIDs {
if bt := refBts[refID]; nil != bt { bt := refBts[refID]
if "p" == bt.Type { if nil == bt || "p" != bt.Type {
if parent := treenode.GetBlockTree(bt.ParentID); nil != parent && "i" == parent.Type { continue
// 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853 }
(*refIDs)[i] = parent.ID
} if parent := treenode.GetBlockTree(bt.ParentID); nil != parent &&
} ("i" == parent.Type || "b" == parent.Type || "s" == parent.Type) {
// 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
(*refIDs)[i] = parent.ID
(*originalRefIDs)[parent.ID] = refID
} }
} }
} }

View File

@ -603,7 +603,9 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
var nodes []*ast.Node var nodes []*ast.Node
if isBacklink { if isBacklink {
// 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853 // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
nodes, isBacklinkExpand = getBacklinkRenderNodes(node) originalRefBlockIDs := map[string]string{}
// TODO 需要增加参数,使用 getRefIDs 返回的 originalRefBlockIDs 增加这个参数后才能支持计数浮窗内计算折叠状态 https://github.com/siyuan-note/siyuan/issues/13776
nodes, isBacklinkExpand = getBacklinkRenderNodes(node, originalRefBlockIDs)
} else { } else {
// 如果同时存在 startID 和 endID并且是动态加载的情况则只加载 startID 和 endID 之间的块 [startID, endID] // 如果同时存在 startID 和 endID并且是动态加载的情况则只加载 startID 和 endID 之间的块 [startID, endID]
if "" != startID && "" != endID && scroll { if "" != startID && "" != endID && scroll {

View File

@ -17,9 +17,6 @@
package model package model
import ( import (
"github.com/88250/lute"
"github.com/88250/lute/render"
"github.com/siyuan-note/siyuan/kernel/filesys"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -28,10 +25,13 @@ import (
"github.com/88250/go-humanize" "github.com/88250/go-humanize"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
"github.com/88250/lute/parse" "github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/emirpasic/gods/sets/hashset" "github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/siyuan/kernel/av" "github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/task" "github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/treenode"
@ -157,7 +157,7 @@ func refreshRefCount(rootID, blockID string) {
for _, count := range refCounts { for _, count := range refCounts {
rootRefCount += count rootRefCount += count
} }
refIDs, _, _ := GetBlockRefs(blockID, false) refIDs, _, _, _ := GetBlockRefs(blockID, false)
util.PushSetDefRefCount(rootID, blockID, refIDs, refCount, rootRefCount) util.PushSetDefRefCount(rootID, blockID, refIDs, refCount, rootRefCount)
} }
@ -238,6 +238,15 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
} }
// 2. 更新属性视图主键内容 // 2. 更新属性视图主键内容
updateAttributeViewBlockText(updatedDefNodes)
// 3. 保存变更
for _, tree := range changedRefTree {
indexWriteTreeUpsertQueue(tree)
}
}
func updateAttributeViewBlockText(updatedDefNodes map[string]*ast.Node) {
var parents []*ast.Node var parents []*ast.Node
for _, updatedDefNode := range updatedDefNodes { for _, updatedDefNode := range updatedDefNodes {
for parent := updatedDefNode.Parent; nil != parent && ast.NodeDocument != parent.Type; parent = parent.Parent { for parent := updatedDefNode.Parent; nil != parent && ast.NodeDocument != parent.Type; parent = parent.Parent {
@ -287,11 +296,6 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
} }
} }
} }
// 3. 保存变更
for _, tree := range changedRefTree {
indexWriteTreeUpsertQueue(tree)
}
} }
// ReloadAttrView 用于重新加载属性视图。 // ReloadAttrView 用于重新加载属性视图。

View File

@ -536,6 +536,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
luteEngine := util.NewLute() luteEngine := util.NewLute()
var reloadTreeIDs []string var reloadTreeIDs []string
updateNodes := map[string]*ast.Node{}
for i, id := range ids { for i, id := range ids {
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
if nil == bt { if nil == bt {
@ -863,6 +864,8 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
} }
} }
updateNodes[id] = node
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(206), i+1, len(ids))) util.PushEndlessProgress(fmt.Sprintf(Conf.Language(206), i+1, len(ids)))
} }
@ -880,6 +883,8 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
refreshProtyle(id) refreshProtyle(id)
} }
updateAttributeViewBlockText(updateNodes)
sql.FlushQueue() sql.FlushQueue()
util.PushClearProgress() util.PushClearProgress()
return return

View File

@ -495,6 +495,13 @@ func SetSyncProviderLocal(local *conf.Local) (err error) {
return return
} }
if util.IsSubPath(absPath, util.WorkspaceDir) {
msg := fmt.Sprintf("endpoint [%s] is parent of workspace", local.Endpoint)
logging.LogErrorf(msg)
err = errors.New(fmt.Sprintf(Conf.Language(77), msg))
return
}
local.Timeout = util.NormalizeTimeout(local.Timeout) local.Timeout = util.NormalizeTimeout(local.Timeout)
local.ConcurrentReqs = util.NormalizeConcurrentReqs(local.ConcurrentReqs, conf.ProviderLocal) local.ConcurrentReqs = util.NormalizeConcurrentReqs(local.ConcurrentReqs, conf.ProviderLocal)