Skip to content

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

:sparkles: Move mobile undo controls to the document breadcrumb https://github.com/siyuan-note/siyuan/issues/20854

Daniel11e560591166
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
index d1da41f471..a79335e30b 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
@@ -8,7 +8,7 @@
"title": "Formatting elements",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2052,7 +2052,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091509-v1x69oc",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2168,7 +2168,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261024161816-f51bzy4",
- "updated": "20261025114801"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2192,6 +2192,20 @@
}
]
},
+ {
+ "ID": "20261028111611-1147a49",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261028111611-1147a49",
+ "updated": "20261028111611"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "On mobile, use Undo and Redo in the document breadcrumb bar, even when the keyboard is closed or a mind map is full screen. These actions use the document history and can also undo changes outside the mind map. The buttons are hidden when both histories are empty or the document is read-only."
+ }
+ ]
+ },
{
"ID": "20261024161816-m2f0ujc",
"Type": "NodeParagraph",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
index 978def95d1..7f8b6a8391 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2055,7 +2055,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091228-wdpx6ev",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2094,7 +2094,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261024161816-k1vwtue",
- "updated": "20261025114801"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2118,6 +2118,20 @@
}
]
},
+ {
+ "ID": "20261028111611-9011ee1",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261028111611-9011ee1",
+ "updated": "20261028111611"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "移动端可使用文档面包屑栏中的撤销、重做按钮,收起键盘或将思维导图全屏后也能操作。它们共用文档的撤销历史,也可能撤销导图以外的修改。没有可撤销或重做的操作时,以及文档只读时,按钮隐藏。"
+ }
+ ]
+ },
{
"ID": "20261024164212-nq100ct",
"Type": "NodeParagraph",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
index f0193d8517..299bec4ac5 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2053,7 +2053,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122008-731sqd6",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2092,7 +2092,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261024161816-xvhal7o",
- "updated": "20261025114801"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2116,6 +2116,20 @@
}
]
},
+ {
+ "ID": "20261028111611-4b5448e",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261028111611-4b5448e",
+ "updated": "20261028111611"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "行動版可使用文件導覽路徑列中的撤銷、重做按鈕,收起鍵盤或將心智圖全螢幕顯示後也能操作。它們共用文件的撤銷歷程,也可能撤銷心智圖以外的修改。沒有可撤銷或重做的操作時,以及文件唯讀時,按鈕隱藏。"
+ }
+ ]
+ },
{
"ID": "20261024164212-21uo12c",
"Type": "NodeParagraph",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
index 25cf262660..1bb14a8cdf 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
@@ -9,7 +9,7 @@
"title": "書式要素",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2177,7 +2177,7 @@
"Properties": {
"ID": "20240530101000-ch5e4vh",
"id": "20240530101000-1ev7xub",
- "updated": "20261027231810"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2216,7 +2216,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261024161816-8fr1gcz",
- "updated": "20261025114801"
+ "updated": "20261028111611"
},
"Children": [
{
@@ -2240,6 +2240,20 @@
}
]
},
+ {
+ "ID": "20261028111611-70ba205",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261028111611-70ba205",
+ "updated": "20261028111611"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "モバイル版では、文書のパンくずリストにある元に戻す・やり直しボタンを使えます。キーボードを閉じた状態やマインドマップの全画面表示中も操作できます。文書全体の履歴を共有するため、マインドマップ以外の変更も対象になります。元に戻す操作とやり直す操作がどちらもない場合や、文書が読み取り専用の場合はボタンが非表示になります。"
+ }
+ ]
+ },
{
"ID": "20261024161816-mich9w1",
"Type": "NodeParagraph",
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index b668a690df..6227dad8a3 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -43,6 +43,26 @@ body.mobile-keyboard--open {
-webkit-user-select: none;
user-select: none;
+ &__history {
+ flex-shrink: 0;
+ }
+
+ > .protyle-breadcrumb__icon {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ &--fullscreen {
+ position: fixed;
+ top: var(--mobile-top-safe-area);
+ right: env(safe-area-inset-right);
+ left: env(safe-area-inset-left);
+ height: var(--mobile-breadcrumb-height);
+ border-radius: 0;
+ z-index: 9;
+ }
+
&__space--mobile-title {
display: flex;
align-items: center;
@@ -63,6 +83,11 @@ body.mobile-keyboard--open {
}
}
+.mindmap-view--document-bar.fullscreen {
+ top: calc(var(--mobile-top-safe-area) + var(--mobile-breadcrumb-height));
+ height: calc(100dvh - var(--mobile-top-safe-area) - var(--mobile-breadcrumb-height));
+}
+
.protyle-preview__title {
-webkit-user-select: none;
user-select: none;
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scss
index 84b1d49356..847e3b4063 100644
--- a/app/src/assets/scss/protyle/_mindmap-view.scss
+++ b/app/src/assets/scss/protyle/_mindmap-view.scss
@@ -130,18 +130,6 @@
padding: 4px;
}
- &--history &__toolbar-group {
- gap: 3px;
- }
-
- &--history &__toolbar {
- box-sizing: border-box;
- }
-
- &--history &__spacer {
- display: none;
- }
-
&__spacer {
flex: 1;
}
diff --git a/app/src/mobile/util/documentBar.ts b/app/src/mobile/util/documentBar.ts
new file mode 100644
index 0000000000..e0325eb813
--- /dev/null
+++ b/app/src/mobile/util/documentBar.ts
@@ -0,0 +1,16 @@
+export const showFullscreenDocumentBar = (protyle: IProtyle, host: HTMLElement) => {
+ const bar = protyle.breadcrumb?.element.parentElement;
+ if (!bar) {
+ return;
+ }
+ const marker = document.createComment("document-bar");
+ bar.before(marker);
+ host.before(bar);
+ bar.classList.add("protyle-breadcrumb--fullscreen");
+ host.classList.add("mindmap-view--document-bar");
+ return () => {
+ bar.classList.remove("protyle-breadcrumb--fullscreen");
+ host.classList.remove("mindmap-view--document-bar");
+ marker.replaceWith(bar);
+ };
+};
diff --git a/app/src/mobile/util/mobileTopBar.test.ts b/app/src/mobile/util/mobileTopBar.test.ts
index 643d8545d8..af0d465400 100644
--- a/app/src/mobile/util/mobileTopBar.test.ts
+++ b/app/src/mobile/util/mobileTopBar.test.ts
@@ -88,6 +88,7 @@ describe("mobile top bar layout", () => {
value: {
body: bodyElement,
getElementById: (id: string) => elements.get(id),
+ querySelector: () => breadcrumbSpace,
},
});
Object.defineProperty(globalThis, "window", {
@@ -101,6 +102,12 @@ describe("mobile top bar layout", () => {
assert.equal(breadcrumbSpace.classList.contains("protyle-breadcrumb__space--mobile-title"), true);
assert.deepEqual(breadcrumbSpace.children, [toolbarSidebarLeft, toolbarName, toolbarNameReadonly, toolbarSync, toolbarSidebarRight]);
+ editorElement.breadcrumbSpace = undefined;
+ updateMobileTopBarLayout();
+ assert.equal(bodyElement.classList.contains("mobile-topbar--merged"), true,
+ "fullscreen mind maps keep title controls in the document breadcrumb");
+ assert.deepEqual(breadcrumbSpace.children, [toolbarSidebarLeft, toolbarName, toolbarNameReadonly, toolbarSync, toolbarSidebarRight]);
+
restoreMobileTopBarLayout();
assert.equal(bodyElement.classList.contains("mobile-topbar--merged"), false);
assert.equal(breadcrumbSpace.classList.contains("protyle-breadcrumb__space--mobile-title"), false);
diff --git a/app/src/mobile/util/mobileTopBar.ts b/app/src/mobile/util/mobileTopBar.ts
index e12c9b63ec..be26354452 100644
--- a/app/src/mobile/util/mobileTopBar.ts
+++ b/app/src/mobile/util/mobileTopBar.ts
@@ -38,7 +38,8 @@ export const updateMobileTopBarLayout = () => {
return;
}
- const breadcrumbSpace = editorElement.querySelector<HTMLElement>(".protyle-breadcrumb__space");
+ const breadcrumbSpace = editorElement.querySelector<HTMLElement>(".protyle-breadcrumb__space") ||
+ document.querySelector<HTMLElement>(".protyle-breadcrumb--fullscreen .protyle-breadcrumb__space");
const merged = isMobileLandscape() &&
!editorElement.classList.contains("fn__none") && Boolean(breadcrumbSpace);
const targetElement = merged ? breadcrumbSpace : topBarElement;
diff --git a/app/src/protyle/breadcrumb/history.test.ts b/app/src/protyle/breadcrumb/history.test.ts
new file mode 100644
index 0000000000..87ed7d13ac
--- /dev/null
+++ b/app/src/protyle/breadcrumb/history.test.ts
@@ -0,0 +1,162 @@
+import * as assert from "node:assert/strict";
+import {execFile} from "node:child_process";
+import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";
+import {tmpdir} from "node:os";
+import * as path from "node:path";
+import {promisify} from "node:util";
+import test from "node:test";
+import {ScriptTarget, transpileModule} from "typescript";
+
+const browserCases = async (source: string, css: string) => {
+ const check = require("node:assert/strict");
+ const style = document.createElement("style"); style.textContent = css; document.head.append(style);
+ window.siyuan = {languages: {undo: "Undo", redo: "Redo", breadcrumb: "Breadcrumb", more: "More", gutterTip2: "Document"},
+ config: {keymap: {editor: {general: {exitFocus: {}}}}, editor: {}}, readonly: false} as any;
+ let finishAllowed = true;
+ let finishPending: Promise<boolean>;
+ const calls: string[] = [];
+ const dependencies = {
+ Constants: {SIYUAN_APPID: "test"}, isMobile: () => true, isMac: () => false,
+ updateHotkeyTip: () => "", mountBreadcrumbButtons: () => {}, bindMobileMenuKeyboard: () => () => {},
+ finishListMindmaps: async () => { calls.push("finish"); return finishPending || finishAllowed; },
+ waitForPendingTransactions: async () => {}, isKnownTransactionOperation: () => true,
+ getCurrentEditor: (): undefined => undefined, getMobileToolbarProtyle: (): undefined => undefined,
+ fetchPost: async (url: string, data: {rootID: string}, callback: (value: unknown) => void) => {
+ check.equal(data.rootID, "document", "the action bar always uses document history");
+ if (url.endsWith("undoState")) {
+ callback({data: {canUndo: true, canRedo: true}});
+ } else {
+ calls.push(url.endsWith("redo") ? "redo" : "undo");
+ callback({data: {canUndo: true, canRedo: true, mutatedRootIDs: ["document"],
+ doOperations: [{action: "update", id: "body"}], undoOperations: [{action: "update", id: "body"}]}});
+ }
+ },
+ };
+ const api = new Function(...Object.keys(dependencies), source +
+ ";return {Breadcrumb, markMirror, getMirror, refreshUndoButtons, showFullscreenDocumentBar};")(...Object.values(dependencies));
+ const settle = async () => {
+ for (let i = 0; i < 3; i++) { await new Promise<void>(resolve => requestAnimationFrame(() => resolve())); }
+ };
+ for (const width of [320, 375, 768]) {
+ document.body.className = "body--android";
+ document.body.style.cssText = "margin:0;--b3-ui-panel-height:42px;--b3-theme-background:white;--b3-theme-on-surface:black";
+ const editor = document.createElement("div"); editor.id = "editor"; editor.style.width = `${width}px`;
+ const root = document.createElement("div"); root.className = "protyle-wysiwyg";
+ root.innerHTML = '<p contenteditable="true">Document body</p>';
+ const owner = {element: editor, block: {rootID: "document"}, notebookId: "box", id: "editor",
+ wysiwyg: {element: root, flushPendingInput: () => calls.push("flush")},
+ undo: {renderLocal: (_owner: unknown, operations: {id: string}[]) => {
+ check.equal(operations[0].id, "body", "undo can affect body text outside the mind map");
+ calls.push("replay");
+ }}, toolbar: {}, disabled: false} as unknown as IProtyle;
+ owner.breadcrumb = new api.Breadcrumb(owner);
+ const bar = owner.breadcrumb.element.parentElement;
+ editor.append(bar, root); document.body.append(editor);
+ const group = bar.querySelector<HTMLElement>(".protyle-breadcrumb__history");
+ const button = (type: string) => group.querySelector<HTMLButtonElement>(`[data-type="${type}"]`);
+ api.markMirror("document", {canUndo: false, canRedo: false}); api.refreshUndoButtons(owner);
+ check.equal(group.getClientRects().length, 0, "empty document history hides both buttons");
+ api.markMirror("document", {canUndo: true, canRedo: false}); await settle();
+ check.equal(button("undo").disabled, false); check.equal(button("redo").disabled, true);
+ for (const fontSize of [16, 32]) {
+ root.style.fontSize = `${fontSize}px`;
+ for (const item of Array.from(bar.querySelectorAll<HTMLButtonElement>("button"))) {
+ const rect = item.getBoundingClientRect();
+ check.ok(rect.left >= -1 && rect.right <= width + 1, `${width}px breadcrumb contains ${item.dataset.type}`);
+ }
+ }
+ root.firstElementChild.dispatchEvent(new Event("focus"));
+ const touch = async (type: string) => {
+ const rect = button(type).getBoundingClientRect();
+ await require("electron").ipcRenderer.invoke("history-touch", [
+ {type: "touchStart", touchPoints: [{id: 1, x: (rect.left + rect.right) / 2, y: (rect.top + rect.bottom) / 2}]},
+ {type: "touchEnd", touchPoints: []},
+ ]);
+ await settle();
+ };
+ calls.length = 0;
+ let release: (value: boolean) => void;
+ finishPending = new Promise(resolve => release = resolve);
+ await touch("undo");
+ check.deepEqual(calls, ["finish"]);
+ check.equal(button("undo").disabled, true); check.equal(button("redo").disabled, true);
+ button("undo").click(); check.deepEqual(calls, ["finish"], "pending edits cannot trigger duplicate undo");
+ release(true); finishPending = undefined; await settle();
+ check.deepEqual(calls, ["finish", "flush", "undo", "replay"]);
+ check.ok(!document.activeElement.matches("input, textarea, [contenteditable='true']"), "keyboard stays closed");
+ calls.length = 0; finishAllowed = false; button("undo").click(); await settle();
+ check.deepEqual(calls, ["finish"], "failed node saves prevent document undo"); finishAllowed = true;
+ calls.length = 0; button("redo").focus();
+ await require("electron").ipcRenderer.invoke("history-key"); await settle();
+ check.deepEqual(calls, ["finish", "flush", "redo", "replay"]);
+ owner.disabled = true; api.refreshUndoButtons(owner);
+ check.equal(group.getClientRects().length, 0); check.equal(button("undo").disabled, true);
+ owner.disabled = false; api.refreshUndoButtons(owner);
+ const host = document.createElement("div"); host.className = "mindmap-view fullscreen";
+ document.body.append(host);
+ const restore = api.showFullscreenDocumentBar(owner, host); await settle();
+ check.equal(bar.parentElement, document.body);
+ check.ok(host.getBoundingClientRect().top >= bar.getBoundingClientRect().bottom - 1, "canvas leaves room for the document bar");
+ calls.length = 0; await touch("undo"); check.deepEqual(calls, ["finish", "flush", "undo", "replay"]);
+ restore(); check.equal(bar.parentElement, editor);
+ check.equal(Array.from(editor.childNodes).some(node => node.nodeType === Node.COMMENT_NODE), false);
+ calls.length = 0; finishPending = new Promise(resolve => release = resolve);
+ button("undo").click(); owner.block.rootID = "another-document";
+ release(true); finishPending = undefined; await settle();
+ check.deepEqual(calls, ["finish"], "switching documents while a save is pending cancels history execution");
+ owner.block.rootID = "document";
+ owner.breadcrumb.refreshHistory("another-document");
+ api.markMirror("document", {canUndo: false, canRedo: false});
+ api.markMirror("another-document", {canUndo: false, canRedo: true});
+ check.equal(button("redo").disabled, false, "the bar follows its new document subscription");
+ api.markMirror("document", {canUndo: true, canRedo: true}); owner.breadcrumb.refreshHistory("document");
+ calls.length = 0; finishPending = new Promise(resolve => release = resolve);
+ button("undo").click();
+ owner.breadcrumb.destroy();
+ release(true); finishPending = undefined; await settle();
+ check.deepEqual(calls, ["finish"], "destroying the editor while saving cancels history execution");
+ owner.breadcrumb.refreshHistory("late-document");
+ api.markMirror("late-document", {canUndo: false, canRedo: false});
+ api.markMirror("document", {canUndo: false, canRedo: false});
+ check.ok(!group.classList.contains("fn__none"), "destroyed bars unsubscribe from history updates");
+ host.remove(); editor.remove();
+ }
+ return "Document history passed";
+};
+
+test("mobile breadcrumb history supports keyboard-closed touch, pending edits, readonly and fullscreen", {
+ skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY, timeout: 60000,
+}, async () => {
+ const source = ["../../util/escape.ts", "../undo/globalUndo.ts", "history.ts", "index.ts", "../../mobile/util/documentBar.ts"]
+ .map(file => transpileModule(require("ifdef-loader/preprocessor").parse(readFileSync(path.join(__dirname, file), "utf8"),
+ {BROWSER: true, MOBILE: true}, false, true).replace(/^import [\s\S]*?;\r?\n/gm, "").replace(/^export /gm, ""),
+ {compilerOptions: {target: ScriptTarget.ES2021}}).outputText).join("\n");
+ const css = ["util/_function.scss", "business/_block.scss", "protyle/_protyle.scss", "protyle/_mindmap-view.scss", "main/_mobile.scss"]
+ .map(file => require("sass").compile(path.resolve(__dirname, "../../assets/scss", file),
+ {logger: require("sass").Logger.silent}).css).join("\n");
+ const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-document-history-"));
+ const script = path.join(temporary, "run.cjs");
+ const browserSource = transpileModule(`(${browserCases.toString()})`, {compilerOptions: {target: ScriptTarget.ES2021}})
+ .outputText.trim().replace(/^"use strict";\s*/, "").replace(/;$/, "");
+ writeFileSync(script, `const {app,BrowserWindow,ipcMain}=require("electron");
+app.setPath("userData",${JSON.stringify(path.join(temporary, "profile"))});app.commandLine.appendSwitch("disable-gpu");
+app.whenReady().then(async()=>{const win=new BrowserWindow({show:false,width:1000,height:800,
+webPreferences:{offscreen:true,nodeIntegration:true,contextIsolation:false}});
+ipcMain.handle("history-touch",async(_event,events)=>{
+if(!win.webContents.debugger.isAttached())win.webContents.debugger.attach("1.3");
+await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled",{enabled:true});
+try{for(const event of events){await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent",event);await new Promise(resolve=>setTimeout(resolve,30));}}
+finally{await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled",{enabled:false});}});
+ipcMain.handle("history-key",()=>{win.webContents.sendInputEvent({type:"keyDown",keyCode:"Return"});win.webContents.sendInputEvent({type:"char",keyCode:"\\r"});win.webContents.sendInputEvent({type:"keyUp",keyCode:"Return"});});
+try{await win.loadURL("data:text/html,<html><body></body></html>");
+console.log(await win.webContents.executeJavaScript(${JSON.stringify(`const __name=value=>value;(${browserSource})(${JSON.stringify(source)},${JSON.stringify(css)})`)}));
+win.destroy();app.exit(0);}catch(error){console.error(error);win.destroy();app.exit(1);}});`, "utf8");
+ const env = {...process.env}; delete env.ELECTRON_RUN_AS_NODE;
+ try {
+ const result = await promisify(execFile)(require("electron") as unknown as string, [script], {env, timeout: 55000, windowsHide: true});
+ assert.match(result.stdout, /Document history passed/);
+ } finally {
+ assert.equal(path.dirname(path.resolve(temporary)), path.resolve(tmpdir()));
+ rmSync(temporary, {recursive: true, force: true});
+ }
+});
diff --git a/app/src/protyle/breadcrumb/history.ts b/app/src/protyle/breadcrumb/history.ts
new file mode 100644
index 0000000000..b6a3a49e14
--- /dev/null
+++ b/app/src/protyle/breadcrumb/history.ts
@@ -0,0 +1,79 @@
+import {getUndoStateSnapshot, requestRedo, requestUndo, subscribeUndoState} from "../undo/globalUndo";
+import {finishListMindmaps} from "../render/listMindmap";
+import {escapeAttr} from "../../util/escape";
+
+export class DocumentHistory {
+ public element = document.createElement("div");
+ private rootID?: string;
+ private unsubscribe?: () => void;
+ private pending = false;
+ private disposed = false;
+
+ constructor(private protyle: IProtyle) {
+ this.element.className = "protyle-breadcrumb__history fn__flex";
+ this.element.innerHTML = (["undo", "redo"] as const).map(type =>
+ `<button class="block__icon fn__flex-center ariaLabel" disabled data-type="${type}" aria-label="${escapeAttr(window.siyuan.languages[type])}"><svg><use xlink:href="#icon${type === "undo" ? "Undo" : "Redo"}"></use></svg></button>`).join("");
+ this.element.classList.add("fn__none");
+ this.element.addEventListener("pointerdown", event => event.preventDefault());
+ this.element.addEventListener("click", event => {
+ const button = (event.target as Element).closest<HTMLButtonElement>("button");
+ if (!button) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ void this.run(button.dataset.type === "redo").catch(error => console.error(error));
+ });
+ }
+
+ public refresh(rootID: string) {
+ if (this.disposed) {
+ return;
+ }
+ if (this.rootID !== rootID) {
+ this.unsubscribe?.();
+ this.rootID = rootID;
+ this.unsubscribe = rootID ? subscribeUndoState(rootID, () => this.render()) : undefined;
+ }
+ this.render();
+ }
+
+ private render() {
+ const state = getUndoStateSnapshot(this.rootID);
+ this.element.classList.toggle("fn__none", this.protyle.disabled || !state.canUndo && !state.canRedo && !this.pending);
+ this.element.querySelectorAll<HTMLButtonElement>("button").forEach(button => {
+ button.disabled = this.protyle.disabled || this.pending || state.pending ||
+ !(button.dataset.type === "undo" ? state.canUndo : state.canRedo);
+ });
+ }
+
+ private async run(redo: boolean) {
+ const protyle = this.protyle;
+ const rootID = this.rootID;
+ const documentID = protyle.block.rootID;
+ const notebookID = protyle.notebookId;
+ const button = this.element.querySelector<HTMLButtonElement>(`[data-type="${redo ? "redo" : "undo"}"]`);
+ if (this.disposed || button.disabled || !rootID || this.pending) {
+ return;
+ }
+ this.pending = true;
+ this.render();
+ try {
+ if (!await finishListMindmaps(protyle) || this.disposed || protyle.disabled || !protyle.element.isConnected ||
+ protyle.block.rootID !== documentID || protyle.notebookId !== notebookID) {
+ return;
+ }
+ protyle.wysiwyg.flushPendingInput();
+ await (redo ? requestRedo(protyle, rootID) : requestUndo(protyle, rootID));
+ } finally {
+ this.pending = false;
+ this.render();
+ }
+ }
+
+ public destroy() {
+ this.disposed = true;
+ this.unsubscribe?.();
+ this.unsubscribe = undefined;
+ }
+}
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index d0bc3aaaa9..a892f2dfa5 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -49,6 +49,7 @@ import {bindMobileMenuKeyboard} from "../../mobile/util/keyboardToolbar";
/// #if MOBILE
import {commandPanel} from "../../boot/globalEvent/command/panel";
import {getEditorFocusRange} from "../util/editorFocus";
+import {DocumentHistory} from "./history";
/// #endif
const genDocumentStatLabel = (stat: IBlockStat, statWithEmbed?: IBlockStat, embedStat?: IEmbedStat) => {
@@ -71,6 +72,21 @@ export class Breadcrumb {
private menuRequestID = 0;
private previousFocusElement: HTMLElement;
private previousRange: Range;
+ /// #if MOBILE
+ private history: DocumentHistory;
+ /// #endif
+
+ public refreshHistory(rootID: string) {
+ /// #if MOBILE
+ this.history?.refresh(rootID);
+ /// #endif
+ }
+
+ public destroy() {
+ /// #if MOBILE
+ this.history?.destroy();
+ /// #endif
+ }
constructor(protyle: IProtyle) {
const element = document.createElement("div");
@@ -97,6 +113,10 @@ ${isMobile() ? `<button class="block__icon fn__flex-center ariaLabel" data-type=
<button class="block__icon fn__flex-center ariaLabel" data-type="more" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></button>
<button class="block__icon fn__flex-center fn__none ariaLabel" data-type="context" aria-label="${window.siyuan.languages.context}"><svg><use xlink:href="#iconAlignCenter"></use></svg></button>`;
this.element = element.firstElementChild as HTMLElement;
+ /// #if MOBILE
+ this.history = new DocumentHistory(protyle);
+ element.querySelector('[data-type="command-panel"]').before(this.history.element);
+ /// #endif
mountBreadcrumbButtons(protyle, element.querySelector(".protyle-breadcrumb__plugin"));
const takeMenuKeyboard = bindMobileMenuKeyboard(element,
'button[data-type="mobile-menu"], button[data-type="doc"], button[data-type="more"], button[data-type="command-panel"]',
diff --git a/app/src/protyle/render/listMindmap/editor.test.ts b/app/src/protyle/render/listMindmap/editor.test.ts
index 767e3a44b2..833920660d 100644
--- a/app/src/protyle/render/listMindmap/editor.test.ts
+++ b/app/src/protyle/render/listMindmap/editor.test.ts
@@ -241,6 +241,19 @@ const browserCases = async (sourceCode: string, css: string, cleanupSource: stri
}}},
} as unknown as typeof window.siyuan;
+ const documentHistoryEditor = create();
+ const documentHistory = document.createElement("div");
+ documentHistory.className = "protyle-breadcrumb__history";
+ const undoButton = document.createElement("button");
+ documentHistory.append(undoButton); document.body.append(documentHistory);
+ undoButton.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true}));
+ await settle();
+ check.equal(documentHistoryEditor.state.finished, 0,
+ "document history controls preserve the node editor until the explicit save gate runs");
+ check.equal(await documentHistoryEditor.editor.finish(), true);
+ check.equal(documentHistoryEditor.state.finished, 1);
+ documentHistory.remove(); await documentHistoryEditor.remove();
+
// 普通段落与软键盘回车走同一节点拆分路径;保留富文本、后续块和原生编辑边界。
const listParagraph = '<div data-type="NodeParagraph" data-node-id="paragraph"><div contenteditable="true"><span data-type="strong">AlphaBeta</span></div></div>';
for (const softKeyboard of [false, true]) {
diff --git a/app/src/protyle/render/listMindmap/editor.ts b/app/src/protyle/render/listMindmap/editor.ts
index 862e820e35..0f8efe9f65 100644
--- a/app/src/protyle/render/listMindmap/editor.ts
+++ b/app/src/protyle/render/listMindmap/editor.ts
@@ -583,7 +583,7 @@ export const openListMindmapEditor = (options: ListMindmapEditorOptions) => {
`[data-type="NodeAttributeView"][data-node-id="${avOverlay.dataset.avBlockId}"]`)) {
return true;
}
- return !!target.closest("#keyboardToolbar, #commonMenu, .b3-dialog");
+ return !!target.closest("#keyboardToolbar, #commonMenu, .b3-dialog, .protyle-breadcrumb__history");
};
document.addEventListener("pointerdown", event => {
if (options.isPanTarget?.(event)) {
diff --git a/app/src/protyle/render/listMindmap/focus.test.ts b/app/src/protyle/render/listMindmap/focus.test.ts
index abaf686137..70fe9fc1c7 100644
--- a/app/src/protyle/render/listMindmap/focus.test.ts
+++ b/app/src/protyle/render/listMindmap/focus.test.ts
@@ -9,8 +9,8 @@ const source = createSourceFile("index.ts", readFileSync("src/protyle/render/lis
const controller = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapController");
assert.ok(controller && isClassDeclaration(controller));
const methods = controller.members.filter(item => item.name &&
- ["add", "deleteNode", "change", "undo", "focusNode", "edit", "refreshUndoState", "bindUndoState"].includes(item.name.getText(source)));
-assert.equal(methods.length, 8);
+ ["add", "deleteNode", "change", "undo", "focusNode", "edit"].includes(item.name.getText(source)));
+assert.equal(methods.length, 6);
let editorUndo = "";
const visit = (item: import("typescript").Node) => {
if (isPropertyAssignment(item) && item.name.getText(source) === "onUndo" &&
@@ -29,38 +29,6 @@ class Controller {
globalThis.Controller = Controller;
globalThis.isUndoViewportPreserved = isUndoViewportPreserved;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
-test("canvas history follows embedded source documents, local stacks, busy state and subscription lifetime", () => {
- const listeners = new Map<string, () => void>();
- const states: unknown[] = [];
- let editable = true;
- let embedded = true;
- const root = {undoPending: false};
- const owner = {block: {rootID: "document"}, lite: false, undo: {undoStack: [] as unknown[], redoStack: [] as unknown[]}};
- const context: any = {roots: new WeakMap([[owner, root]]), canEdit: () => editable,
- getUndoStateSnapshot: (id: string) => ({canUndo: id === "source", canRedo: false, pending: false}),
- hasUndoStateMirror: () => true,
- subscribeUndoState: (id: string, listener: () => void) => {
- listeners.set(id, listener); listener();
- return () => listeners.delete(id);
- }};
- runInNewContext(compiled, context);
- const target = Object.assign(new context.Controller(), {owner,
- list: {closest: () => embedded ? {dataset: {rootId: "source"}} : null},
- view: {setUndoState: (state: unknown) => states.push(JSON.parse(JSON.stringify(state)))}});
- target.bindUndoState();
- assert.deepEqual([...listeners.keys()], ["source"]);
- assert.deepEqual(states.at(-1), {canUndo: true, canRedo: false, pending: false});
- root.undoPending = true; listeners.get("source")();
- assert.deepEqual(states.at(-1), {canUndo: true, canRedo: false, pending: true});
- root.undoPending = false; embedded = false; target.bindUndoState();
- assert.deepEqual([...listeners.keys()], ["document"]);
- assert.deepEqual(states.at(-1), {canUndo: false, canRedo: false, pending: false});
- owner.lite = true; owner.undo.redoStack.push({}); target.refreshUndoState();
- assert.deepEqual(states.at(-1), {canUndo: false, canRedo: true, pending: false});
- editable = false; target.bindUndoState();
- assert.equal(listeners.size, 0);
-});
-
test("explicit mind map additions stay selected while clipboard additions still open the editor", async () => {
const steps: string[] = [];
const item = {dataset: {nodeId: "new"}, classList: {replace: () => {}}, outerHTML: "new node"};
diff --git a/app/src/protyle/render/listMindmap/history.test.ts b/app/src/protyle/render/listMindmap/history.test.ts
deleted file mode 100644
index 7c505b7f1b..0000000000
--- a/app/src/protyle/render/listMindmap/history.test.ts
+++ /dev/null
@@ -1,179 +0,0 @@
-import * as assert from "node:assert/strict";
-import {execFile} from "node:child_process";
-import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";
-import {tmpdir} from "node:os";
-import * as path from "node:path";
-import {promisify} from "node:util";
-import test from "node:test";
-import {ScriptTarget, transpileModule} from "typescript";
-
-const browserCases = async (source: string, css: string) => {
- const check = require("node:assert/strict");
- const style = document.createElement("style"); style.textContent = css; document.head.append(style);
- const api = new Function("Constants", "mathRender", "tabsRender", "destroyTabsRender", source +
- ";return {ListMindmapView, readListMindmap};")(
- {CUSTOM_SY_LIST_MINDMAP_DATA: "custom-sy-list-mindmap-data"}, () => {}, () => {}, () => {});
- const lute = Lute.New(); lute.SetProtyleWYSIWYG(true);
- const settle = async () => {
- for (let i = 0; i < 3; i++) { await new Promise<void>(resolve => requestAnimationFrame(() => resolve())); }
- };
- for (const width of [240, 320, 700]) {
- for (const scale of [1, .75]) {
- document.body.className = width < 700 ? "body--android" : "body--windows";
- const outer = document.createElement("div");
- outer.style.cssText = `position:absolute;left:20px;top:20px;width:${width}px;height:360px;overflow:auto;` +
- `transform:scale(${scale});transform-origin:top left`;
- const host = document.createElement("div");
- host.style.cssText = "--mindmap-view-height:1000px;--b3-border-color:#888";
- outer.append(host); document.body.append(outer);
- const holder = document.createElement("div"); holder.innerHTML = lute.Md2BlockDOM("- Root\n - Node\n");
- const model = api.readListMindmap(holder.firstElementChild);
- const original = holder.innerHTML;
- let undo = 0;
- let redo = 0;
- let finishAllowed = true;
- let release: () => void;
- const view = new api.ListMindmapView({host, model, onExit() {}, onSettingsMenu() {}, onExpandLevelMenu() {},
- finishEdit: () => finishAllowed,
- onUndo: () => { undo++; return new Promise<void>(resolve => release = resolve); },
- onRedo: () => { redo++; },
- });
- await settle();
- view.setInteractionActive(true); view.clearSelection();
- outer.scrollTop = 220; await settle();
- const toolbar = host.querySelector<HTMLElement>(".mindmap-view__toolbar");
- const button = (key: string) => toolbar.querySelector<HTMLButtonElement>(`[data-type="${key}"]`);
- let stage = "initial";
- const visible = () => {
- const rect = toolbar.getBoundingClientRect();
- const clip = view.fullscreenMarker ? {left: 0, top: 0, right: innerWidth, bottom: innerHeight} : outer.getBoundingClientRect();
- check.equal(getComputedStyle(toolbar).visibility, "visible",
- `${stage}: toolbar ${JSON.stringify(rect.toJSON())}, clip ${JSON.stringify(clip)}, style ${toolbar.style.cssText}`);
- check.ok(rect.top >= clip.top - 1 && rect.bottom <= clip.bottom + 1);
- for (const key of ["undo", "redo"]) {
- const bounds = button(key).getBoundingClientRect();
- check.ok(bounds.left >= clip.left - 1 && bounds.right <= clip.right + 1,
- `${key} fits the ${width}px canvas at scale ${scale}`);
- }
- };
- check.equal(button("undo").disabled, true); check.equal(button("redo").disabled, true);
- check.equal(button("undo").getClientRects().length, 0, "empty history hides both controls");
- check.equal(button("redo").getClientRects().length, 0);
- view.setUndoState({canUndo: true, canRedo: false});
- await settle(); visible();
- const bounds = button("undo").getBoundingClientRect();
- await require("electron").ipcRenderer.invoke("mindmap-history-touch", [
- {type: "touchStart", touchPoints: [{id: 1, x: (bounds.left + bounds.right) / 2, y: (bounds.top + bounds.bottom) / 2}]},
- {type: "touchEnd", touchPoints: []},
- ]);
- await settle();
- check.equal(undo, 1, "canvas undo works without a selected node or a text editor");
- check.equal(button("undo").disabled, true); check.equal(button("redo").disabled, true);
- button("undo").click(); await settle(); check.equal(undo, 1, "pending history cannot repeat");
- check.ok(!document.activeElement.matches("input, textarea, [contenteditable='true']"), "undo does not focus text input");
- check.equal(outer.scrollTop, 220, "history activation preserves document scroll position");
- view.setUndoState({canUndo: false, canRedo: true}); release(); await settle();
- visible();
- view.offsetX = 500; view.offsetY = -500; view.draw(); await settle();
- view.focusNode(model.root.id, false); await settle();
- check.deepEqual([view.offsetX, view.offsetY, outer.scrollTop], [500, -500, 220],
- "history restores an offscreen node selection without panning the canvas or scrolling the document");
- check.equal(button("undo").disabled, true); check.equal(button("redo").disabled, false);
- button("redo").focus();
- check.equal(document.activeElement, button("redo"));
- await require("electron").ipcRenderer.invoke("mindmap-history-key"); await settle();
- check.equal(redo, 1, "the history control supports keyboard activation");
- view.setUndoState({canUndo: true, canRedo: false}); finishAllowed = false;
- button("undo").click(); await settle();
- check.equal(undo, 1, "failed pending edits prevent history execution");
- check.equal(button("undo").disabled, false, "canceled execution releases the local busy state");
- finishAllowed = true;
- const selectedID = model.root.children[0].id;
- const selectedNode = host.querySelector<HTMLElement>(`[data-mindmap-id="${selectedID}"]`);
- view.focusNode(selectedID, false);
- const mouseClick = async (key: string) => {
- const rect = button(key).getBoundingClientRect();
- await require("electron").ipcRenderer.invoke("mindmap-history-mouse", {
- x: (rect.left + rect.right) / 2, y: (rect.top + rect.bottom) / 2,
- });
- await settle();
- check.equal(view.getSelectedId(), selectedID, "history pointerdown preserves the selected node");
- check.equal(selectedNode.classList.contains("mindmap-view__node--selected"), true,
- "the node selection cannot disappear while history is pending");
- };
- await mouseClick("undo");
- check.equal(undo, 2);
- check.equal(button("undo").disabled, true);
- view.setUndoState({canUndo: false, canRedo: true}); release(); await settle();
- await mouseClick("redo");
- check.equal(redo, 2);
- view.setUndoState({canUndo: true, canRedo: false});
- const touchBounds = button("undo").getBoundingClientRect();
- await require("electron").ipcRenderer.invoke("mindmap-history-touch", [
- {type: "touchStart", touchPoints: [{id: 1, x: (touchBounds.left + touchBounds.right) / 2,
- y: (touchBounds.top + touchBounds.bottom) / 2}]},
- {type: "touchEnd", touchPoints: []},
- ]);
- await settle();
- check.equal(undo, 3);
- check.equal(view.getSelectedId(), selectedID, "touch undo also keeps the selected node visible while pending");
- check.equal(selectedNode.classList.contains("mindmap-view__node--selected"), true);
- view.setUndoState({canUndo: true, canRedo: false}); release(); await settle();
- stage = "short";
- outer.style.height = "60px"; outer.dispatchEvent(new Event("scroll")); await settle(); visible();
- outer.style.height = "360px"; outer.dispatchEvent(new Event("scroll")); await settle();
- const scrollTop = outer.scrollTop;
- stage = "fullscreen";
- view.enterFullscreen(); await settle(); visible();
- view.exitFullscreen(); await settle(); check.equal(outer.scrollTop, scrollTop); visible();
- view.setReadOnly(true); await settle();
- check.equal(button("undo"), null); check.equal(button("redo"), null);
- view.setReadOnly(false); await settle(); visible();
- check.equal(button("undo").disabled, false);
- view.setUndoState({canUndo: false, canRedo: false}); await settle();
- check.equal(button("undo").getClientRects().length, 0, "clearing both histories hides the controls again");
- check.equal(button("redo").getClientRects().length, 0);
- check.equal(holder.innerHTML, original, "history controls never write document metadata");
- view.destroy(); outer.remove();
- }
- }
- return "Mindmap history controls passed";
-};
-
-test("desktop and mobile canvas history hides empty controls and preserves selection through touch, mouse and keyboard", {
- skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY, timeout: 60000,
-}, async () => {
- const source = ["../av/richTextValue.ts", "summary.ts", "connectors.ts", "appearance.ts", "model.ts", "fold.ts", "routing.ts", "pan.ts", "view.ts"]
- .map(file => transpileModule(readFileSync(path.join(__dirname, file), "utf8")
- .replace(/^import [\s\S]*?;\r?\n/gm, "").replace(/^export /gm, ""), {compilerOptions: {target: ScriptTarget.ES2021}}).outputText).join("\n");
- const css = ["business/_block.scss", "business/_color.scss", "component/_svg.scss", "protyle/_mindmap-view.scss"]
- .map(file => require("sass").compile(path.resolve(__dirname, "../../../assets/scss", file),
- {logger: require("sass").Logger.silent}).css).join("\n");
- const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-mindmap-history-"));
- const script = path.join(temporary, "run.cjs");
- const browserSource = transpileModule(`(${browserCases.toString()})`, {compilerOptions: {target: ScriptTarget.ES2021}})
- .outputText.trim().replace(/^"use strict";\s*/, "").replace(/;$/, "");
- writeFileSync(script, `const {app,BrowserWindow,ipcMain}=require("electron");
-app.setPath("userData",${JSON.stringify(path.join(temporary, "profile"))});app.commandLine.appendSwitch("disable-gpu");
-app.whenReady().then(async()=>{const win=new BrowserWindow({show:false,width:1000,height:800,
-webPreferences:{offscreen:true,nodeIntegration:true,contextIsolation:false}});
-ipcMain.handle("mindmap-history-touch",async(_event,events)=>{
-if(!win.webContents.debugger.isAttached())win.webContents.debugger.attach("1.3");
-await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled",{enabled:true});
-try{for(const event of events){await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent",event);await new Promise(resolve=>setTimeout(resolve,30));}}
-finally{await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled",{enabled:false});}});
-ipcMain.handle("mindmap-history-key",()=>{win.webContents.sendInputEvent({type:"keyDown",keyCode:"Return"});win.webContents.sendInputEvent({type:"char",keyCode:"\\r"});win.webContents.sendInputEvent({type:"keyUp",keyCode:"Return"});});
-ipcMain.handle("mindmap-history-mouse",(_event,point)=>{for(const type of ["mouseDown","mouseUp"]){win.webContents.sendInputEvent({type,...point,button:"left",clickCount:1});}});
-try{await win.loadURL("data:text/html,<html><body></body></html>");
-await win.webContents.executeJavaScript(require("fs").readFileSync(${JSON.stringify(path.resolve(__dirname, "../../../../stage/protyle/js/lute/lute.min.js"))},"utf8"));
-console.log(await win.webContents.executeJavaScript(${JSON.stringify(`const __name=value=>value;(${browserSource})(${JSON.stringify(source)},${JSON.stringify(css)})`)}));
-win.destroy();app.exit(0);}catch(error){console.error(error);win.destroy();app.exit(1);}});`, "utf8");
- const env = {...process.env}; delete env.ELECTRON_RUN_AS_NODE;
- try {
- const result = await promisify(execFile)(require("electron") as unknown as string, [script], {env, timeout: 55000, windowsHide: true});
- assert.match(result.stdout, /Mindmap history controls passed/);
- } finally {
- assert.equal(path.dirname(path.resolve(temporary)), path.resolve(tmpdir()));
- rmSync(temporary, {recursive: true, force: true});
- }
-});
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index 1b746f1722..7a7e3e0a49 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -58,7 +58,10 @@ import {getListMindmapConnectorMenuItem} from "./connectorMenu";
import {getDefaultListMindmapConnectorStyle, setDefaultListMindmapConnectorStyle} from "./preferences";
import {assignListMindmapBranchColors, getListMindmapAppearanceMenu} from "./appearance";
import {getEmbedChildOperationContext} from "../../wysiwyg/getBlock";
-import {getUndoStateSnapshot, hasUndoStateMirror, initMirror, requestRedo, requestUndo, subscribeUndoState} from "../../undo/globalUndo";
+import {requestRedo, requestUndo} from "../../undo/globalUndo";
+/// #if MOBILE
+import {showFullscreenDocumentBar} from "../../../mobile/util/documentBar";
+/// #endif
import {preserveUndoViewport} from "../../undo/viewport";
import {buildBlockDOMClipboardData} from "../../util/blockDOMClipboard";
import {buildWebClipboardHTML, getTextSiyuanFromTextHTML} from "../../util/clipboardData";
@@ -69,7 +72,7 @@ import {canCutMindmapBranches, copyMindmapBranches, pasteMindmapBranches, readMi
const roots = new WeakMap<IProtyle, {refresh: () => void, mountNew: (list: HTMLElement) => void,
restoreFocus: (listID: string, candidateIDs: string[], selection?: Record<string, string>, source?: HTMLElement) => void, focusRevision: number,
- interactionRevision?: number, focusGuard?: () => boolean, undoPending?: boolean, refreshUndoState?: () => void,
+ interactionRevision?: number, focusGuard?: () => boolean, undoPending?: boolean,
finish: () => Promise<boolean>, destroy: () => void}>();
const hasMindmapFocusOverlay = () => {
@@ -183,8 +186,6 @@ class ListMindmapController {
private taskChanges: Promise<void> = Promise.resolve();
private unregisterVisible?: () => void;
private resize: ReturnType<typeof bindListMindmapResize>;
- private undoRootID?: string;
- private unsubscribeUndoState?: () => void;
constructor(owner: IProtyle, list: HTMLElement) {
this.owner = owner;
@@ -244,6 +245,9 @@ class ListMindmapController {
}, {capture: true});
list.appendChild(this.host);
let restoreFullscreenChrome: () => void;
+ /// #if MOBILE
+ let restoreDocumentBar: () => void;
+ /// #endif
this.view = new ListMindmapView({
viewport: getListMindmapViewport(owner, list),
onViewportChange: state => saveListMindmapViewport(owner, list, state),
@@ -359,6 +363,14 @@ class ListMindmapController {
});
}),
onFullscreen: (enter, button) => {
+ /// #if MOBILE
+ if (enter) {
+ restoreDocumentBar = showFullscreenDocumentBar(this.owner, this.host);
+ } else {
+ restoreDocumentBar?.();
+ restoreDocumentBar = undefined;
+ }
+ /// #endif
if (enter) {
const drag = document.getElementById("drag");
const controls = document.getElementById("windowControls");
@@ -506,8 +518,6 @@ class ListMindmapController {
}
});
}),
- onUndo: () => this.undo(false),
- onRedo: () => this.undo(true),
onNodeStyle: (id, patch) => this.metadata(metadata => {
metadata.nodes[id] = {...metadata.nodes[id], ...patch};
}),
@@ -586,7 +596,6 @@ class ListMindmapController {
metadata.summaries = metadata.summaries?.filter(item => item.id !== id) || [];
}),
});
- this.bindUndoState();
list.dataset.mindmapViewRendered = "true";
this.resize = bindListMindmapResize({
block: list, host: this.host,
@@ -1027,7 +1036,6 @@ class ListMindmapController {
if (root) {
root.undoPending = true;
root.focusGuard = guard;
- root.refreshUndoState?.();
}
try {
if (!canEdit(this.owner, this.list) || (this.activeEditor && !await this.activeEditor.finish())) {
@@ -1076,7 +1084,6 @@ class ListMindmapController {
if (root?.focusGuard === guard) {
root.focusGuard = undefined;
root.undoPending = false;
- root.refreshUndoState?.();
}
}
}
@@ -1125,41 +1132,13 @@ class ListMindmapController {
}
public async finish() {
+ this.view.finishLabels();
await this.taskChanges;
return this.activeEditor ? this.activeEditor.finish() : true;
}
- public refreshUndoState() {
- if (this.disposed) {
- return;
- }
- const state = getUndoStateSnapshot(this.undoRootID);
- const undo = this.owner.undo;
- if (this.owner.lite && undo && "undoStack" in undo && "redoStack" in undo &&
- Array.isArray(undo.undoStack) && Array.isArray(undo.redoStack)) {
- state.canUndo = undo.undoStack.length > 0;
- state.canRedo = undo.redoStack.length > 0;
- }
- this.view.setUndoState({...state, pending: state.pending || !!roots.get(this.owner)?.undoPending});
- }
-
- private bindUndoState() {
- const rootID = canEdit(this.owner, this.list) ?
- this.list.closest<HTMLElement>(".protyle-wysiwyg__embed")?.dataset.rootId || this.owner.block.rootID : undefined;
- if (rootID !== this.undoRootID) {
- this.unsubscribeUndoState?.();
- this.undoRootID = rootID;
- this.unsubscribeUndoState = rootID ? subscribeUndoState(rootID, () => this.refreshUndoState()) : undefined;
- if (rootID && !this.owner.lite && !hasUndoStateMirror(rootID)) {
- void initMirror(rootID).catch(error => console.error(error));
- }
- }
- this.refreshUndoState();
- }
-
public refresh() {
this.view.setReadOnly(!canEdit(this.owner, this.list));
- this.bindUndoState();
syncListMindmapHeight(this.list, this.host);
this.resize.refresh();
const snapshot = cleanListMindmapHTML(this.list.outerHTML);
@@ -1176,7 +1155,6 @@ class ListMindmapController {
return;
}
this.disposed = true;
- this.unsubscribeUndoState?.();
const restoreFocus = this.host.contains(document.activeElement) && this.list.isConnected &&
this.list.dataset.type !== "NodeMindmap" && this.list.getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) !== "1";
this.activeEditor?.destroy();
@@ -1430,7 +1408,7 @@ export const initListMindmaps = (owner: IProtyle) => {
newlyCreated.add(list);
refresh();
}
- }, restoreFocus, refreshUndoState: () => instances.forEach(instance => instance.refreshUndoState()),
+ }, restoreFocus,
focusRevision: 0, interactionRevision: 0, destroy: () => {
disposed = true;
interactions.abort();
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index fdacc3a199..36f17af390 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -390,9 +390,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
isProtyleListItemFragment: () => false, isHiddenTabContent: () => false,
matchHotKey: (binding: unknown) => { check.equal(binding, undefined); return false; },
isMobile: () => mobile, waitForPendingTransactions: async () => {},
- getUndoStateSnapshot: () => ({canUndo: true, canRedo: true, pending: false}),
- hasUndoStateMirror: () => true,
- subscribeUndoState: (_rootID: string, listener: () => void) => { listener(); return () => {}; },
preserveUndoViewport: () => () => {},
isEncryptedBox: () => false,
setStorageVal: () => check.fail("Embedded previews cannot persist viewport positions"),
@@ -1255,8 +1252,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
const nodeStyles: unknown[] = [];
const fullscreenChanges: boolean[] = [];
let interactions = 0;
- let undo = 0;
- let redo = 0;
let settingsOpened = 0;
const colorSettings: {kind: string, anchor?: HTMLButtonElement}[] = [];
let overflowExpand: ((level: number | "expandAll" | "foldAll") => void) | undefined;
@@ -1288,8 +1283,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
deletions.push(id);
},
onFold: (id: string) => folds.push(id),
- onUndo: () => undo++,
- onRedo: () => redo++,
onSettingsMenu: (_anchor: HTMLElement, expand?: typeof overflowExpand, pan?: typeof panMenu) => {
settingsOpened++;
overflowExpand = expand;
@@ -1904,13 +1897,8 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(view.getContentHost(alpha).firstElementChild, editorMarker);
view.setEditing();
view.update(api.readListMindmap(list));
- check.equal(host.querySelector<HTMLButtonElement>('[aria-label="undo"]').disabled, true,
- "an empty history keeps undo disabled");
- check.equal(host.querySelector<HTMLButtonElement>('[aria-label="redo"]').disabled, true);
- check.equal(host.querySelector<HTMLButtonElement>('[aria-label="undo"]').hidden, true);
- check.equal(host.querySelector<HTMLButtonElement>('[aria-label="redo"]').hidden, true);
- check.equal(undo, 0);
- check.equal(redo, 0);
+ check.equal(host.querySelector('[data-type="undo"], [data-type="redo"]'), null,
+ "history controls belong to the document action bar");
finishAllowed = false;
nodeElement(alpha).querySelector<HTMLButtonElement>(".mindmap-view__add-child").click();
check.equal(additions.length, 0);
@@ -2210,7 +2198,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(fitButton.parentElement, toolbarPopup, "fit shares the zoom panel with the slider and reset");
check.equal(toolbarGroup.querySelector(':scope > [aria-label="listMindmapFit"]'), null,
"fit no longer occupies a separate top-level toolbar slot");
- view.setUndoState({canUndo: true, canRedo: false});
for (const width of [96, 180, 240, 260, 320, 360, 700]) {
for (const fontSize of [14, 32]) {
host.style.width = `${width}px`;
@@ -2264,7 +2251,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
}
}
}
- view.setUndoState({canUndo: false, canRedo: false});
host.style.cssText = originalHostStyle;
host.focus();
view.zoomAt(1);
@@ -3439,7 +3425,6 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
nodeElement(beta).dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
host.dispatchEvent(new KeyboardEvent("keydown", {key: "z", ctrlKey: true, bubbles: true}));
check.equal(edits.length, editsBeforeReadonly);
- check.equal(undo, 0);
const persistedBeforeFold = list.outerHTML;
pressDelete();
check.deepEqual(deletions, [beta]);
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index eb7ea924d9..4411250233 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -70,8 +70,6 @@ export interface ListMindmapViewOptions {
onTabTaskMenu?: (id: string, itemId: string, anchor: HTMLElement) => void;
isTaskCycle?: (event: KeyboardEvent) => boolean;
isTaskCompletionToggle?: (event: KeyboardEvent) => boolean;
- onUndo?: () => void | Promise<void>;
- onRedo?: () => void | Promise<void>;
onNodeStyle?: (id: string, patch: Partial<ListMindmapNodeStyle>) => void;
onNodesStyle?: (ids: string[], patch: Partial<ListMindmapNodeStyle>) => void;
onNodeWidths?: (widths: {id: string, width: number}[], expected: string) => Promise<boolean>;
@@ -139,8 +137,6 @@ export class ListMindmapView {
widths: {id: string, width: number}[], baseWidth: number, slider: number, preview: boolean,
};
private widthPending = false;
- private undoState = {canUndo: false, canRedo: false, pending: false};
- private historyPending = false;
private inspectorFrame = 0;
private revealInspectorHost = false;
private readonly zoomLabel: HTMLSpanElement;
@@ -516,7 +512,6 @@ export class ListMindmapView {
}
if (this.inspector.contains(target) || this.inspectorPopover.contains(target) || this.buttons.get("style")?.contains(target) ||
this.buttons.get("relation")?.contains(target) || this.buttons.get("expandLevel")?.contains(target) ||
- this.buttons.get("undo")?.contains(target) || this.buttons.get("redo")?.contains(target) ||
this.buttons.get("summary")?.contains(target) || this.buttons.get("multiSelect")?.contains(target) ||
this.levelSelect?.contains(target)) {
return;
@@ -555,49 +550,9 @@ export class ListMindmapView {
return this.locked;
}
- public setUndoState(state: {canUndo: boolean, canRedo: boolean, pending?: boolean}) {
- if (this.destroyed) {
- return;
- }
- this.undoState = {...state, pending: !!state.pending};
- this.updateUndoControls();
- }
-
- private updateUndoControls() {
- const hidden = !this.undoState.canUndo && !this.undoState.canRedo && !this.historyPending;
- for (const key of ["undo", "redo"] as const) {
- const button = this.buttons.get(key);
- if (button) {
- button.hidden = hidden;
- button.disabled = this.readOnly || this.historyPending || this.undoState.pending ||
- !(key === "undo" ? this.undoState.canUndo : this.undoState.canRedo);
- }
- }
- this.queueInspectorLayout();
- }
-
- private async runHistory(redo: boolean) {
- if (this.readOnly || this.historyPending || this.buttons.get(redo ? "redo" : "undo")?.disabled) {
- return;
- }
- this.historyPending = true;
- this.updateUndoControls();
- try {
- this.closeInspectorPanel();
- this.finishSummaryEdit?.(true);
- this.finishRelationEdit?.(true);
- const finished = await this.options.finishEdit?.();
- if (finished !== false && !this.destroyed && !this.readOnly) {
- await (redo ? this.options.onRedo?.() : this.options.onUndo?.());
- }
- } catch (error) {
- console.error(error);
- } finally {
- this.historyPending = false;
- if (!this.destroyed) {
- this.updateUndoControls();
- }
- }
+ public finishLabels() {
+ this.finishSummaryEdit?.(true);
+ this.finishRelationEdit?.(true);
}
private activatePointer = (event: PointerEvent) => {
@@ -679,10 +634,6 @@ export class ListMindmapView {
}
private createToolbar() {
- this.toolbar.style.top = this.toolbar.style.left = this.toolbar.style.right = this.toolbar.style.width =
- this.toolbar.style.visibility = "";
- const history = !this.readOnly && !!(this.options.onUndo || this.options.onRedo);
- this.options.host.classList.toggle("mindmap-view--history", history);
const controls = createElement("div", "mindmap-view__toolbar-group");
const add = (id: string, key: string, icon: string, action: () => void, nodeAction = false, finish = true) => {
const button = this.makeButton(key, icon, action, "", finish);
@@ -713,15 +664,6 @@ export class ListMindmapView {
add("fullscreen", "fullscreen", "iconFullscreen", () => this.toggleFullscreen());
};
this.toolbar.append(createElement("span", "mindmap-view__spacer fn__flex-1"), controls);
- if (history) {
- for (const [key, icon] of [["undo", "iconUndo"], ["redo", "iconRedo"]] as const) {
- if (key === "undo" ? this.options.onUndo : this.options.onRedo) {
- add(key, key, icon, () => void this.runHistory(key === "redo"), false, false);
- this.buttons.get(key).dataset.type = key;
- }
- }
- this.updateUndoControls();
- }
this.levelSelect = undefined;
this.options.host.classList.toggle("mindmap-view--locked", this.locked);
add("lock", this.locked ? "listMindmapUnlock" : "listMindmapLock", this.locked ? "iconLock" : "iconUnlock", () => {
@@ -3723,8 +3665,7 @@ export class ListMindmapView {
}
private queueInspectorLayout(reveal = false) {
- const history = !this.readOnly && !!(this.options.onUndo || this.options.onRedo);
- if (this.destroyed || this.inspector.hidden && !reveal && !history) {
+ if (this.destroyed || this.inspector.hidden && !reveal) {
return;
}
this.revealInspectorHost ||= reveal;
@@ -3738,7 +3679,6 @@ export class ListMindmapView {
if (this.destroyed) {
return;
}
- this.positionToolbar();
if (this.inspector.hidden || this.readOnly) {
return;
}
@@ -3788,28 +3728,11 @@ export class ListMindmapView {
this.inspector.style.bottom = `${this.options.host.clientTop + this.options.host.clientHeight -
(visible.bottom - host.top) / scaleY + 8}px`;
// 可见条带放不下操作栏时保留选择,滚动回足够的空间后恢复显示。
- const toolbarHeight = !this.readOnly && (this.options.onUndo || this.options.onRedo) ? this.toolbar.offsetHeight + 4 : 0;
this.inspector.style.visibility = width <= 0 ||
- (visible.bottom - visible.top) / scaleY < toolbarHeight + this.inspector.offsetHeight + 16 ? "hidden" : "";
+ (visible.bottom - visible.top) / scaleY < this.inspector.offsetHeight + 16 ? "hidden" : "";
this.positionInspectorPanel();
}
- private positionToolbar() {
- if (this.readOnly || !(this.options.onUndo || this.options.onRedo)) {
- return;
- }
- const host = this.options.host.getBoundingClientRect();
- const visible = this.getVisibleViewportBounds();
- const scaleX = host.width / this.options.host.offsetWidth || 1;
- const scaleY = host.height / this.options.host.offsetHeight || 1;
- this.toolbar.style.left = `${(visible.left - host.left) / scaleX - this.options.host.clientLeft}px`;
- this.toolbar.style.right = "auto";
- this.toolbar.style.width = `${Math.max(0, (visible.right - visible.left) / scaleX)}px`;
- this.toolbar.style.top = `${Math.max(0, (visible.top - host.top) / scaleY - this.options.host.clientTop)}px`;
- this.toolbar.style.visibility = visible.right <= visible.left ||
- (visible.bottom - visible.top) / scaleY < this.toolbar.offsetHeight + 8 ? "hidden" : "";
- }
-
private positionInspectorPanel() {
if (this.destroyed || this.inspectorPopover.hidden || !this.inspectorPanel) {
return;
diff --git a/app/src/protyle/undo/globalUndo.ts b/app/src/protyle/undo/globalUndo.ts
index a78fc41a0c..9e5dbc8373 100644
--- a/app/src/protyle/undo/globalUndo.ts
+++ b/app/src/protyle/undo/globalUndo.ts
@@ -48,7 +48,7 @@ const notifyUndoState = (rootID?: string) => {
}
};
-// 画布等不依赖文字选区的入口订阅同一份文档历史状态,销毁视图时解除订阅。
+// 文档操作栏订阅共享历史状态,销毁编辑器时解除订阅。
export const subscribeUndoState = (rootID: string, listener: (state: ReturnType<typeof getUndoStateSnapshot>) => void) => {
let listeners = undoStateListeners.get(rootID);
if (!listeners) {
@@ -156,6 +156,7 @@ const applyUndoButtons = (protyle: IProtyle, rootID: string) => {
};
if (protyle.breadcrumb) {
applyState(protyle.breadcrumb.element.parentElement);
+ protyle.breadcrumb.refreshHistory?.(rootID);
}
/// #if MOBILE
const toolbarEditor = getMobileToolbarProtyle();
diff --git a/app/src/protyle/util/destroy.ts b/app/src/protyle/util/destroy.ts
index 198652e220..fb422aac40 100644
--- a/app/src/protyle/util/destroy.ts
+++ b/app/src/protyle/util/destroy.ts
@@ -24,6 +24,7 @@ export const destroy = (protyle: IProtyle) => {
disposeSyncEditorSave(protyle);
destroyFoldedRender(protyle);
destroyListMindmaps(protyle);
+ protyle.breadcrumb?.destroy();
cancelLegacyMindmapMigration(protyle);
invalidateFocusFoldRequests(protyle);
unregisterViewFoldContext(protyle);
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index f0512d797f..9d35480747 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -597,9 +597,10 @@ export const disabledProtyle = (protyle: IProtyle) => {
if (undoElement && !undoElement.classList.contains("fn__none")) {
undoElement.classList.add("fn__none");
protyle.breadcrumb.element.parentElement.querySelector('[data-type="redo"]').classList.add("fn__none");
- protyle.breadcrumb.element.parentElement.querySelector('[data-type="indent"]').classList.add("fn__none");
- protyle.breadcrumb.element.parentElement.querySelector('[data-type="outdent"]').classList.add("fn__none");
+ protyle.breadcrumb.element.parentElement.querySelector('[data-type="indent"]')?.classList.add("fn__none");
+ protyle.breadcrumb.element.parentElement.querySelector('[data-type="outdent"]')?.classList.add("fn__none");
}
+ protyle.breadcrumb.refreshHistory?.(protyle.block.rootID);
}
hideTooltip();
};
@@ -671,9 +672,10 @@ export const enableProtyle = (protyle: IProtyle) => {
if (undoElement && undoElement.classList.contains("fn__none")) {
undoElement.classList.remove("fn__none");
protyle.breadcrumb.element.parentElement.querySelector('[data-type="redo"]').classList.remove("fn__none");
- protyle.breadcrumb.element.parentElement.querySelector('[data-type="indent"]').classList.remove("fn__none");
- protyle.breadcrumb.element.parentElement.querySelector('[data-type="outdent"]').classList.remove("fn__none");
+ protyle.breadcrumb.element.parentElement.querySelector('[data-type="indent"]')?.classList.remove("fn__none");
+ protyle.breadcrumb.element.parentElement.querySelector('[data-type="outdent"]')?.classList.remove("fn__none");
}
+ protyle.breadcrumb.refreshHistory?.(protyle.block.rootID);
}
hideElements(["gutter"], protyle);
hideTooltip();