An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve backlink document title visibility https://github.com/siyuan-note/siyuan/issues/13679
Danielcd4591310246
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex 0ed34760a9..50f2899c0e 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -420,13 +420,30 @@.sy__backlink {> .backlinkList,> .backlinkMList {- > .b3-list > .b3-list-item > .counter {- background-color: transparent;- color: var(--b3-theme-on-surface-light);-- &:hover {- background-color: transparent;- color: var(--b3-theme-on-surface-light);+ > .b3-list > .backlinkList__item {+ display: flow-root;+ position: relative;++ > .b3-list-item {+ background-color: var(--b3-theme-background);+ position: sticky;+ top: 0;+ z-index: 6; // 需高于编辑器内固定表头及高亮层,低于工具栏++ &:hover:not(.b3-list-item--focus):not(.dragover):not(.dragover__current):not(.dragover__top):not(.dragover__bottom),+ &.b3-list-item--focus {+ background-image: linear-gradient(var(--b3-list-hover), var(--b3-list-hover));+ }++ > .counter {+ background-color: transparent;+ color: var(--b3-theme-on-surface-light);++ &:hover {+ background-color: transparent;+ color: var(--b3-theme-on-surface-light);+ }+ }}}}@@ -496,7 +513,7 @@min-height: auto;overflow: visible;- > .b3-list > .b3-list-item {+ > .b3-list > .backlinkList__item > .b3-list-item {margin-left: 0;> .b3-list-item__toggle {diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 8cee949103..63a07fd789 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -1109,6 +1109,32 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {event.preventDefault();return true;}+ if (activeItemElement.closest(".backlinkList__item")) {+ if (event.key === "ArrowLeft") {+ event.preventDefault();+ return true;+ }+ if (event.key === "ArrowDown" || event.key === "ArrowRight" || event.key === "ArrowUp") {+ const itemElements = backlinkModel.getDocumentItemElements(tree);+ const currentIndex = itemElements.indexOf(activeItemElement as HTMLLIElement);+ const nextIndex = currentIndex + (event.key === "ArrowUp" ? -1 : 1);+ const nextElement = itemElements[nextIndex];+ if (nextElement) {+ activeItemElement.classList.remove("b3-list-item--focus");+ nextElement.classList.add("b3-list-item--focus");+ const nextRect = nextElement.getBoundingClientRect();+ const scrollElement = backlinkModel.getScrollElement(tree);+ const scrollRect = scrollElement.getBoundingClientRect();+ if (nextRect.top < scrollRect.top) {+ scrollElement.scrollTop += nextRect.top - scrollRect.top;+ } else if (nextRect.bottom > scrollRect.bottom) {+ scrollElement.scrollTop += nextRect.bottom - scrollRect.bottom;+ }+ }+ event.preventDefault();+ return true;+ }+ }const ulElement = hasClosestByClassName(activeItemElement, "b3-list");if (!ulElement) {return false;diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.tsindex b7172c2486..e5c37864c8 100644--- a/app/src/layout/dock/Backlink.ts+++ b/app/src/layout/dock/Backlink.ts@@ -26,6 +26,7 @@ import {interface IBacklinkItemRecord {revision: string,+ containerElement: HTMLDivElement,headerElement: HTMLLIElement,editor?: Protyle,contextRevision?: string,@@ -341,11 +342,7 @@ export class Backlink extends Model {this.updateBottomBacklinkSpacing();});this.element.querySelector('[data-type="expand"]').addEventListener("click", () => {- Array.from(this.tree.element.firstElementChild.children).forEach((item: HTMLElement) => {- if (item.tagName === "LI" && !item.querySelector(".b3-list-item__arrow--open")) {- this.toggleItem(item, false);- }- });+ this.expandDocumentItems(this.tree, false);});this.element.addEventListener("click", (event) => {let target = event.target as HTMLElement;@@ -363,11 +360,7 @@ export class Backlink extends Model {event.stopPropagation();break;case "mExpand":- Array.from(this.mTree.element.firstElementChild.children).forEach((item: HTMLElement) => {- if (item.tagName === "LI" && !item.querySelector(".b3-list-item__arrow--open")) {- this.toggleItem(item, true);- }- });+ this.expandDocumentItems(this.mTree, true);event.stopPropagation();break;case "mCollapse":@@ -631,7 +624,7 @@ export class Backlink extends Model {}const docId = liElement.getAttribute("data-node-id");const record = this.itemRecords[isMention ? 1 : 0].get(docId);- const editor = record?.editor || this.editors.find(item => item.protyle.element === liElement.nextElementSibling);+ const editor = record?.editor;if (svgElement.classList.contains("b3-list-item__arrow--open")) {svgElement.classList.remove("b3-list-item__arrow--open");if (record) {@@ -659,6 +652,29 @@ export class Backlink extends Model {}}+ private expandDocumentItems(tree: Tree, isMention: boolean) {+ const listElement = tree.element;+ const folded = this.type === "bottom" ?+ listElement.classList.contains("fn__none") :+ (isMention ? listElement.style.height === "0px" : listElement.classList.contains("fn__none"));+ if (folded) {+ if (this.type === "bottom") {+ const toggleType = isMention ? "layout" : "bLayout";+ this.setBottomLayout(+ listElement.previousElementSibling.querySelector(`[data-type="${toggleType}"]`),+ listElement+ );+ } else {+ this.setDockSectionLayout(listElement);+ }+ }+ this.getDocumentItemElements(tree).forEach(item => {+ if (!item.querySelector(".b3-list-item__arrow--open")) {+ this.toggleItem(item, isMention);+ }+ });+ }+private loadContext(liElement: HTMLElement, isMention: boolean, expand: boolean) {const index = isMention ? 1 : 0;const docId = liElement.getAttribute("data-node-id");@@ -712,7 +728,7 @@ export class Backlink extends Model {editorElement.setAttribute("data-defid", blockId);editorElement.setAttribute("data-ismention", isMention ? "true" : "false");editorElement.setAttribute("data-backlink-revision", response.data.revision);- liElement.after(editorElement);+ record.containerElement.appendChild(editorElement);const editor = new Protyle(this.app, editorElement, {blockId: docId,click: {@@ -769,9 +785,18 @@ export class Backlink extends Model {if (editorIndex > -1) {this.editors.splice(editorIndex, 1);}- record.editor.protyle.element.remove();}- record.headerElement.remove();+ record.containerElement.remove();+ }++ public getDocumentItemElements(tree: Tree) {+ return Array.from(tree.element.querySelectorAll(+ ":scope > .b3-list > .backlinkList__item > .b3-list-item[data-node-id]"+ )) as HTMLLIElement[];+ }++ public getScrollElement(tree: Tree) {+ return this.type === "bottom" ? this.ownerProtyle.contentElement : tree.element;}private ensureListElement(tree: Tree) {@@ -823,13 +848,18 @@ export class Backlink extends Model {let record = records.get(id);if (!record) {const headerElement = tree.createTopLevelItem(item);+ const containerElement = document.createElement("div");+ containerElement.className = "backlinkList__item";+ containerElement.dataset.nodeId = id;+ containerElement.appendChild(headerElement);record = {revision: item.revision || "",+ containerElement,headerElement,requestGeneration: 0,};records.set(id, record);- listElement.appendChild(headerElement);+ listElement.appendChild(containerElement);changed = true;} else if (!item.revision || record.revision !== item.revision) {const headerElement = tree.createTopLevelItem(item);@@ -851,18 +881,11 @@ export class Backlink extends Model {let cursor = listElement.firstElementChild;orderedRecords.forEach(record => {- if (record.headerElement !== cursor) {- listElement.insertBefore(record.headerElement, cursor);+ if (record.containerElement !== cursor) {+ listElement.insertBefore(record.containerElement, cursor);changed = true;}- cursor = record.headerElement.nextElementSibling;- if (record.editor) {- if (record.editor.protyle.element !== cursor) {- listElement.insertBefore(record.editor.protyle.element, cursor);- changed = true;- }- cursor = record.editor.protyle.element.nextElementSibling;- }+ cursor = record.containerElement.nextElementSibling;});return changed;}@@ -871,7 +894,9 @@ export class Backlink extends Model {const scrollElement = this.type === "bottom" ? this.ownerProtyle.contentElement : tree.element;const scopeElement = tree?.element || this.element;const scrollRect = scrollElement.getBoundingClientRect();- const itemElements = Array.from(scopeElement.querySelectorAll(".b3-list > .b3-list-item[data-node-id]")) as HTMLElement[];+ const itemElements = Array.from(+ scopeElement.querySelectorAll(".b3-list > .backlinkList__item[data-node-id]")+ ) as HTMLElement[];const anchorElement = itemElements.find(item => item.getBoundingClientRect().bottom >= scrollRect.top);if (!anchorElement) {return;@@ -889,7 +914,7 @@ export class Backlink extends Model {return;}const tree = anchor.isMention ? this.mTree : this.tree;- const anchorElement = tree.element.querySelector(`.b3-list-item[data-node-id="${anchor.rootID}"]`);+ const anchorElement = tree.element.querySelector(`.backlinkList__item[data-node-id="${anchor.rootID}"]`);if (!anchorElement) {return;}@@ -923,7 +948,9 @@ export class Backlink extends Model {this.tree.element.classList.remove("backlinkList--divider-spacing");return;}- const lastItem = this.tree.element.querySelector(":scope > .b3-list > .b3-list-item:last-of-type");+ const lastItem = this.tree.element.querySelector(+ ":scope > .b3-list > .backlinkList__item:last-child > .b3-list-item"+ );this.tree.element.classList.toggle("backlinkList--divider-spacing",!lastItem || !lastItem.querySelector(".b3-list-item__arrow--open"));}