🎨 Backlink and backmention sort mode persistence (#16291)

fix https://github.com/siyuan-note/siyuan/issues/7764
This commit is contained in:
Jeffrey Chen 2025-11-06 09:33:20 +08:00 committed by GitHub
parent f45f2c7cdb
commit d14501178d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 15 deletions

View file

@ -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,
}

View file

@ -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{}