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: Align pinned document selection behavior https://github.com/siyuan-note/siyuan/issues/19401
Daniel9368dc3b6177
diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex 83f75cf327..20c80f1857 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -1944,6 +1944,7 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"if (!target) {return;}+ this.pinnedDocs.clearSelection();this.element.querySelectorAll("li.b3-list-item--focus").forEach((liItem) => {liItem.classList.remove("b3-list-item--focus");});diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.tsindex 0c1fff4934..49928cc67d 100644--- a/app/src/layout/dock/PinnedDocs.test.ts+++ b/app/src/layout/dock/PinnedDocs.test.ts@@ -8,6 +8,8 @@ import * as ts from "typescript";interface IPanelHarness {element: unknown;heading: unknown;+ sourceTree: unknown;+ clearSelection(): void;refresh(): Promise<void>;collapse(): void;expanded: Set<string>;@@ -53,6 +55,7 @@ const loadPanel = (fetchCode = 0) => {append(child: unknown) { this.children.push(child); },})},require: (name: string) => {+ if (name.endsWith("/compatibility")) { return {isOnlyMeta: (event: MouseEvent) => Boolean(event.ctrlKey)}; }if (name.endsWith("/fileTreeIcon")) { return {getFileTreeIconHTML: () => ""}; }if (name.endsWith("/escape")) { return {escapeHtml: (value: string) => value}; }if (name.endsWith("/emoji")) { return {openEmojiPanel: record("icon")}; }@@ -71,6 +74,8 @@ const loadPanel = (fetchCode = 0) => {const panel = Object.create(exports.PinnedDocs.prototype) as IPanelHarness;panel.clearDrop = () => { panel.dropTarget = undefined; };panel.scheduleRefresh = () => {};+ panel.list = {querySelectorAll: (): unknown[] => []};+ panel.sourceTree = {querySelectorAll: (): unknown[] => []};return {panel, calls, config, docs, storage};};@@ -134,7 +139,7 @@ test("pinned roots share one list and retain each document notebook without wraptest("pinned icons respect editing, expansion and readonly settings", () => {const {panel, calls, config} = loadPanel();- const row = {dataset: {nodeId: "document", notebook: "notebook", count: "1"}};+ const row = {dataset: {nodeId: "document", notebook: "notebook", count: "1"}, classList: {add: () => {}}};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}};@@ -196,6 +201,32 @@ test("panel clicks never bubble into the mobile source tree handler", () => {assert.equal(prevented, 1);});+test("modifier clicks toggle pins without opening and ordinary clicks clear source selection", () => {+ const {panel} = loadPanel();+ let focused = true;+ let opened = 0;+ let sourceCleared = 0;+ const row = {dataset: {nodeId: "doc", notebook: "box"}, classList: {+ toggle: () => { focused = !focused; }, add: () => { focused = true; }, remove: () => { focused = false; },+ }, removeAttribute: () => {}};+ panel.list = {querySelectorAll: () => [row]};+ panel.sourceTree = {querySelectorAll: () => [{classList: {remove: () => sourceCleared++}, removeAttribute: () => {}}]};+ panel.open = () => opened++;+ const event = {ctrlKey: true, stopPropagation: () => {}, preventDefault: () => {},+ target: {closest: (selector: string) => selector === "[data-pin-row]" ? row : null}};+ panel.click(event);+ assert.equal(focused, false);+ panel.click(event);+ assert.equal(focused, true);+ assert.equal(opened, 0);+ event.ctrlKey = false;+ panel.click(event);+ assert.equal(opened, 1);+ assert.equal(sourceCleared, 1);+ panel.clearSelection();+ assert.equal(focused, false);+});+test("notebook root expansion requests physical root while documents keep their own paths", async () => {const {panel, calls} = loadPanel(-1);for (const id of ["notebook", "document"]) {diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.tsindex c933f04571..16d45d81c3 100644--- a/app/src/layout/dock/PinnedDocs.ts+++ b/app/src/layout/dock/PinnedDocs.ts@@ -12,6 +12,7 @@ import {reorderSortedFileTree} from "../../util/fileTreeReorder";import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragover";import {MenuItem} from "../../menus/Menu";import {newFileInTree} from "../../util/newFile";+import {isOnlyMeta} from "../../protyle/util/compatibility";import {FILE_TREE_CHILDREN_SORT_MODE, FILE_TREE_EFFECTIVE_SORT_MODE} from "../../util/fileTreeSort";interface IPinnedDoc {@@ -294,6 +295,24 @@ export class PinnedDocs {localStorage.setItem("siyuan-pinned-docs-expanded", JSON.stringify([...this.expanded]));}+ public clearSelection() {+ this.list.querySelectorAll(".b3-list-item--focus").forEach(item => {+ item.classList.remove("b3-list-item--focus");+ item.removeAttribute("select-start");+ item.removeAttribute("select-end");+ });+ }++ private selectRow(row: HTMLElement) {+ this.clearSelection();+ this.sourceTree.querySelectorAll(".b3-list-item--focus").forEach(item => {+ item.classList.remove("b3-list-item--focus");+ item.removeAttribute("select-start");+ item.removeAttribute("select-end");+ });+ row.classList.add("b3-list-item--focus");+ }+private click(event: MouseEvent) {event.stopPropagation();if (this.suppressClick) { event.preventDefault(); return; }@@ -306,6 +325,11 @@ export class PinnedDocs {}const row = target.closest<HTMLElement>("[data-pin-row]");if (!row) { return; }+ if (isOnlyMeta(event) && !event.altKey && !event.shiftKey) {+ event.preventDefault();+ row.classList.toggle("b3-list-item--focus");+ return;+ }if (target.closest("[data-pin-more]")) {this.menu(row, event.clientX, event.clientY);} else if (target.closest("[data-pin-new]")) {@@ -314,6 +338,7 @@ export class PinnedDocs {this.toggle(row);} else if (target.closest(".b3-list-item__icon") && row.dataset.unavailable !== "true") {if (this.mobile || window.siyuan.config.fileTree.docIconClickExpand) {+ this.selectRow(row);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");@@ -322,12 +347,11 @@ export class PinnedDocs {undefined, icon.querySelector("img"));}} else if (row.dataset.unavailable !== "true") {+ this.selectRow(row);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/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.tsindex 584f1c3b7e..91fc431fce 100644--- a/app/src/mobile/dock/MobileFiles.ts+++ b/app/src/mobile/dock/MobileFiles.ts@@ -1403,6 +1403,7 @@ export class MobileFiles extends Model {if (!target) {return;}+ this.pinnedDocs.clearSelection();this.element.querySelectorAll("li.b3-list-item--focus").forEach((liItem) => {liItem.classList.remove("b3-list-item--focus");});