Skip to content

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

:art: Improve WYSIWYG and export preview mode switching https://github.com/siyuan-note/siyuan/issues/19060

Daniel3360b7f18437
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
index 71ffe2d60d..488623ba59 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
@@ -7,7 +7,7 @@
"id": "20200924100950-9op5xi1",
"title": "Shortcuts",
"type": "doc",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3987,7 +3987,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210106154056-koo4wdj",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -4006,7 +4006,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210106154319-v9tt3e2",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -4026,7 +4026,7 @@
"Properties": {
"colgroup": "||",
"id": "20240112150534-wiik5sl",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -6080,73 +6080,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "Switch to Instant Rendering mode"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "​"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Ctrl"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Alt"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "7"
- },
- {
- "Type": "NodeText",
- "Data": " / "
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "⌥⌘7"
- },
- {
- "Type": "NodeText",
- "Data": "​"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td"
- }
- ]
- },
- {
- "Type": "NodeTableRow",
- "Data": "tr",
- "Children": [
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "Switch to Preview mode"
+ "Data": "Toggle WYSIWYG and Export Preview modes"
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
index 04477d7812..d27136df19 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
@@ -7,7 +7,7 @@
"id": "20200813004551-gm0pbn1",
"title": "快捷键",
"type": "doc",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3985,7 +3985,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20201227133317-rkh4bji",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -4000,7 +4000,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20201227133317-kazyttz",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -4024,7 +4024,7 @@
"Properties": {
"colgroup": "||",
"id": "20201227133317-vopotjc",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -6036,73 +6036,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "切换为编辑模式"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "​"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Ctrl"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Alt"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "7"
- },
- {
- "Type": "NodeText",
- "Data": " / "
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "⌥⌘7"
- },
- {
- "Type": "NodeText",
- "Data": "​"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td"
- }
- ]
- },
- {
- "Type": "NodeTableRow",
- "Data": "tr",
- "Children": [
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "切换为预览模式"
+ "Data": "切换所见即所得和导出预览模式"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
index 43ed7c67f4..e46783334b 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
@@ -7,7 +7,7 @@
"id": "20211226122549-jktxego",
"title": "快捷鍵",
"type": "doc",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3979,7 +3979,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122652-htptsmh",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3994,7 +3994,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20211226122652-xp1hi60",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -4014,7 +4014,7 @@
"Properties": {
"colgroup": "||",
"id": "20240112151141-ggglv0f",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -6049,73 +6049,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "切換為編輯模式"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "​"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Ctrl"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Alt"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "7"
- },
- {
- "Type": "NodeText",
- "Data": " / "
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "⌥⌘7"
- },
- {
- "Type": "NodeText",
- "Data": "​"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td"
- }
- ]
- },
- {
- "Type": "NodeTableRow",
- "Data": "tr",
- "Children": [
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "切換為預覽模式"
+ "Data": "切換所見即所得和匯出預覽模式"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
index dafeabdba7..bfdf6dce7b 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
@@ -9,7 +9,7 @@
"id": "20240530101000-xsbxokr",
"title": "ショートカット",
"type": "doc",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3949,7 +3949,7 @@
"Properties": {
"ID": "20240530101000-twmuxke",
"id": "20240530101000-675gu9g",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3975,7 +3975,7 @@
"Properties": {
"ID": "20240530101000-tkbdrth",
"id": "20240530101000-9wkmh8w",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -3995,7 +3995,7 @@
"Properties": {
"colgroup": "||",
"id": "20240530101000-1isfzez",
- "updated": "20260830213256"
+ "updated": "20260902224242"
},
"Children": [
{
@@ -6071,73 +6071,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "編集モードに切り替え"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "​"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Ctrl"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "Alt"
- },
- {
- "Type": "NodeText",
- "Data": "​+"
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "7"
- },
- {
- "Type": "NodeText",
- "Data": " / "
- },
- {
- "Type": "NodeTextMark",
- "TextMarkType": "kbd",
- "TextMarkTextContent": "⌥⌘7"
- },
- {
- "Type": "NodeText",
- "Data": "​"
- }
- ]
- },
- {
- "Type": "NodeTableCell",
- "Data": "td"
- }
- ]
- },
- {
- "Type": "NodeTableRow",
- "Data": "tr",
- "Children": [
- {
- "Type": "NodeTableCell",
- "Data": "td",
- "Children": [
- {
- "Type": "NodeText",
- "Data": "プレビューモードに切り替え"
+ "Data": "WYSIWYG モードとプレビューモードを切り替える"
}
]
},
diff --git a/app/src/boot/globalEvent/commonHotkey.ts b/app/src/boot/globalEvent/commonHotkey.ts
index 8c34af16c1..8203a4a534 100644
--- a/app/src/boot/globalEvent/commonHotkey.ts
+++ b/app/src/boot/globalEvent/commonHotkey.ts
@@ -8,6 +8,7 @@ import type {App} from "../../index";
import {isMac, isNotCtrl, isOnlyMeta} from "../../protyle/util/compatibility";
import {showPopover} from "../../block/popover";
import {clearDisallowedKeymapItems} from "../../util/hotKeyPolicy";
+import {migrateEditModeKeymap} from "../../util/keymapMigration";
const matchKeymap = (keymap: Config.IKeys, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
if (key1 === "general") {
@@ -124,6 +125,11 @@ export const correctHotkey = (app: App) => {
Constants.SIYUAN_KEYMAP.editor.general.selectToPageEnd.custom =
Constants.SIYUAN_KEYMAP.editor.general.selectToPageEnd.default = "⇧⌘End";
}
+ const editorGeneralKeymap = window.siyuan.config.keymap?.editor?.general as unknown as
+ Record<string, Config.IKey | undefined> | undefined;
+ if (editorGeneralKeymap) {
+ migrateEditModeKeymap(editorGeneralKeymap, Constants.SIYUAN_KEYMAP.editor.general["edit-mode"].default);
+ }
const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general");
const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general");
const matchKeymap3 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.insert, "editor", "insert");
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index ab5ef14a95..acab099fa9 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -20,7 +20,7 @@ import {getInstanceById, saveLayout} from "../../layout/util";
import {getActiveTab, getDockByType, switchTabByIndex} from "../../layout/tabUtil";
import {Tab} from "../../layout/Tab";
import {Editor} from "../../editor";
-import {setEditMode} from "../../protyle/util/setEditMode";
+import {toggleEditMode} from "../../protyle/util/toggleEditMode";
import {rename} from "../../editor/rename";
import {Files} from "../../layout/dock/Files";
import {newDailyNote} from "../../util/mount";
@@ -528,15 +528,9 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.preview.custom, event)) {
- setEditMode(protyle, "preview");
- saveLayout();
- event.preventDefault();
- return true;
- }
- if (matchHotKey(window.siyuan.config.keymap.editor.general.wysiwyg.custom, event) && !protyle.options.backlinkData) {
- setEditMode(protyle, "wysiwyg");
- reloadProtyle(protyle, true);
+ if (!event.repeat && !protyle.options.backlinkData &&
+ matchHotKey(window.siyuan.config.keymap.editor.general["edit-mode"].custom, event)) {
+ toggleEditMode(protyle);
saveLayout();
event.preventDefault();
return true;
diff --git a/app/src/config/entryVisibility/catalog.test.ts b/app/src/config/entryVisibility/catalog.test.ts
index 85daf5f3f7..9429c20119 100644
--- a/app/src/config/entryVisibility/catalog.test.ts
+++ b/app/src/config/entryVisibility/catalog.test.ts
@@ -544,6 +544,13 @@ test("document loading actions follow the document menu order", () => {
assert.equal(children[loadAllIndex + 2]?.key, "separator_1");
});
+test("document mode switch is a direct configurable entry", () => {
+ const editMode = getEntryCatalogNode("document.more.editMode");
+ assert.equal(editMode?.type, "entry");
+ assert.equal(editMode?.simple, true);
+ assert.equal(editMode?.children, undefined);
+});
+
test("multiple document and notebook entries follow their document tree menus", () => {
assert.deepEqual(getEntryCatalogChildren("docTree.panel").map((item) => item.key), [
"newNotebook",
diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.ts
index ad11370a43..6291f69202 100644
--- a/app/src/config/entryVisibility/catalog.ts
+++ b/app/src/config/entryVisibility/catalog.ts
@@ -696,10 +696,7 @@ export const entryCatalog: IEntryCatalogSection[] = [
node("refresh", lang("refresh")),
node("optimizeTypography", lang("optimizeTypography")),
node("fullscreen", lang("fullscreen")),
- node("editMode", lang("edit-mode"), true, [
- node("wysiwyg", lang("wysiwyg")),
- node("preview", lang("preview")),
- ]),
+ node("editMode", lang("edit-mode")),
node("editReadonly", lang("editReadonly"), false, [
node("enable", lang("enable"), false),
node("disable", lang("disable"), false),
diff --git a/app/src/config/entryVisibility/profile.test.ts b/app/src/config/entryVisibility/profile.test.ts
index 3e0f73c9c3..73e1305e4c 100644
--- a/app/src/config/entryVisibility/profile.test.ts
+++ b/app/src/config/entryVisibility/profile.test.ts
@@ -17,11 +17,12 @@ test("custom entry visibility shows missing entries", () => {
assert.equal(getProfileEntryVisibility(undefined, "new-entry"), true);
});
-test("entry visibility import supports versions 1, 2, and 3", () => {
- assert.equal(isEntryVisibilityImportVersionSupported(1, 3), true);
- assert.equal(isEntryVisibilityImportVersionSupported(2, 3), true);
- assert.equal(isEntryVisibilityImportVersionSupported(3, 3), true);
- assert.equal(isEntryVisibilityImportVersionSupported(4, 3), false);
+test("entry visibility import supports versions 1 through 4", () => {
+ assert.equal(isEntryVisibilityImportVersionSupported(1, 4), true);
+ assert.equal(isEntryVisibilityImportVersionSupported(2, 4), true);
+ assert.equal(isEntryVisibilityImportVersionSupported(3, 4), true);
+ assert.equal(isEntryVisibilityImportVersionSupported(4, 4), true);
+ assert.equal(isEntryVisibilityImportVersionSupported(5, 4), false);
});
test("legacy entry visibility imports require base without persisting it", () => {
@@ -47,7 +48,7 @@ test("current entry visibility imports do not require base", () => {
assert.deepEqual(normalizeEntryVisibilityImportProfile({
name: "Current",
entries: {},
- }, 3, defaultOrders), {
+ }, 4, defaultOrders), {
name: "Current",
entries: {},
orders: defaultOrders,
@@ -66,3 +67,36 @@ test("version 1 entry visibility imports use default orders", () => {
orders: defaultOrders,
});
});
+
+test("version 3 entry visibility imports migrate the edit mode submenu", () => {
+ assert.deepEqual(normalizeEntryVisibilityImportProfile({
+ name: "Legacy edit mode",
+ entries: {
+ "document.more.editMode": true,
+ "document.more.editMode.wysiwyg": false,
+ "document.more.editMode.preview": false,
+ },
+ orders: {
+ "document.more.editMode": ["preview", "wysiwyg"],
+ },
+ }, 3, {}), {
+ name: "Legacy edit mode",
+ entries: {"document.more.editMode": false},
+ orders: {},
+ });
+});
+
+test("version 3 entry visibility imports keep the merged mode entry when a legacy child is visible", () => {
+ assert.deepEqual(normalizeEntryVisibilityImportProfile({
+ name: "Partially visible edit mode",
+ entries: {
+ "document.more.editMode": true,
+ "document.more.editMode.wysiwyg": false,
+ "document.more.editMode.preview": true,
+ },
+ }, 3, {}), {
+ name: "Partially visible edit mode",
+ entries: {"document.more.editMode": true},
+ orders: {},
+ });
+});
diff --git a/app/src/config/entryVisibility/profile.ts b/app/src/config/entryVisibility/profile.ts
index 06c609a589..365ce00b52 100644
--- a/app/src/config/entryVisibility/profile.ts
+++ b/app/src/config/entryVisibility/profile.ts
@@ -36,6 +36,15 @@ export const normalizeEntryVisibilityImportProfile = (
}
return result;
}, {})
- : defaultOrders;
+ : Object.fromEntries(Object.entries(defaultOrders).map(([path, order]) => [path, [...order]]));
+ if (version < 4) {
+ if (entries["document.more.editMode.wysiwyg"] === false &&
+ entries["document.more.editMode.preview"] === false) {
+ entries["document.more.editMode"] = false;
+ }
+ delete entries["document.more.editMode.wysiwyg"];
+ delete entries["document.more.editMode.preview"];
+ delete orders["document.more.editMode"];
+ }
return {name: profile.name, entries, orders};
};
diff --git a/app/src/config/entryVisibility/runtime.ts b/app/src/config/entryVisibility/runtime.ts
index d635be1ab0..98da0eefc3 100644
--- a/app/src/config/entryVisibility/runtime.ts
+++ b/app/src/config/entryVisibility/runtime.ts
@@ -13,7 +13,7 @@ import {getProfileEntryVisibility} from "./profile";
import {TOOLBAR_ENTRY_ROOT_PATH} from "../../protyle/toolbar/defaults";
import {resolveToolbarItems} from "../../protyle/toolbar/entryVisibility";
-export const ENTRY_VISIBILITY_VERSION = 3;
+export const ENTRY_VISIBILITY_VERSION = 4;
export const ENTRY_PROFILE_SIMPLE = "simple";
export const ENTRY_PROFILE_FULL = "full";
export type TEntryVisibilityTemplate = typeof ENTRY_PROFILE_SIMPLE | typeof ENTRY_PROFILE_FULL;
diff --git a/app/src/constants.ts b/app/src/constants.ts
index a9b9800baa..c863e082ca 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -577,8 +577,7 @@ export abstract class Constants {
alignLeft: {default: "⌥L", custom: "⌥L"},
alignCenter: {default: "⌥C", custom: "⌥C"},
alignRight: {default: "⌥R", custom: "⌥R"},
- wysiwyg: {default: "⌥⌘7", custom: "⌥⌘7"},
- preview: {default: "⌥⌘9", custom: "⌥⌘9"},
+ "edit-mode": {default: "⌥⌘9", custom: "⌥⌘9"},
insertBefore: {default: "⇧⌘B", custom: "⇧⌘B"},
insertAfter: {default: "⇧⌘A", custom: "⇧⌘A"},
insertSuperBlockLeft: {default: "", custom: ""},
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index a1b2549f89..81326385a2 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -4,7 +4,7 @@ import {Constants} from "../../constants";
import {MenuItem} from "../../menus/Menu";
import {net2LocalAssets, updateReadonly} from "./action";
import {openFileAttr} from "../../menus/commonMenuItem";
-import {setEditMode} from "../util/setEditMode";
+import {toggleEditMode} from "../util/toggleEditMode";
import {RecordMedia, RecordMediaInputEndedError} from "../util/RecordMedia";
import {hideMessage, showMessage} from "../../dialog/message";
import {uploadFiles} from "../upload";
@@ -900,33 +900,14 @@ ${padHTML}
id: "editMode",
icon: "iconEdit",
label: window.siyuan.languages["edit-mode"],
- type: "submenu",
- submenu: [{
- id: "wysiwyg",
- current: !protyle.contentElement.classList.contains("fn__none"),
- label: window.siyuan.languages.wysiwyg,
- accelerator: window.siyuan.config.keymap.editor.general.wysiwyg.custom,
- click: () => {
- setEditMode(protyle, "wysiwyg");
- reloadProtyle(protyle, true);
- /// #if !MOBILE
- saveLayout();
- /// #endif
- }
- }, {
- id: "preview",
- current: !protyle.preview.element.classList.contains("fn__none"),
- icon: "iconPreview",
- label: window.siyuan.languages.preview,
- accelerator: window.siyuan.config.keymap.editor.general.preview.custom,
- click: () => {
- setEditMode(protyle, "preview");
- window.siyuan.menus.menu.remove();
- /// #if !MOBILE
- saveLayout();
- /// #endif
- }
- }]
+ accelerator: window.siyuan.config.keymap.editor.general["edit-mode"].custom,
+ click: () => {
+ toggleEditMode(protyle);
+ window.siyuan.menus.menu.remove();
+ /// #if !MOBILE
+ saveLayout();
+ /// #endif
+ }
}).element);
if (!window.siyuan.config.editor.readOnly && !window.siyuan.config.readonly) {
const isCustomReadonly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
diff --git a/app/src/protyle/util/toggleEditMode.ts b/app/src/protyle/util/toggleEditMode.ts
new file mode 100644
index 0000000000..c1757200f9
--- /dev/null
+++ b/app/src/protyle/util/toggleEditMode.ts
@@ -0,0 +1,11 @@
+import {reloadProtyle} from "./reload";
+import {setEditMode} from "./setEditMode";
+
+export const toggleEditMode = (protyle: IProtyle) => {
+ if (protyle.preview.element.classList.contains("fn__none")) {
+ setEditMode(protyle, "preview");
+ return;
+ }
+ setEditMode(protyle, "wysiwyg");
+ reloadProtyle(protyle, true);
+};
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index 8f0f704d0f..e044ea5da9 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -1245,7 +1245,7 @@ declare namespace Config {
openBy: IKey;
optimizeTypography: IKey;
outline: IKey;
- preview: IKey;
+ "edit-mode": IKey;
quickMakeCard: IKey;
redo: IKey;
refPopover: IKey;
@@ -1262,7 +1262,6 @@ declare namespace Config {
switchAdjust: IKey;
undo: IKey;
vLayout: IKey;
- wysiwyg: IKey;
}
/**
diff --git a/app/src/util/keymapMigration.test.ts b/app/src/util/keymapMigration.test.ts
new file mode 100644
index 0000000000..b15524fa9c
--- /dev/null
+++ b/app/src/util/keymapMigration.test.ts
@@ -0,0 +1,58 @@
+import * as assert from "node:assert/strict";
+import test from "node:test";
+import {migrateEditModeKeymap} from "./keymapMigration";
+
+test("edit mode keymap migration prefers the customized preview shortcut", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ preview: {default: "preview-default", custom: "preview-custom"},
+ wysiwyg: {default: "wysiwyg-default", custom: "wysiwyg-custom"},
+ };
+ assert.equal(migrateEditModeKeymap(keymap, "new-default"), true);
+ assert.deepEqual(keymap["edit-mode"], {default: "new-default", custom: "preview-custom"});
+});
+
+test("edit mode keymap migration preserves the only customized shortcut", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ preview: {default: "preview-default", custom: "preview-default"},
+ wysiwyg: {default: "wysiwyg-default", custom: "wysiwyg-custom"},
+ };
+ migrateEditModeKeymap(keymap, "new-default");
+ assert.deepEqual(keymap["edit-mode"], {default: "new-default", custom: "wysiwyg-custom"});
+});
+
+test("edit mode keymap migration keeps an active legacy shortcut", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ preview: {default: "preview-default", custom: ""},
+ wysiwyg: {default: "wysiwyg-default", custom: "wysiwyg-default"},
+ };
+ migrateEditModeKeymap(keymap, "new-default");
+ assert.deepEqual(keymap["edit-mode"], {default: "new-default", custom: "wysiwyg-default"});
+});
+
+test("edit mode keymap migration keeps preview as the default toggle shortcut", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ preview: {default: "preview-default", custom: "preview-default"},
+ wysiwyg: {default: "wysiwyg-default", custom: "wysiwyg-default"},
+ };
+ migrateEditModeKeymap(keymap, "preview-default");
+ assert.deepEqual(keymap["edit-mode"], {default: "preview-default", custom: "preview-default"});
+});
+
+test("edit mode keymap migration preserves clearing both shortcuts", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ preview: {default: "preview-default", custom: ""},
+ wysiwyg: {default: "wysiwyg-default", custom: ""},
+ };
+ migrateEditModeKeymap(keymap, "new-default");
+ assert.deepEqual(keymap["edit-mode"], {default: "new-default", custom: ""});
+});
+
+test("edit mode keymap migration does not overwrite the merged shortcut", () => {
+ const keymap: Record<string, {default: string, custom: string}> = {
+ "edit-mode": {default: "new-default", custom: "merged-custom"},
+ preview: {default: "preview-default", custom: "preview-custom"},
+ wysiwyg: {default: "wysiwyg-default", custom: "wysiwyg-custom"},
+ };
+ assert.equal(migrateEditModeKeymap(keymap, "new-default"), false);
+ assert.deepEqual(keymap["edit-mode"], {default: "new-default", custom: "merged-custom"});
+});
diff --git a/app/src/util/keymapMigration.ts b/app/src/util/keymapMigration.ts
new file mode 100644
index 0000000000..44c91a7de3
--- /dev/null
+++ b/app/src/util/keymapMigration.ts
@@ -0,0 +1,22 @@
+type TKeymapItem = {
+ default: string;
+ custom: string;
+};
+
+export const migrateEditModeKeymap = (
+ keymap: Record<string, TKeymapItem | undefined>,
+ defaultHotkey: string,
+) => {
+ if (keymap["edit-mode"] || (!keymap.preview && !keymap.wysiwyg)) {
+ return false;
+ }
+
+ const legacyItems = [keymap.preview, keymap.wysiwyg].filter((item): item is TKeymapItem => Boolean(item));
+ const customizedItem = legacyItems.find((item) => item.custom !== item.default && Boolean(item.custom));
+ const activeItem = legacyItems.find((item) => Boolean(item.custom));
+ keymap["edit-mode"] = {
+ default: defaultHotkey,
+ custom: customizedItem?.custom ?? activeItem?.custom ?? "",
+ };
+ return true;
+};
diff --git a/kernel/conf/appearance.go b/kernel/conf/appearance.go
index 1bc316a22d..a1df13d221 100644
--- a/kernel/conf/appearance.go
+++ b/kernel/conf/appearance.go
@@ -61,7 +61,7 @@ func NewAppearance() *Appearance {
}
const (
- EntryVisibilityVersion = 3
+ EntryVisibilityVersion = 4
EntryVisibilityProfileSimple = "simple"
EntryVisibilityProfileFull = "full"
)
@@ -94,7 +94,7 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)
if nil == entryVisibility {
return NewEntryVisibility(fallback)
}
- entryVisibility.Version = EntryVisibilityVersion
+ version := entryVisibility.Version
if nil == entryVisibility.Profiles {
entryVisibility.Profiles = []*EntryVisibilityProfile{}
}
@@ -112,9 +112,20 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)
if nil == profile.Orders {
profile.Orders = map[string][]string{}
}
+ if version < 4 {
+ wysiwygVisible, wysiwygConfigured := profile.Entries["document.more.editMode.wysiwyg"]
+ previewVisible, previewConfigured := profile.Entries["document.more.editMode.preview"]
+ if wysiwygConfigured && previewConfigured && !wysiwygVisible && !previewVisible {
+ profile.Entries["document.more.editMode"] = false
+ }
+ delete(profile.Entries, "document.more.editMode.wysiwyg")
+ delete(profile.Entries, "document.more.editMode.preview")
+ delete(profile.Orders, "document.more.editMode")
+ }
profileIDs[profile.ID] = true
profiles = append(profiles, profile)
}
+ entryVisibility.Version = EntryVisibilityVersion
entryVisibility.Profiles = profiles
if entryVisibility.Active != EntryVisibilityProfileSimple && entryVisibility.Active != EntryVisibilityProfileFull &&
!profileIDs[entryVisibility.Active] {
diff --git a/kernel/conf/appearance_test.go b/kernel/conf/appearance_test.go
index 6cfdb9fe4e..fd91205117 100644
--- a/kernel/conf/appearance_test.go
+++ b/kernel/conf/appearance_test.go
@@ -97,3 +97,38 @@ func TestNormalizeEntryVisibilityRemovesLegacyBase(t *testing.T) {
t.Fatalf("unexpected normalized legacy config: %+v", entryVisibility)
}
}
+
+func TestNormalizeEntryVisibilityMigratesEditMode(t *testing.T) {
+ entryVisibility := NormalizeEntryVisibility(&EntryVisibility{
+ Version: 3,
+ Active: "custom",
+ Profiles: []*EntryVisibilityProfile{
+ {
+ ID: "custom",
+ Name: "Custom",
+ Entries: map[string]bool{
+ "document.more.editMode": true,
+ "document.more.editMode.wysiwyg": false,
+ "document.more.editMode.preview": false,
+ },
+ Orders: map[string][]string{
+ "document.more.editMode": {"preview", "wysiwyg"},
+ },
+ },
+ },
+ }, EntryVisibilityProfileFull)
+
+ profile := entryVisibility.Profiles[0]
+ if profile.Entries["document.more.editMode"] {
+ t.Fatalf("hidden legacy mode entries should hide the merged entry: %+v", profile.Entries)
+ }
+ if _, ok := profile.Entries["document.more.editMode.wysiwyg"]; ok {
+ t.Fatalf("legacy WYSIWYG entry should be removed: %+v", profile.Entries)
+ }
+ if _, ok := profile.Entries["document.more.editMode.preview"]; ok {
+ t.Fatalf("legacy preview entry should be removed: %+v", profile.Entries)
+ }
+ if _, ok := profile.Orders["document.more.editMode"]; ok {
+ t.Fatalf("legacy mode order should be removed: %+v", profile.Orders)
+ }
+}