Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: Remove super block entry configuration migration https://github.com/siyuan-note/siyuan/issues/10906

Daniel8c9820350bd9
diff --git a/kernel/conf/appearance.go b/kernel/conf/appearance.go
index 02691a27c3..92d18348f1 100644
--- a/kernel/conf/appearance.go
+++ b/kernel/conf/appearance.go
@@ -16,11 +16,7 @@
package conf
-import (
- "strings"
-
- "github.com/siyuan-note/siyuan/kernel/util"
-)
+import "github.com/siyuan-note/siyuan/kernel/util"
type Appearance struct {
Mode int `json:"mode"` // 模式:0:明亮,1:暗黑
@@ -124,7 +120,6 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)
profiles = append(profiles, profile)
}
entryVisibility.Profiles = profiles
- migrateSuperBlockEntryVisibility(entryVisibility)
if entryVisibility.Active != EntryVisibilityProfileSimple && entryVisibility.Active != EntryVisibilityProfileFull &&
!profileIDs[entryVisibility.Active] {
entryVisibility.Active = fallback
@@ -136,65 +131,6 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)
return entryVisibility
}
-func migrateSuperBlockEntryVisibility(entryVisibility *EntryVisibility) {
- const oldPrefix = "gutter.single."
- const newPrefix = "gutter.single.superBlock."
- movedKeys := map[string]bool{
- "cancelSuperBlock": true,
- "turnIntoVLayout": true,
- "turnIntoHLayout": true,
- "superBlockAlignment": true,
- }
- for _, profile := range entryVisibility.Profiles {
- if nil == profile {
- continue
- }
- for path, visible := range profile.Entries {
- if !strings.HasPrefix(path, oldPrefix) {
- continue
- }
- suffix := strings.TrimPrefix(path, oldPrefix)
- if movedKeys[suffix] || strings.HasPrefix(suffix, "superBlockAlignment.") {
- profile.Entries[newPrefix+suffix] = visible
- delete(profile.Entries, path)
- }
- }
- if alignmentOrder, ok := profile.Orders[oldPrefix+"superBlockAlignment"]; ok {
- profile.Orders[newPrefix+"superBlockAlignment"] = alignmentOrder
- delete(profile.Orders, oldPrefix+"superBlockAlignment")
- }
- rootOrder, ok := profile.Orders["gutter.single"]
- if !ok {
- continue
- }
- migratedRootOrder := make([]string, 0, len(rootOrder))
- superBlockOrder := make([]string, 0, len(movedKeys))
- parentInserted := false
- for _, key := range rootOrder {
- if key == "superBlock" {
- if !parentInserted {
- migratedRootOrder = append(migratedRootOrder, key)
- parentInserted = true
- }
- continue
- }
- if !movedKeys[key] {
- migratedRootOrder = append(migratedRootOrder, key)
- continue
- }
- superBlockOrder = append(superBlockOrder, key)
- if !parentInserted {
- migratedRootOrder = append(migratedRootOrder, "superBlock")
- parentInserted = true
- }
- }
- profile.Orders["gutter.single"] = migratedRootOrder
- if len(superBlockOrder) > 0 {
- profile.Orders["gutter.single.superBlock"] = superBlockOrder
- }
- }
-}
-
type AppearanceTheme struct {
Name string `json:"name"` // daylight
Label string `json:"label"` // i18n display name
diff --git a/kernel/conf/appearance_test.go b/kernel/conf/appearance_test.go
index 43d1e7087f..cc3c10a47c 100644
--- a/kernel/conf/appearance_test.go
+++ b/kernel/conf/appearance_test.go
@@ -72,53 +72,3 @@ func TestNormalizeEntryVisibilityActiveCustomProfile(t *testing.T) {
t.Fatal("profile orders should be initialized")
}
}
-
-func TestNormalizeEntryVisibilityMigratesSuperBlockMenu(t *testing.T) {
- entryVisibility := NormalizeEntryVisibility(&EntryVisibility{
- Version: 2,
- Active: "custom",
- Profiles: []*EntryVisibilityProfile{{
- ID: "custom",
- Name: "Custom",
- Base: EntryVisibilityProfileFull,
- Entries: map[string]bool{
- "gutter.single.cancelSuperBlock": false,
- "gutter.single.superBlockAlignment.alignTop": false,
- "gutter.single.superBlockAlignment.useDefaultVerticalAlign": true,
- },
- Orders: map[string][]string{
- "gutter.single": {"copy", "turnIntoHLayout", "cancelSuperBlock", "delete"},
- "gutter.single.superBlockAlignment": {"alignBottom", "alignTop"},
- },
- }},
- }, EntryVisibilityProfileFull)
-
- profile := entryVisibility.Profiles[0]
- if _, ok := profile.Entries["gutter.single.cancelSuperBlock"]; ok {
- t.Fatal("old super block entry path should be removed")
- }
- if visible, ok := profile.Entries["gutter.single.superBlock.cancelSuperBlock"]; !ok || visible {
- t.Fatalf("unexpected migrated entries: %+v", profile.Entries)
- }
- if visible, ok := profile.Entries["gutter.single.superBlock.superBlockAlignment.alignTop"]; !ok || visible {
- t.Fatalf("unexpected migrated entries: %+v", profile.Entries)
- }
- if !profile.Entries["gutter.single.superBlock.superBlockAlignment.useDefaultVerticalAlign"] {
- t.Fatalf("unexpected migrated entries: %+v", profile.Entries)
- }
- rootOrder := profile.Orders["gutter.single"]
- if len(rootOrder) != 3 || rootOrder[0] != "copy" || rootOrder[1] != "superBlock" || rootOrder[2] != "delete" {
- t.Fatalf("unexpected migrated root order: %+v", rootOrder)
- }
- superBlockOrder := profile.Orders["gutter.single.superBlock"]
- if len(superBlockOrder) != 2 || superBlockOrder[0] != "turnIntoHLayout" || superBlockOrder[1] != "cancelSuperBlock" {
- t.Fatalf("unexpected migrated super block order: %+v", superBlockOrder)
- }
- if _, ok := profile.Orders["gutter.single.superBlockAlignment"]; ok {
- t.Fatal("old super block alignment order should be removed")
- }
- alignmentOrder := profile.Orders["gutter.single.superBlock.superBlockAlignment"]
- if len(alignmentOrder) != 2 || alignmentOrder[0] != "alignBottom" || alignmentOrder[1] != "alignTop" {
- t.Fatalf("unexpected migrated alignment order: %+v", alignmentOrder)
- }
-}