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: Restore PDF outline expansion on icon clicks
Daniel77cb813cc401
diff --git a/app/src/asset/pdf/base_tree_viewer.js b/app/src/asset/pdf/base_tree_viewer.jsindex 0411074f81..950481736b 100644--- a/app/src/asset/pdf/base_tree_viewer.js+++ b/app/src/asset/pdf/base_tree_viewer.js@@ -31,6 +31,18 @@ class BaseTreeViewer {this._l10n = options.l10n;this.reset();+ this.container.addEventListener("click", e => {+ const target = e.target.closest(".treeItemToggler");+ if (!target || !this.container.contains(target)) {+ return;+ }+ stopEvent(e);+ target.classList.toggle("treeItemsHidden");+ if (e.shiftKey) {+ const shouldShowAll = !target.classList.contains("treeItemsHidden");+ this._toggleTreeItem(target.parentNode, shouldShowAll);+ }+ });}reset() {@@ -81,7 +93,7 @@ class BaseTreeViewer {_addToggleButton(div, hidden = false) {const toggler = document.createElement("div");// NOTE- toggler.innerHTML = `<svg><use xlink:href="#iconDown"></use></svg>`+ toggler.innerHTML = `<svg><use xlink:href="#iconDown"></use></svg>`;toggler.className = "treeItemToggler";if (hidden) {toggler.classList.add("treeItemsHidden");@@ -122,18 +134,6 @@ class BaseTreeViewer {if (hasAnyNesting) {this.container.classList.add("withNesting");this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");- this.container.addEventListener("click", e => {- const { target } = e;- if (!target.classList.contains("treeItemToggler")) {- return;- }- stopEvent(e);- target.classList.toggle("treeItemsHidden");- if (e.shiftKey) {- const shouldShowAll = !target.classList.contains("treeItemsHidden");- this._toggleTreeItem(target.parentNode, shouldShowAll);- }- });}// Pause translation when inserting the tree into the DOM.this._l10n.pause();diff --git a/app/tests/pdfOutlineButton.test.js b/app/tests/pdfOutlineButton.test.jsindex 182e50749b..db144cea2c 100644--- a/app/tests/pdfOutlineButton.test.js+++ b/app/tests/pdfOutlineButton.test.js@@ -72,6 +72,36 @@ const cases = async (moduleURL, runtimeURL, configSource, mobile) => {check.equal(sidebar.active, SidebarView.THUMBS, "a document without an outline falls back to thumbnails");check.equal(visible(), false);check.equal(button.disabled, true);+ const nestedOutline = [{title: "Chapter", dest: [0], count: -1, items: [+ {title: "Section", dest: [1], count: -1, items: [+ {title: "Subsection", dest: [2], items: []},+ ]},+ ]}];+ const destinations = [];+ outlineViewer.linkService.goToDestination = dest => destinations.push(dest);+ for (let render = 0; render < 2; render++) {+ outlineViewer.render({outline: nestedOutline, pdfDocument: {loadingParams: {disableAutoFetch: false}}});+ const togglers = [...content.querySelectorAll(".treeItemToggler")];+ const [chapter, section] = togglers;+ const children = chapter.parentNode.querySelector(".treeItems");+ const click = (element, shiftKey = false) => element.dispatchEvent(new MouseEvent("click", {bubbles: true, cancelable: true, shiftKey}));+ check.equal(children.checkVisibility(), false);+ click(chapter.querySelector("svg"));+ check.equal(children.checkVisibility(), true, "clicking the SVG expands the chapter");+ check.ok(section.classList.contains("treeItemsHidden"), "a normal click preserves nested state");+ click(chapter.querySelector("use"));+ check.equal(children.checkVisibility(), false, "clicking the SVG use element collapses the chapter");+ click(chapter);+ check.equal(children.checkVisibility(), true, "clicking the surrounding button toggles exactly once after rendering");+ click(chapter, true);+ check.ok(togglers.every(el => el.classList.contains("treeItemsHidden")), "shift-click collapses the subtree");+ click(chapter.querySelector("svg"), true);+ check.ok(togglers.every(el => !el.classList.contains("treeItemsHidden")), "shift-click on the icon expands the subtree");+ check.equal(destinations.length, render, "expanding the tree does not navigate");+ click(chapter.parentNode.querySelector("a"));+ check.deepEqual(destinations.at(-1), [0], "clicking the title still navigates");+ check.ok(togglers.every(el => !el.classList.contains("treeItemsHidden")), "navigation preserves expanded items");+ }return "PDF outline button cases passed";};