diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index a1661420e..554296ecd 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.ts
index e1da971bf..9775a4fb5 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 = `
${window.siyuan.languages.backlinks}
@@ -92,7 +94,7 @@ export class Backlink extends Model {
-
+
@@ -115,7 +117,7 @@ export class Backlink extends Model {
-
+
@@ -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.ts
index d071554b4..ba7106506 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.go
index deda1cd2e..b630eea91 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.go
index 1043a69b7..2a29fdd7d 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{}