An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support keyboard navigation for breadcrumbs https://github.com/siyuan-note/siyuan/issues/2613
Daniela53973c1c458
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex 37beb4cd33..03ccdfefdc 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "التركيز على مسار التنقل","tableRectangleSelectionRequired": "يتطلب تحديدًا مستطيلاً","updateChannel": "قناة التحديث","updateChannelTip": "تتلقى قناة Beta الإصدارات المستقرة وRC وBeta، بينما تتلقى قناة Alpha جميع الإصدارات. تتطلب قنوات الاختبار إمكانية الوصول إلى GitHub",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex f448a3283a..4f1bf0d991 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Breadcrumb fokussieren","tableRectangleSelectionRequired": "Erfordert eine rechteckige Auswahl","updateChannel": "Aktualisierungskanal","updateChannelTip": "Der Beta-Kanal erhält stabile, RC- und Beta-Versionen; der Alpha-Kanal erhält alle Versionen. Testkanäle erfordern Zugriff auf GitHub",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex ac457de47c..806d1734ca 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Focus breadcrumb","tableRectangleSelectionRequired": "Requires a rectangular selection","updateChannel": "Update channel","updateChannelTip": "Beta receives stable, RC, and Beta releases; Alpha receives all releases. Test channels require access to GitHub",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 5d4fa0288f..880f6abaca 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Enfocar ruta de navegación","tableRectangleSelectionRequired": "Requiere una selección rectangular","updateChannel": "Canal de actualización","updateChannelTip": "El canal Beta recibe versiones estables, RC y Beta; el canal Alpha recibe todas las versiones. Los canales de prueba requieren acceso a GitHub",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex a2b8765fa1..0213b4f890 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Activer le fil d’Ariane","tableRectangleSelectionRequired": "Nécessite une sélection rectangulaire","updateChannel": "Canal de mise à jour","updateChannelTip": "Le canal Beta reçoit les versions stables, RC et bêta ; le canal Alpha reçoit toutes les versions. Les canaux de test nécessitent un accès à GitHub",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex 7302bb6f2f..ea538fcb67 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "מיקוד בפירורי לחם","tableRectangleSelectionRequired": "נדרשת בחירה מלבנית","updateChannel": "ערוץ עדכונים","updateChannelTip": "ערוץ Beta מקבל גרסאות יציבות, RC ו-Beta; ערוץ Alpha מקבל את כל הגרסאות. ערוצי הבדיקה דורשים גישה ל-GitHub",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex e3120a0521..2519b9776c 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "ब्रेडक्रंब पर फ़ोकस करें","tableRectangleSelectionRequired": "आयताकार चयन आवश्यक है","updateChannel": "अपडेट चैनल","updateChannelTip": "Beta चैनल को स्थिर, RC और Beta रिलीज़ मिलते हैं; Alpha चैनल को सभी रिलीज़ मिलते हैं। परीक्षण चैनलों के लिए GitHub तक पहुंच आवश्यक है",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex ed1a2f713c..382831fcbd 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Fokuskan breadcrumb","tableRectangleSelectionRequired": "Memerlukan pilihan persegi panjang","updateChannel": "Saluran pembaruan","updateChannelTip": "Kanal Beta menerima rilis stabil, RC, dan Beta; kanal Alpha menerima semua rilis. Kanal pengujian memerlukan akses ke GitHub",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex 4f27a6d055..35f87ece73 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Attiva breadcrumb","tableRectangleSelectionRequired": "Richiede una selezione rettangolare","updateChannel": "Canale di aggiornamento","updateChannelTip": "Il canale Beta riceve le versioni stabili, RC e Beta; il canale Alpha riceve tutte le versioni. I canali di test richiedono l'accesso a GitHub",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 402a45b036..d57fd2df59 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "パンくずリストにフォーカス","tableRectangleSelectionRequired": "矩形範囲の選択が必要です","updateChannel": "更新チャンネル","updateChannelTip": "Beta チャンネルでは正式版、RC、Beta 版を受信し、Alpha チャンネルではすべての版を受信します。テストチャンネルの利用には GitHub へのアクセスが必要です",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex e96f0c1f61..88497e092a 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "이동 경로에 포커스","tableRectangleSelectionRequired": "직사각형 선택 영역이 필요합니다","updateChannel": "업데이트 채널","updateChannelTip": "Beta 채널은 정식, RC 및 Beta 릴리스를 받고 Alpha 채널은 모든 릴리스를 받습니다. 테스트 채널을 사용하려면 GitHub에 접근할 수 있어야 합니다",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex 42ff0ca54a..e6eec788ca 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Breadcrumb focussen","tableRectangleSelectionRequired": "Vereist een rechthoekige selectie","updateChannel": "Updatekanaal","updateChannelTip": "Het Beta-kanaal ontvangt stabiele, RC- en Beta-versies; het Alpha-kanaal ontvangt alle versies. Testkanalen vereisen toegang tot GitHub",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 05624e09e4..0fb4da1b50 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Ustaw fokus na ścieżce nawigacji","tableRectangleSelectionRequired": "Wymaga prostokątnego zaznaczenia","updateChannel": "Kanał aktualizacji","updateChannelTip": "Kanał Beta otrzymuje wydania stabilne, RC i Beta, a kanał Alpha wszystkie wydania. Kanały testowe wymagają dostępu do GitHub",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex f10bbee9ba..a56515ffb4 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Focar breadcrumb","tableRectangleSelectionRequired": "Requer uma seleção retangular","updateChannel": "Canal de atualização","updateChannelTip": "O canal Beta recebe versões estáveis, RC e Beta; o canal Alpha recebe todas as versões. Os canais de teste exigem acesso ao GitHub",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex bd26f3a123..f0ab89e5ff 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Перейти к навигационной цепочке","tableRectangleSelectionRequired": "Требуется прямоугольное выделение","updateChannel": "Канал обновлений","updateChannelTip": "Канал Beta получает стабильные, RC- и Beta-версии, а канал Alpha — все версии. Для тестовых каналов требуется доступ к GitHub",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex 716e057646..da55db34fa 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Zamerať navigačnú cestu","tableRectangleSelectionRequired": "Vyžaduje obdĺžnikový výber","updateChannel": "Aktualizačný kanál","updateChannelTip": "Kanál Beta prijíma stabilné vydania, RC a Beta; kanál Alpha prijíma všetky vydania. Testovacie kanály vyžadujú prístup ku GitHubu",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 06f09b79ae..29b2f0f2e9 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "โฟกัสเส้นทางนำทาง","tableRectangleSelectionRequired": "ต้องเลือกเป็นรูปสี่เหลี่ยมผืนผ้า","updateChannel": "ช่องทางการอัปเดต","updateChannelTip": "ช่อง Beta จะได้รับรุ่นเสถียร รุ่น RC และรุ่น Beta ส่วนช่อง Alpha จะได้รับทุกรุ่น ช่องทดสอบจำเป็นต้องเข้าถึง GitHub",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex 13f362a18a..e6fdcb2845 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "İçerik haritasına odaklan","tableRectangleSelectionRequired": "Dikdörtgen bir seçim gerektirir","updateChannel": "Güncelleme kanalı","updateChannelTip": "Beta kanalı kararlı, RC ve Beta sürümlerini; Alpha kanalı ise tüm sürümleri alır. Test kanalları GitHub erişimi gerektirir",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex a5233aacd7..83969a663c 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "Перейти до навігаційного ланцюжка","tableRectangleSelectionRequired": "Потрібне прямокутне виділення","updateChannel": "Канал оновлень","updateChannelTip": "Канал Beta отримує стабільні, RC- та Beta-версії, а канал Alpha — усі версії. Для тестових каналів потрібен доступ до GitHub",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex 24e9b8064e..a188bbf5d7 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "聚焦面包屑","tableRectangleSelectionRequired": "需要矩形选区","updateChannel": "更新通道","updateChannelTip": "Beta 通道接收正式版、RC 和 Beta,Alpha 通道接收全部版本。测试通道需要能够访问 GitHub",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex 42af98caf7..89e9fbf71f 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,5 @@{+ "focusBreadcrumb": "聚焦麵包屑","tableRectangleSelectionRequired": "需要矩形選區","updateChannel": "更新通道","updateChannelTip": "Beta 通道接收正式版、RC 和 Beta,Alpha 通道接收所有版本。測試通道需要能夠存取 GitHub",diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex 493cf5c78b..c7037eea3c 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -331,10 +331,15 @@}&:hover,+ &:focus-visible,&--active {color: var(--b3-theme-on-background);background-color: var(--b3-list-hover);}++ &:focus-visible {+ outline: 1px solid var(--b3-theme-primary);+ }}}diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 778348bb99..3be099a733 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -382,6 +382,12 @@ const editKeydown = (app: App, event: KeyboardEvent) => {zoomOut({protyle, id: protyle.block.rootID, focusId: protyle.block.id});return true;}+ if (matchHotKey(window.siyuan.config.keymap.editor.general.focusBreadcrumb.custom, event)) {+ if (protyle.breadcrumb?.focus(range)) {+ event.preventDefault();+ return true;+ }+ }if (matchHotKey(window.siyuan.config.keymap.editor.general.switchReadonly.custom, event)) {event.preventDefault();onlyProtyleCommand({diff --git a/app/src/constants.ts b/app/src/constants.tsindex e18e3237f9..8598887319 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -569,6 +569,7 @@ export abstract class Constants {refPopover: {default: "", custom: ""},copyText: {default: "", custom: ""},exitFocus: {default: "", custom: ""},+ focusBreadcrumb: {default: "", custom: ""},ai: {default: "", custom: ""},switchReadonly: {default: "", custom: ""},switchAdjust: {default: "", custom: ""},diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.tsindex 09583b9b96..bbc4fb8877 100644--- a/app/src/protyle/breadcrumb/index.ts+++ b/app/src/protyle/breadcrumb/index.ts@@ -12,7 +12,7 @@ import {hasClosestBlock, hasTopClosestByClassName} from "../util/hasClosest";import {needSubscribe} from "../../util/needSubscribe";import {isMobile} from "../../util/functions";import {zoomOut} from "../../menus/protyle";-import {getEditorRange} from "../util/selection";+import {focusByRange, getEditorRange} from "../util/selection";/// #if !MOBILEimport {openFileById} from "../../editor/util";import {saveLayout} from "../../layout/util";@@ -34,12 +34,15 @@ import {resize} from "../util/resize";import {listIndent, listOutdent} from "../wysiwyg/list";import {improveBreadcrumbAppearance} from "../wysiwyg/renderBacklink";import {getCloudURL} from "../../config/util/about";+import {escapeAriaLabel} from "../../util/escape";export class Breadcrumb {public element: HTMLElement;private mediaRecorder: RecordMedia;private id: string;private messageId: string;+ private previousFocusElement: HTMLElement;+ private previousRange: Range;constructor(protyle: IProtyle) {const element = document.createElement("div");@@ -211,6 +214,39 @@ ${padHTML}isLeft: false,});});+ this.element.addEventListener("keydown", (event) => {+ if (event.isComposing || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {+ return;+ }+ const itemElement = (event.target as HTMLElement).closest(".protyle-breadcrumb__item") as HTMLElement;+ if (!itemElement || !this.element.contains(itemElement)) {+ return;+ }+ if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {+ return;+ }+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") {+ const nextItemElement = this.getSiblingItem(itemElement, event.key === "ArrowRight");+ if (nextItemElement) {+ this.focusItem(nextItemElement);+ }+ event.preventDefault();+ event.stopPropagation();+ } else if (event.key === "ArrowDown" || event.key === "Enter") {+ const itemRect = itemElement.getBoundingClientRect();+ this.openChildrenMenu(protyle, itemElement.getAttribute("data-node-id"), {+ x: itemRect.left,+ y: itemRect.bottom,+ isLeft: false,+ }, true);+ event.preventDefault();+ event.stopPropagation();+ } else if (event.key === "Escape") {+ this.restoreEditorFocus(protyle);+ event.preventDefault();+ event.stopPropagation();+ }+ });element.addEventListener("mouseleave", () => {protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl").forEach(item => {item.classList.remove("protyle-wysiwyg--hl");@@ -222,11 +258,12 @@ ${padHTML}/// #endif}- private async openChildrenMenu(protyle: IProtyle, id: string, position: IPosition) {+ private async openChildrenMenu(protyle: IProtyle, id: string, position: IPosition, keyboard = false) {if (!id) {return;}+ const keyboardItemElement = keyboard ? document.activeElement : undefined;const menuName = `${Constants.MENU_BREADCRUMB_CHILDREN}-${id}`;const menu = new Menu(menuName);if (menu.isOpen) {@@ -255,6 +292,12 @@ ${padHTML}}return;}+ if (keyboard && document.activeElement !== keyboardItemElement) {+ if (window.siyuan.menus.menu.element.getAttribute("data-name") === menuName) {+ window.siyuan.menus.menu.remove();+ }+ return;+ }if (window.siyuan.menus.menu.element.getAttribute("data-name") !== menuName) {return;}@@ -267,6 +310,53 @@ ${padHTML}menu.addItem(item);});menu.open(position);+ if (keyboard) {+ menu.element.querySelector(".b3-menu__item:not([disabled])")?.classList.add("b3-menu__item--current");+ }+ }++ private getSiblingItem(itemElement: HTMLElement, forward: boolean) {+ let siblingElement = forward ? itemElement.nextElementSibling : itemElement.previousElementSibling;+ while (siblingElement && !siblingElement.classList.contains("protyle-breadcrumb__item")) {+ siblingElement = forward ? siblingElement.nextElementSibling : siblingElement.previousElementSibling;+ }+ return siblingElement as HTMLElement;+ }++ private focusItem(itemElement: HTMLElement) {+ this.element.querySelectorAll(".protyle-breadcrumb__item").forEach((item) => {+ item.setAttribute("tabindex", item === itemElement ? "0" : "-1");+ });+ itemElement.focus({preventScroll: true});+ itemElement.scrollIntoView({block: "nearest", inline: "nearest"});+ }++ private restoreEditorFocus(protyle: IProtyle) {+ const focusElement = this.previousFocusElement?.isConnected ? this.previousFocusElement : protyle.wysiwyg.element;+ focusElement.focus({preventScroll: true});+ if (this.previousRange) {+ focusByRange(this.previousRange);+ }+ this.previousFocusElement = undefined;+ this.previousRange = undefined;+ }++ public focus(range?: Range) {+ if (!this.element.isConnected || this.element.getClientRects().length === 0) {+ return false;+ }+ const itemElement = this.element.querySelector(".protyle-breadcrumb__item--active") as HTMLElement ||+ this.element.querySelector(".protyle-breadcrumb__item:last-of-type") as HTMLElement;+ if (!itemElement) {+ return false;+ }+ window.siyuan.menus.menu.remove();+ if (!this.element.contains(document.activeElement)) {+ this.previousFocusElement = document.activeElement as HTMLElement;+ this.previousRange = range?.cloneRange();+ }+ this.focusItem(itemElement);+ return true;}private async genChildrenMenuItems(protyle: IProtyle, id: string, currentPathIDs: Set<string>,@@ -848,11 +938,11 @@ ${padHTML}isCurrent = true;}if (index === 0 && !protyle.options.render.breadcrumbDocName) {- html += `<span class="protyle-breadcrumb__item${isCurrent ? " protyle-breadcrumb__item--active" : ""}" data-node-id="${item.id}"${response.data.length === 1 ? ' style="max-width:none"' : ""}>+ html += `<span class="protyle-breadcrumb__item${isCurrent ? " protyle-breadcrumb__item--active" : ""}" data-node-id="${item.id}" role="button" tabindex="-1" aria-label="${escapeAriaLabel(item.name || window.siyuan.languages.untitled)}"${response.data.length === 1 ? ' style="max-width:none"' : ""}><svg class="popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.type, item.subType)}"></use></svg></span>`;} else {- html += `<span class="protyle-breadcrumb__item${isCurrent ? " protyle-breadcrumb__item--active" : ""}" data-node-id="${item.id}"${(response.data.length === 1 || index === 0) ? ' style="max-width:none"' : ""}>+ html += `<span class="protyle-breadcrumb__item${isCurrent ? " protyle-breadcrumb__item--active" : ""}" data-node-id="${item.id}" role="button" tabindex="-1" aria-label="${escapeAriaLabel(item.name || window.siyuan.languages.untitled)}"${(response.data.length === 1 || index === 0) ? ' style="max-width:none"' : ""}><svg class="popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.type, item.subType)}"></use></svg>${item.name ? `<span class="protyle-breadcrumb__text" title="${item.name}">${item.name}</span>` : ""}</span>`;diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex fcf7cdc84c..4fcddb28b6 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -1111,6 +1111,7 @@ declare namespace Config {copyText: IKey;duplicate: IKey;exitFocus: IKey;+ focusBreadcrumb: IKey;expand: IKey;expandDown: IKey;expandUp: IKey;