An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Backlink and backmention sort mode persistence (#16291)
Jeffrey Chend14501178d54
diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex a1661420e2..554296ecd0 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -674,8 +674,8 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => {}item.element.querySelector('.block__icon[data-type="refresh"] svg').classList.add("fn__rotate");fetchPost("/api/ref/getBacklink2", {- sort: item.status[blockId] ? item.status[blockId].sort : "3",- mSort: item.status[blockId] ? item.status[blockId].mSort : "3",+ sort: item.status[blockId] ? item.status[blockId].sort.toString() : window.siyuan.config.editor.backlinkSort.toString(),+ mSort: item.status[blockId] ? item.status[blockId].mSort.toString() : window.siyuan.config.editor.backmentionSort.toString(),id: blockId || "",k: item.inputsElement[0].value,mk: item.inputsElement[1].value,diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.tsindex e1da971bfe..9775a4fb5d 100644--- a/app/src/layout/dock/Backlink.ts+++ b/app/src/layout/dock/Backlink.ts@@ -24,8 +24,8 @@ export class Backlink extends Model {public editors: Protyle[] = [];public status: {[key: string]: {- sort: string,- mSort: string,+ sort: number,+ mSort: number,scrollTop: number,mScrollTop: number,backlinkOpenIds: string[],@@ -80,6 +80,8 @@ export class Backlink extends Model {this.type = options.type;this.element = options.tab.panelElement;this.element.classList.add("fn__flex-column", "file-tree", "sy__backlink");+ const backlinkSort = window.siyuan.config.editor.backlinkSort;+ const backmentionSort = window.siyuan.config.editor.backmentionSort;this.element.innerHTML = `<div class="block__icons"><div class="block__logo"><svg class="block__logoicon"><use xlink:href="#iconLink"></use></svg>${window.siyuan.languages.backlinks}@@ -92,7 +94,7 @@ export class Backlink extends Model {<span class="fn__space"></span><span data-type="refresh" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href='#iconRefresh'></use></svg></span><span class="fn__space"></span>- <span data-type="sort" data-sort="3" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.sort}"><svg><use xlink:href='#iconSort'></use></svg></span>+ <span data-type="sort" data-sort="${backlinkSort}" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.sort}"><svg><use xlink:href='#iconSort'></use></svg></span><span class="fn__space"></span><span data-type="expand" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.expand}${updateHotkeyAfterTip(window.siyuan.config.keymap.editor.general.expand.custom)}"><svg><use xlink:href="#iconExpand"></use></svg>@@ -115,7 +117,7 @@ export class Backlink extends Model {<input class="b3-text-field search__label fn__none fn__size200" placeholder="${window.siyuan.languages.filterKeywordEnter}" /><span data-type="search" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.filter}"><svg><use xlink:href='#iconFilter'></use></svg></span><span class="fn__space"></span>- <span data-type="mSort" data-sort="3" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.sort}"><svg><use xlink:href='#iconSort'></use></svg></span>+ <span data-type="mSort" data-sort="${backmentionSort}" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.sort}"><svg><use xlink:href='#iconSort'></use></svg></span><span class="fn__space"></span><span data-type="mExpand" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.expand}"><svg><use xlink:href="#iconExpand"></use></svg>@@ -353,6 +355,14 @@ export class Backlink extends Model {private showSortMenu(type: string, sort: string) {const clickEvent = (currentSort: string) => {(type === "sort" ? this.tree : this.mTree).element.previousElementSibling.querySelector(`[data-type="${type}"]`).setAttribute("data-sort", currentSort);+ // 保存排序状态到配置+ const sortValue = parseInt(currentSort);+ if (type === "sort") {+ window.siyuan.config.editor.backlinkSort = sortValue;+ } else {+ window.siyuan.config.editor.backmentionSort = sortValue;+ }+ fetchPost("/api/setting/setEditor", window.siyuan.config.editor);this.searchBacklinks();};window.siyuan.menus.menu.remove();@@ -489,8 +499,8 @@ export class Backlink extends Model {}element.classList.add("fn__rotate");fetchPost("/api/ref/getBacklink2", {- sort: this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').getAttribute("data-sort"),- mSort: this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').getAttribute("data-sort"),+ sort: parseInt(this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').getAttribute("data-sort")).toString(),+ mSort: parseInt(this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').getAttribute("data-sort")).toString(),k: this.inputsElement[0].value,mk: this.inputsElement[1].value,id: this.blockId,@@ -504,8 +514,8 @@ export class Backlink extends Model {public saveStatus() {this.status[this.blockId] = {- sort: this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').getAttribute("data-sort"),- mSort: this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').getAttribute("data-sort"),+ sort: parseInt(this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').getAttribute("data-sort")),+ mSort: parseInt(this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').getAttribute("data-sort")),scrollTop: this.tree.element.scrollTop,mScrollTop: this.mTree.element.scrollTop,backlinkOpenIds: [],@@ -582,8 +592,8 @@ export class Backlink extends Model {if (!this.status[this.blockId]) {this.status[this.blockId] = {- sort: "3",- mSort: "3",+ sort: window.siyuan.config.editor.backlinkSort,+ mSort: window.siyuan.config.editor.backmentionSort,scrollTop: 0,mScrollTop: 0,backlinkOpenIds: [],@@ -653,8 +663,8 @@ export class Backlink extends Model {layoutElement.setAttribute("aria-label", window.siyuan.languages.down);layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");}- this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').setAttribute("data-sort", this.status[this.blockId].sort);- this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').setAttribute("data-sort", this.status[this.blockId].mSort);+ this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').setAttribute("data-sort", this.status[this.blockId].sort.toString());+ this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').setAttribute("data-sort", this.status[this.blockId].mSort.toString());setTimeout(() => {this.tree.element.scrollTop = this.status[this.blockId].scrollTop;diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex d071554b49..ba71065067 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -362,6 +362,14 @@ declare namespace Config {* Whether the backlink contains children*/backlinkContainChildren: boolean;+ /**+ * Backlink sort mode+ */+ backlinkSort: number;+ /**+ * Backmention sort mode+ */+ backmentionSort: number;/*** The maximum length of the dynamic anchor text for block references*/diff --git a/kernel/conf/editor.go b/kernel/conf/editor.goindex deda1cd2e1..b630eea91a 100644--- a/kernel/conf/editor.go+++ b/kernel/conf/editor.go@@ -52,6 +52,8 @@ type Editor struct {BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量BacklinkContainChildren bool `json:"backlinkContainChildren"` // 反向链接是否包含子块进行计算+ BacklinkSort *int `json:"backlinkSort"` // 反向链接排序方式+ BackmentionSort *int `json:"backmentionSort"` // 反链提及排序方式HeadingEmbedMode int `json:"headingEmbedMode"` // 标题嵌入块模式,0:显示标题与下方的块,1:仅显示标题,2:仅显示标题下方的块Markdown *util.Markdown `json:"markdown"` // Markdown 配置}@@ -89,6 +91,8 @@ func NewEditor() *Editor {BacklinkExpandCount: 8,BackmentionExpandCount: -1,BacklinkContainChildren: true,+ BacklinkSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),+ BackmentionSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),HeadingEmbedMode: 0,Markdown: util.MarkdownSettings,}diff --git a/kernel/model/conf.go b/kernel/model/conf.goindex 1043a69b75..2a29fdd7d4 100644--- a/kernel/model/conf.go+++ b/kernel/model/conf.go@@ -229,8 +229,17 @@ func InitConf() {Conf.Tag = conf.NewTag()}+ defaultEditor := conf.NewEditor()if nil == Conf.Editor {- Conf.Editor = conf.NewEditor()+ Conf.Editor = defaultEditor+ }+ // 新增字段的默认值+ // 使用指针类型来区分字段不存在(nil)和用户设置为 0(非 nil)+ if nil == Conf.Editor.BacklinkSort {+ Conf.Editor.BacklinkSort = defaultEditor.BacklinkSort+ }+ if nil == Conf.Editor.BackmentionSort {+ Conf.Editor.BackmentionSort = defaultEditor.BackmentionSort}if 1 > len(Conf.Editor.Emoji) {Conf.Editor.Emoji = []string{}