An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Clear table selection when toggling read-only mode https://github.com/siyuan-note/siyuan/issues/20463
Daniel718ffa710006
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex fbd7682f1c..21f6cb9967 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -556,6 +556,10 @@ export const disabledProtyle = (protyle: IProtyle) => {window.siyuan.menus.menu.remove();hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);protyle.disabled = true;+ if (!wasDisabled) {+ protyle.wysiwyg.tableControl?.clear();+ protyle.wysiwyg.element.querySelectorAll(".table__select").forEach(item => item.removeAttribute("style"));+ }protyle.databaseAttributePanel?.updateReadonly();if (protyle.title && protyle.title.editElement) {protyle.title.editElement.setAttribute("contenteditable", "false");@@ -599,6 +603,10 @@ export const enableProtyle = (protyle: IProtyle) => {}/// #endifprotyle.disabled = false;+ if (wasDisabled) {+ protyle.wysiwyg.tableControl?.clear();+ protyle.wysiwyg.element.querySelectorAll(".table__select").forEach(item => item.removeAttribute("style"));+ }protyle.databaseAttributePanel?.updateReadonly();if (isMobile()) {/// #if MOBILEdiff --git a/app/src/protyle/util/onGetReadonlyBars.test.ts b/app/src/protyle/util/onGetReadonlyBars.test.tsindex 2d4f709739..c1a61551f7 100644--- a/app/src/protyle/util/onGetReadonlyBars.test.ts+++ b/app/src/protyle/util/onGetReadonlyBars.test.ts@@ -15,6 +15,8 @@ for (const enable of [false, true]) {let state = {...createMobileBarsState(300), readingBarsOffset: 12};let pauses = 0;let layoutChanges = 0;+ let tableClears = 0;+ let legacyClears = 0;const changeLayout = () => {layoutChanges++;state = reduceMobileBarsState(state, {type: "scroll", scrollTop: state.scrollTop + 6});@@ -23,7 +25,14 @@ for (const enable of [false, true]) {disabled: enable,element: {getAttribute: (): null => null},databaseAttributePanel: {updateReadonly: changeLayout},- wysiwyg: {element: {setAttribute() {}, style: {}, querySelectorAll: (): HTMLElement[] => []}},+ wysiwyg: {+ tableControl: {clear: () => tableClears++},+ element: {+ setAttribute() {}, style: {},+ querySelectorAll: (selector: string) => selector === ".table__select" ?+ [{removeAttribute: (name: string) => { assert.equal(name, "style"); legacyClears++; }}] : [],+ },+ },};const exports: {enable?: () => void, disable?: () => void} = {};runInNewContext(code + "\nexports.enable = () => enableProtyle(protyle);" +@@ -40,10 +49,14 @@ for (const enable of [false, true]) {});(enable ? exports.enable : exports.disable)();assert.equal(layoutChanges, 1);+ assert.equal(tableClears, 1, "readonly transition clears managed table selection and pending drags");+ assert.equal(legacyClears, 1, "readonly transition clears the legacy table rectangle");assert.equal(pauses, current ? 1 : 0);assert.equal(state.readingBarsOffset, current ? 12 : 18);(enable ? exports.enable : exports.disable)();assert.equal(pauses, current ? 1 : 0, "unchanged readonly state does not restart the pause");+ assert.equal(tableClears, 1, "unchanged readonly state preserves subsequent selections");+ assert.equal(legacyClears, 1);if (current) {state = reduceMobileBarsState(state, {type: "set-programmatic-scrolling", active: false});state = reduceMobileBarsState(state, {type: "scroll", scrollTop: state.scrollTop + 10});