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: Improve pinned document interactions and automatic visibility https://github.com/siyuan-note/siyuan/issues/19401
Daniel754c357e77ff
diff --git a/app/src/assets/scss/component/_list.scss b/app/src/assets/scss/component/_list.scssindex 302d655f8a..7451fac9f9 100644--- a/app/src/assets/scss/component/_list.scss+++ b/app/src/assets/scss/component/_list.scss@@ -4,6 +4,11 @@.file-tree__pins {--file-toggle-width: 0px;padding-bottom: 2px;+ margin-bottom: 6px;++ [data-pin-heading] > .b3-list-item__icon:hover {+ background-color: transparent;+ }&.b3-list--background .b3-list-item.dragover__top::after {top: 0;diff --git a/app/src/config/entryVisibility/catalog.test.ts b/app/src/config/entryVisibility/catalog.test.tsindex 5aed7f8fdd..9acae41ee1 100644--- a/app/src/config/entryVisibility/catalog.test.ts+++ b/app/src/config/entryVisibility/catalog.test.ts@@ -865,7 +865,6 @@ test("multiple document and notebook entries follow their document tree menus","rebuildDataIndex","sort","publishAccess",- "pinnedDocs",]);assert.deepEqual(getEntryCatalogChildren("docTree.notebooks").map((item) => item.key), ["sort",@@ -884,14 +883,9 @@ test("multiple document and notebook entries follow their document tree menus",assert.ok(getEntryCatalogChildren("docTree.multi").some((item) => item.key === "delete"));});-test("pinned area visibility is independent of dock visibility and menu ordering", () => {- assert.deepEqual(getEntryCatalogChildren("documentPanel").map(item => item.key), ["pinnedDocs"]);- assert.equal(getEntryCatalogNode("documentPanel.pinnedDocs")?.simple, true);- assert.equal(getEntryCatalogDefaultVisibility("documentPanel.pinnedDocs"), false);- assert.equal(getEntryCatalogCustomDefaultVisibility("documentPanel.pinnedDocs"), false);- assert.equal(getEntryCatalogDefaultVisibility("docTree.panel.pinnedDocs"), true);- assert.equal(isEntryOrderSortable("documentPanel"), false);- assert.equal(getEntryCatalogNode("docTree.panel.pinnedDocs")?.simple, true);+test("pinned area has no configurable visibility switch", () => {+ assert.equal(getEntryCatalogNode("documentPanel.pinnedDocs"), undefined);+ assert.equal(getEntryCatalogNode("docTree.panel.pinnedDocs"), undefined);assert.equal(getEntryCatalogNode("dock.pinnedDocs"), undefined);});diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.tsindex 41980a1dd0..1f1f1264ec 100644--- a/app/src/config/entryVisibility/catalog.ts+++ b/app/src/config/entryVisibility/catalog.ts@@ -668,14 +668,6 @@ export const entryCatalog: IEntryCatalogSection[] = [topBarCatalogSection,statusBarCatalogSection,dockCatalogSection,- {- key: "documentPanel",- label: lang("entryDocPanel"),- sortable: false,- children: [node("pinnedDocs", lang("pinnedDocs"), true, undefined, undefined, {- defaultVisible: () => false,- })],- },{key: "docTree.panel",label: location(lang("entryDocPanel"), lang("more")),@@ -686,7 +678,6 @@ export const entryCatalog: IEntryCatalogSection[] = [node("rebuildDataIndex", lang("rebuildDataIndex")),node("sort", lang("sort"), true, sortChildren()),node("publishAccess", lang("publishAccess")),- node("pinnedDocs", lang("pinnedDocs")),],},{diff --git a/app/src/config/entryVisibility/order.test.ts b/app/src/config/entryVisibility/order.test.tsindex 2ffb2f7bc5..4c32d896fc 100644--- a/app/src/config/entryVisibility/order.test.ts+++ b/app/src/config/entryVisibility/order.test.ts@@ -40,17 +40,17 @@ test("pin entries merge into document menus without moving existing plugin slotsassert.deepEqual(resolveEntryOrder([...defaults, "plugin:example:item"], merged, separators), merged);});-test("pinned area switch merges into panel menus while preserving plugin slots", () => {+test("removed pinned area switch is not rendered while plugin slots are preserved", () => {const entries = getEntryCatalogChildren("docTree.panel");const defaults = entries.map(item => item.key);- const saved = defaults.filter(key => key !== "pinnedDocs");+ const saved = [...defaults, "pinnedDocs"];saved.splice(1, 0, "plugin:example:item");const merged = mergeEntryOrderPreservingUnknown(defaults, saved);assert.deepEqual(merged.filter(key => key !== "pinnedDocs" && key !== "plugin:example:item"),- saved.filter(key => key !== "plugin:example:item"));+ saved.filter(key => key !== "pinnedDocs" && key !== "plugin:example:item"));assert.equal(merged[1], "plugin:example:item");- assert.equal(merged[merged.length - 1], "pinnedDocs");- assert.deepEqual(resolveEntryOrder([...defaults, "plugin:example:item"], merged, new Set<string>()), merged);+ const rendered = resolveEntryOrder([...defaults, "plugin:example:item"], merged, new Set<string>());+ assert.deepEqual(rendered, saved.filter(key => key !== "pinnedDocs"));});test("entry order ignores unknown and duplicate keys", () => {diff --git a/app/src/config/entryVisibility/ui.ts b/app/src/config/entryVisibility/ui.tsindex 61bb4cfb2d..caec3ecaa1 100644--- a/app/src/config/entryVisibility/ui.ts+++ b/app/src/config/entryVisibility/ui.ts@@ -56,8 +56,8 @@ import {} from "./dockOrder";const getVisibleEntryCatalog = () => isMobile() ? entryCatalog.filter(item =>- item.key === TOOLBAR_ENTRY_ROOT_PATH || item.key === "documentPanel")- .map(item => item.key === "documentPanel" ? item : ({...item, children: item.children.filter(child => child.type === "separator" ||+ item.key === TOOLBAR_ENTRY_ROOT_PATH)+ .map(item => ({...item, children: item.children.filter(child => child.type === "separator" ||MOBILE_TOOLBAR_NAMES.includes(child.key) || child.key.startsWith("plugin:"))})) : entryCatalog;const renderTouchOrderButtons = (enabled: boolean) => isMobile() && enabled ? ["up", "down"].map(direction =>diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.tsindex ce8ea07b7b..fcf6034d62 100644--- a/app/src/emoji/index.ts+++ b/app/src/emoji/index.ts@@ -1616,6 +1616,9 @@ export const updateFileTreeEmoji = (unicode: string, id: string, icon = "iconFilif (liElement) {updateFileTreeItemIcon(liElement, unicode, isNotebookIcon ? "notebook" : undefined);}+ document.querySelectorAll<HTMLElement>(`.file-tree__pins [data-pin-row][data-node-id="${id}"]`).forEach(row => {+ updateFileTreeItemIcon(row, unicode);+ });};export const getEmojiDesc = (emoji: IEmojiItem) => {diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex 4b1c5f289d..d330c19b19 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -2245,14 +2245,6 @@ aria-label="${ariaLabel}">${getDocDisplayName(item.name, item.titleEmpty, true)}}}).element);}- window.siyuan.menus.menu.append(new MenuItem({- id: "pinnedDocs",- icon: "iconPin",- label: window.siyuan.languages.pinnedDocs,- checked: this.pinnedDocs.isVisible(),- disabled: window.siyuan.config.readonly,- click: () => this.pinnedDocs.toggleVisibility(),- }).element);return window.siyuan.menus.menu;}diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.tsindex 2ccb8f978f..0c5a20ff5e 100644--- a/app/src/layout/dock/PinnedDocs.test.ts+++ b/app/src/layout/dock/PinnedDocs.test.ts@@ -7,12 +7,18 @@ import * as ts from "typescript";interface IPanelHarness {element: unknown;- isVisible(): boolean;- toggleVisibility(): void;- applyVisibility(): void;+ refresh(): Promise<void>;+ list: unknown;+ generation: number;+ names: Map<string, string>;+ appendDoc(...args: unknown[]): Promise<void>;loadChildren(row: unknown, children: unknown, generation: number): Promise<void>;drop(ids: string[], x: number, y: number): Promise<void>;click(event: unknown): void;+ menu(row: unknown, x: number, y: number): void;+ toggle(row: unknown): void;+ open(id: string, notebook: string): void;+ mobile?: boolean;previewDrop(): void;clearDrop(): void;scheduleRefresh(): void;@@ -21,11 +27,12 @@ interface IPanelHarness {}const loadPanel = (fetchCode = 0) => {- let visible = true;+ const docs: {id: string, notebook: string, name: string}[] = [];+ const config = {readonly: false, fileTree: {docIconClickExpand: false, parentDocClickExpand: false}};const calls: {kind: string, args: unknown[]}[] = [];const record = (kind: string) => async (...args: unknown[]) => {calls.push({kind, args});- return {code: kind === "http" ? fetchCode : 0};+ return {code: kind === "http" ? fetchCode : 0, data: docs};};const exports: {PinnedDocs?: {prototype: object}} = {};const source = ts.transpileModule(readFileSync(join(__dirname, "PinnedDocs.ts"), "utf8"), {@@ -33,20 +40,20 @@ const loadPanel = (fetchCode = 0) => {}).outputText;runInNewContext(source, {exports,+ window: {siyuan: {config, notebooks: []}},+ document: {activeElement: null, createElement: () => ({+ dataset: {}, children: [] as unknown[],+ append(child: unknown) { this.children.push(child); },+ })},require: (name: string) => {- if (name.endsWith("/entryVisibility/runtime")) {- return {- getConfiguredEntryVisibility: (path: string) => {- assert.equal(path, "documentPanel.pinnedDocs");- return visible;- },- setEntryVisibilityValue: (path: string, value: boolean) => {- assert.equal(path, "documentPanel.pinnedDocs");- visible = value;- },- };+ if (name.endsWith("/emoji")) { return {openEmojiPanel: record("icon")}; }+ if (name.endsWith("/navigation")) {+ return {initFileMenu: (...args: unknown[]) => {+ calls.push({kind: "menu", args});+ return {popup: record("popup"), fullscreen: record("fullscreen")};+ }};}- if (name.endsWith("/pinnedDocs")) { return {updatePinnedDocs: record("pin")}; }+ if (name.endsWith("/pinnedDocs")) { return {updatePinnedDocs: record("pin"), pinnedDocIDs: new Set<string>()}; }if (name.endsWith("/fetch")) { return {fetchSyncPost: record("http")}; }if (name.endsWith("/fileTreeReorder")) { return {reorderSortedFileTree: record("reorder")}; }return {};@@ -55,9 +62,46 @@ const loadPanel = (fetchCode = 0) => {const panel = Object.create(exports.PinnedDocs.prototype) as IPanelHarness;panel.clearDrop = () => { panel.dropTarget = undefined; };panel.scheduleRefresh = () => {};- return {panel, calls};+ return {panel, calls, config, docs};};+test("pinned document more actions open the source document menu", () => {+ const {panel, calls} = loadPanel();+ const row = {dataset: {nodeId: "document", notebook: "notebook", path: "/document.sy"}};+ panel.click({+ stopPropagation: () => {}, clientX: 10, clientY: 20,+ target: {closest: (selector: string) => selector === "[data-pin-row]" || selector === "[data-pin-more]" ? row : null},+ });+ assert.equal(calls[0].kind, "menu");+ assert.deepEqual(calls[0].args.slice(1), ["notebook", "/document.sy", row]);+ assert.equal(calls[1].kind, "popup");+ panel.mobile = true;+ panel.menu(row, 10, 20);+ assert.equal(calls[3].kind, "fullscreen");+});++test("pinned icons respect editing, expansion and readonly settings", () => {+ const {panel, calls, config} = loadPanel();+ const row = {dataset: {nodeId: "document", notebook: "notebook", count: "1"}};+ const icon = {getBoundingClientRect: () => ({left: 1, bottom: 2, height: 3, width: 4}), querySelector: (): Element | null => null};+ const event = {stopPropagation: () => {}, target: {closest: (selector: string) =>+ selector === "[data-pin-row]" ? row : selector === ".b3-list-item__icon" ? icon : null}};+ panel.click(event);+ assert.equal(calls[0].kind, "icon");+ assert.deepEqual(calls[0].args.slice(0, 2), ["document", "doc"]);+ config.readonly = true;+ panel.click(event);+ assert.equal(calls.length, 1);+ config.fileTree.docIconClickExpand = true;+ panel.toggle = () => { calls.push({kind: "toggle", args: []}); };+ panel.open = () => { calls.push({kind: "open", args: []}); };+ panel.click(event);+ assert.equal(calls[1].kind, "toggle");+ row.dataset.count = "0";+ panel.click(event);+ assert.equal(calls[2].kind, "open");+});+test("root drops create an entry without invoking source movement", async () => {const {panel, calls} = loadPanel();panel.previewDrop = () => { panel.dropTarget = {id: "parent", position: "pin-before"}; };@@ -109,19 +153,25 @@ test("notebook root expansion requests physical root while documents keep theirassert.equal(JSON.stringify(calls[1].args[1]), JSON.stringify({notebook: "notebook", path: "/document.sy", maxListCount: 0}));});-test("hiding and restoring the pinned area changes visibility without mutating pins", () => {- const {panel, calls} = loadPanel();+test("pinned area follows list contents on initial load, pin, unpin and sync", async () => {+ const {panel, calls, docs} = loadPanel();const states: boolean[] = [];+ panel.generation = 0;+ panel.names = new Map();+ panel.appendDoc = async () => {};+ panel.list = {parentElement: {scrollTop: 0}, contains: () => false,+ querySelectorAll: (): unknown[] => [], replaceChildren: () => {}};panel.element = {classList: {toggle: (name: string, hidden: boolean) => {assert.equal(name, "fn__none");states.push(hidden);}}};- panel.applyVisibility();- panel.toggleVisibility();- assert.equal(panel.isVisible(), false);- panel.applyVisibility();- panel.toggleVisibility();- panel.applyVisibility();- assert.deepEqual(states, [false, true, false]);- assert.equal(calls.length, 0);+ await panel.refresh();+ docs.push({id: "document", notebook: "notebook", name: "Document"});+ await panel.refresh();+ docs.length = 0;+ await panel.refresh();+ docs.push({id: "synced", notebook: "notebook", name: "Synced"});+ await panel.refresh();+ assert.deepEqual(states, [true, false, true, false]);+ assert.ok(calls.every(call => call.kind === "http" && call.args[0] === "/api/filetree/getPinnedDocs"));});diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.tsindex 3fb5e00188..2fefa58b5f 100644--- a/app/src/layout/dock/PinnedDocs.ts+++ b/app/src/layout/dock/PinnedDocs.ts@@ -4,6 +4,7 @@ import {fetchSyncPost} from "../../util/fetch";import {pinnedDocIDs, updatePinnedDocs} from "../../util/pinnedDocs";import {getPinnedDropPosition} from "../../util/pinnedDocsDrop";import {getFileTreeIconHTML} from "../../emoji/fileTreeIcon";+import {openEmojiPanel} from "../../emoji";import {escapeHtml} from "../../util/escape";import {initFileMenu} from "../../menus/navigation";import {parseDocumentTabDragData, parseDocumentTreeDragData} from "../../util/fileTreeMove";@@ -12,7 +13,6 @@ import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragovimport {MenuItem} from "../../menus/Menu";import {newFileInTree} from "../../util/newFile";import {FILE_TREE_CHILDREN_SORT_MODE, FILE_TREE_EFFECTIVE_SORT_MODE} from "../../util/fileTreeSort";-import {getConfiguredEntryVisibility, setEntryVisibilityValue} from "../../config/entryVisibility/runtime";interface IPinnedDoc {id: string;@@ -43,16 +43,11 @@ export class PinnedDocs {constructor(private app: App, private sourceTree: HTMLElement, private open: (id: string, notebook: string) => void,private mobile = false) {this.element = document.createElement("div");- this.element.className = "file-tree__pins b3-list--background fn__flex-column";+ this.element.className = "file-tree__pins b3-list--background fn__flex-column fn__none";this.element.style.cssText = "flex-shrink:0;max-height:40%;min-height:30px;overflow:hidden;border-bottom:1px solid var(--b3-border-color)";- this.element.innerHTML = `<button class="b3-list-item" type="button" data-pin-heading="true"><span class="b3-list-item__toggle"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__text">${window.siyuan.languages.pinnedDocs}</span></button><div class="fn__flex-1" style="overflow:auto;min-height:0"><ul class="b3-list"></ul></div>`;+ this.element.innerHTML = `<button class="b3-list-item" type="button" data-pin-heading="true"><span class="b3-list-item__toggle"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon"><svg><use xlink:href="#iconPin"></use></svg></span><span class="b3-list-item__text">${window.siyuan.languages.pinnedDocs}</span></button><div class="fn__flex-1" style="overflow:auto;min-height:0"><ul class="b3-list"></ul></div>`;this.list = this.element.lastElementChild.firstElementChild as HTMLElement;sourceTree.before(this.element);- this.applyVisibility();- window.addEventListener("siyuan-entry-visibility", () => {- this.applyVisibility();- this.scheduleRefresh();- }, {signal: this.sourceEvents.signal});try {this.expanded = new Set(JSON.parse(localStorage.getItem("siyuan-pinned-docs-expanded") || "[]"));} catch (e) {@@ -140,18 +135,6 @@ export class PinnedDocs {this.sourceEvents.abort();}- public isVisible() {- return getConfiguredEntryVisibility("documentPanel.pinnedDocs");- }-- public toggleVisibility() {- setEntryVisibilityValue("documentPanel.pinnedDocs", !this.isVisible());- }-- private applyVisibility() {- this.element.classList.toggle("fn__none", !this.isVisible());- }-public scheduleRefresh() {window.clearTimeout(this.refreshTimer);this.refreshTimer = window.setTimeout(() => this.refresh(), 150);@@ -177,7 +160,6 @@ export class PinnedDocs {const selected = new Set(Array.from(this.list.querySelectorAll<HTMLElement>(".b3-list-item--focus"), row => row.dataset.pinRow));pinnedDocIDs.clear();response.data.forEach(doc => pinnedDocIDs.add(doc.id));- if (!this.isVisible()) { return; }const list = document.createElement("ul");for (const doc of response.data) {if (doc.unavailable) {@@ -187,11 +169,13 @@ export class PinnedDocs {}const wrapper = document.createElement("ul");wrapper.dataset.url = doc.notebook;+ wrapper.dataset.sortmode = String(window.siyuan.notebooks.find(notebook => notebook.id === doc.notebook)?.sortMode ?? 15);list.append(wrapper);await this.appendDoc(wrapper, doc, doc.id, 0, generation);}if (generation === this.generation && !this.disposed) {this.list.replaceChildren(...Array.from(list.children));+ this.element.classList.toggle("fn__none", response.data.length === 0);this.list.querySelectorAll<HTMLElement>("[data-pin-row]").forEach(row => {row.classList.toggle("b3-list-item--focus", selected.has(row.dataset.pinRow));if (row.dataset.pinRow === focused) { row.focus({preventScroll: true}); }@@ -215,10 +199,15 @@ export class PinnedDocs {row.dataset.unavailable = String(Boolean(doc.unavailable));row.draggable = !doc.unavailable && !window.siyuan.config.readonly;row.tabIndex = 0;- row.style.paddingLeft = `${depth * (this.mobile ? 20 : 18)}px`;+ const paddingLeft = (depth + 1) * (this.mobile ? 20 : 18);+ row.style.setProperty("--file-toggle-width", `${paddingLeft + 18}px`);+ row.style.setProperty("--file-action-offset", `${paddingLeft + 20}px`);row.setAttribute("aria-disabled", String(Boolean(doc.unavailable)));if (doc.subFileCount) { row.setAttribute("aria-expanded", "false"); }- row.innerHTML = `<span data-pin-toggle="true" class="b3-list-item__toggle${doc.subFileCount ? "" : " fn__hidden"}"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon">${getFileTreeIconHTML(doc.icon, doc.subFileCount ? "folder" : "file")}</span><span class="b3-list-item__text">${escapeHtml(doc.name)}${doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : ""}</span><span data-pin-more="true" class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>`;+ const iconExpands = this.mobile || window.siyuan.config.fileTree.docIconClickExpand;+ const iconLabel = iconExpands ? (doc.subFileCount ? window.siyuan.languages.docIconClickExpand : window.siyuan.languages.openDocument) : window.siyuan.languages.changeIcon;+ if (!doc.icon) { row.dataset.defaultIcon = doc.subFileCount ? "folder" : "file"; }+ row.innerHTML = `<span data-pin-toggle="true" style="padding-left:${paddingLeft}px" class="b3-list-item__toggle b3-list-item__toggle--hl${doc.subFileCount ? "" : " fn__hidden"}"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon ariaLabel" data-position="8east" aria-label="${iconLabel}">${getFileTreeIconHTML(doc.icon, doc.subFileCount ? "folder" : "file")}</span><span class="b3-list-item__text">${escapeHtml(doc.name)}${doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : ""}</span><span data-pin-more="true" class="b3-list-item__action" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`;if (!doc.unavailable && !window.siyuan.config.readonly) {const add = document.createElement("span");add.className = "b3-list-item__action";@@ -300,7 +289,20 @@ export class PinnedDocs {newFileInTree(this.app, row.dataset.notebook, row.dataset.path);} else if (target.closest("[data-pin-toggle]")) {this.toggle(row);+ } else if (target.closest(".b3-list-item__icon") && row.dataset.unavailable !== "true") {+ if (this.mobile || window.siyuan.config.fileTree.docIconClickExpand) {+ if (Number(row.dataset.count) > 0) { this.toggle(row); } else { this.open(row.dataset.nodeId, row.dataset.notebook); }+ } else if (!window.siyuan.config.readonly) {+ const icon = target.closest<HTMLElement>(".b3-list-item__icon");+ const rect = icon.getBoundingClientRect();+ openEmojiPanel(row.dataset.nodeId, "doc", {x: rect.left, y: rect.bottom, h: rect.height, w: rect.width},+ undefined, icon.querySelector("img"));+ }} else if (row.dataset.unavailable !== "true") {+ if (window.siyuan.config.fileTree.parentDocClickExpand && Number(row.dataset.count) > 0) {+ this.toggle(row);+ return;+ }this.list.querySelectorAll(".b3-list-item--focus").forEach(item => item.classList.remove("b3-list-item--focus"));row.classList.add("b3-list-item--focus");this.open(row.dataset.nodeId, row.dataset.notebook);diff --git a/app/src/util/fileTreeSort.test.ts b/app/src/util/fileTreeSort.test.tsindex 200de37ff9..05d95766bd 100644--- a/app/src/util/fileTreeSort.test.ts+++ b/app/src/util/fileTreeSort.test.ts@@ -41,6 +41,18 @@ const elementWithAttrs = (attrs: Record<string, string>, notebookSortMode = "15"}),}) as unknown as Element;+test("pinned lists without a notebook sort ancestor fall back to global sorting", () => {+ withWindow(() => {+ const list = {+ getAttribute: (): string | null => null,+ closest: (): Element | null => null,+ } as unknown as Element;+ assert.equal(getFileTreeListSortMode(list), 6);+ assert.equal(isCustomFileTreeList(list), true);+ assert.equal(getConfiguredChildrenSortMode(list), null);+ });+});+interface ITreeElement {tagName: string;attrs: Record<string, string>;diff --git a/app/src/util/fileTreeSort.ts b/app/src/util/fileTreeSort.tsindex e7b753fc23..68791cc3c5 100644--- a/app/src/util/fileTreeSort.ts+++ b/app/src/util/fileTreeSort.ts@@ -16,8 +16,8 @@ export interface IFileTreeSortRefreshTarget {path: string;}-const parseSortMode = (value: string | null) => {- if (value === null || value.trim() === "") {+const parseSortMode = (value: string | null | undefined) => {+ if (typeof value !== "string" || value.trim() === "") {return;}const sortMode = Number(value);diff --git a/app/src/util/pinnedDocs.ts b/app/src/util/pinnedDocs.tsindex b29971ec20..3bcd3493ec 100644--- a/app/src/util/pinnedDocs.ts+++ b/app/src/util/pinnedDocs.ts@@ -1,12 +1,6 @@import {fetchSyncPost} from "./fetch";-import {getConfiguredEntryVisibility, setEntryVisibilityValue} from "../config/entryVisibility/runtime";export const pinnedDocIDs = new Set<string>();-export const updatePinnedDocs = async (ids: string[], action: "pin" | "unpin", targetID = "", after = false) => {- const response = await fetchSyncPost("/api/filetree/updatePinnedDocs", {ids, action, targetID, after});- if (response.code === 0 && action === "pin" && !getConfiguredEntryVisibility("documentPanel.pinnedDocs")) {- setEntryVisibilityValue("documentPanel.pinnedDocs", true);- }- return response;-};+export const updatePinnedDocs = (ids: string[], action: "pin" | "unpin", targetID = "", after = false) =>+ fetchSyncPost("/api/filetree/updatePinnedDocs", {ids, action, targetID, after});diff --git a/docs/PINNED-DOCUMENTS.md b/docs/PINNED-DOCUMENTS.mdindex 7a121b09d2..f11093ceac 100644--- a/docs/PINNED-DOCUMENTS.md+++ b/docs/PINNED-DOCUMENTS.md@@ -1,4 +1,4 @@-# Pinned documents in the document tree+# Pinned documents in the document panel[中文](PINNED-DOCUMENTS.zh-CN.md)@@ -6,15 +6,17 @@ Related issue: https://github.com/siyuan-note/siyuan/issues/19401## Feature scope-The pinned section appears at the top of the document tree panel and uses pinned documents as roots for their actual child documents. Root entry order is independent of document hierarchy and source-document sorting. Expanded children use source-document data directly. Desktop and mobile clients share the implementation. The section can collapse, has a maximum height, and scrolls independently.+The pinned section appears at the top of the document panel and uses pinned documents as roots for their actual child documents. Root entry order is independent of document hierarchy and source-document sorting. Expanded children use source-document data directly. Desktop and mobile clients share the implementation. The section can collapse, has a maximum height, and scrolls independently.## User interaction-The section is hidden by default. Enable it through Document panel - More - Pinned or the document-panel group in entry visibility settings, including on mobile. Successfully pinning a document explicitly enables the section and saves that setting. A failed pin, unpin, or incoming synchronized pin data does not change visibility. Hiding the section removes its layout space without unpinning documents or resetting order or expansion state. Showing it again refreshes source-document data. Visibility uses the independent configuration identifier `documentPanel.pinnedDocs`, separate from dock-icon and menu-item visibility, and preserves the user's saved choice.+The section appears when it contains pinned documents and hides automatically when empty, on both desktop and mobile. Pin the first document through its context menu; once the section is visible, documents can also be added by dragging. Unpinning the last document hides the section. Incoming synchronized pin data updates visibility in the same way. There is no separate visibility switch, and previously saved visibility settings no longer affect the section. Collapsing the section preserves its entries and their order.| Operation | Behavior ||---|---|| Pin from a menu | Insert the entry at the top; the same menu item becomes Unpin for an already pinned document |+| Context menu or More on a pinned document | Open the document menu, including Unpin and Rename |+| Click a document icon | On desktop, open the icon picker or follow the configured icon expansion behavior; mobile expands or opens the document || Drop on a root insertion line | Create or reorder a pinned entry without moving the source document || Drop between child documents | Reorder actual documents, using the existing sort-conflict confirmation || Drop in the middle of a document row | Move into the actual document, using existing move validation |diff --git a/docs/PINNED-DOCUMENTS.zh-CN.md b/docs/PINNED-DOCUMENTS.zh-CN.mdindex 31cd454b22..fed43bc335 100644--- a/docs/PINNED-DOCUMENTS.zh-CN.md+++ b/docs/PINNED-DOCUMENTS.zh-CN.md@@ -1,4 +1,4 @@-# 文档树面板置顶区+# 文档面板置顶区[English](PINNED-DOCUMENTS.md)@@ -6,15 +6,17 @@## 功能范围-置顶区位于文档树面板顶部,以置顶文档为根展示真实子文档。根入口的顺序独立于文档层级和源文档排序;展开后的子文档直接使用源文档数据。桌面端和移动端共享置顶区实现,区域可折叠并限制最大高度,内部独立滚动。+置顶区位于文档面板顶部,以置顶文档为根展示真实子文档。根入口的顺序独立于文档层级和源文档排序;展开后的子文档直接使用源文档数据。桌面端和移动端共享置顶区实现,区域可折叠并限制最大高度,内部独立滚动。## 用户交互-置顶区域默认隐藏,可通过文档面板 - 更多 - 置顶开启,界面显隐配置中的文档面板分组也可调整该开关,包括移动端。用户主动置顶文档成功后自动开启置顶区域并保存开关状态;置顶失败、取消置顶或同步收到置顶数据时不改变该开关。隐藏时不占用布局空间,不取消任何置顶,也不重置顺序或展开状态;重新显示后刷新源文档数据。区域显隐使用独立配置标识 `documentPanel.pinnedDocs`,与侧栏图标显隐及菜单项显隐分别保存,保留用户明确保存的显隐选择。+桌面端和移动端均在有置顶文档时显示置顶区域,没有时自动隐藏。首个置顶通过文档菜单创建,区域显示后也可通过拖拽添加。取消最后一个置顶后区域自动隐藏,同步收到的置顶列表也按相同规则更新显隐。没有独立显隐开关,已保存的旧显隐配置不再影响该区域。折叠区域会保留置顶文档及其顺序。| 操作 | 行为 ||---|---|| 菜单置顶 | 新入口放在最顶部;已置顶时同一菜单项切换为取消置顶 |+| 置顶文档右键或更多 | 打开文档菜单,支持取消置顶、重命名等操作 |+| 点击文档图标 | 桌面端打开图标选择器,或遵循已配置的图标展开行为;移动端展开或打开文档 || 根层插入线拖放 | 创建或调整置顶入口,源文档位置不变 || 子文档之间插入线拖放 | 调整真实文档顺序,沿用现有排序冲突确认 || 拖放到文档行中部 | 移入真实文档,沿用现有移动校验 |