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: Open the first configured mobile sidebar tab on swipe https://github.com/siyuan-note/siyuan/issues/19704
Daniel21e762132e13
diff --git a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.syindex 3349a4a26e..a818104f2d 100644--- a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy+++ b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy@@ -7,7 +7,7 @@"id": "20240113110040-7sgw8kl","title": "Mobile App","type": "doc",- "updated": "20260829104731"+ "updated": "20260921090531"},"Children": [{@@ -16,7 +16,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113110114-xav9o1n",- "updated": "20250114214300"+ "updated": "20260921090531"},"Children": [{@@ -57,6 +57,47 @@}]},+ {+ "ID": "20260921090531-lx0v0bv",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260921090531-lx0v0bv",+ "updated": "20260921090531"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Swipe right in the editor to open the left sidebar, or swipe left to open the right sidebar. Each gesture opens the first visible feature on that side. Change the feature order in "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Settings"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Appearance"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Left and right layout"+ },+ {+ "Type": "NodeText",+ "Data": "."+ }+ ]+ },{"ID": "20240113110114-rugjxcf","Type": "NodeHeading",diff --git a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.syindex 720fff2e02..53892c2c5c 100644--- a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy+++ b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy@@ -7,7 +7,7 @@"id": "20240113102857-c63dmo5","title": "移动端 App","type": "doc",- "updated": "20260829104731"+ "updated": "20260921090531"},"Children": [{@@ -16,7 +16,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113102857-aof1w7f",- "updated": "20250114214155"+ "updated": "20260921090531"},"Children": [{@@ -57,6 +57,47 @@}]},+ {+ "ID": "20260921090531-bcyyegw",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260921090531-bcyyegw",+ "updated": "20260921090531"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在编辑器中向右滑动可打开左侧栏,向左滑动可打开右侧栏,每次滑动都会打开该侧首个可见功能。可在 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "设置"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "外观"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "左右布局"+ },+ {+ "Type": "NodeText",+ "Data": " 中调整功能顺序。"+ }+ ]+ },{"ID": "20240113103514-zn9zqby","Type": "NodeHeading",diff --git a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.syindex f2ede17650..40c5480aa2 100644--- a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy+++ b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy@@ -7,7 +7,7 @@"id": "20240113110500-dz2ae4n","title": "行動端 App","type": "doc",- "updated": "20260829104731"+ "updated": "20260921090531"},"Children": [{@@ -16,7 +16,7 @@"HeadingLevel": 2,"Properties": {"id": "20240113110513-8s7tp6d",- "updated": "20250114214225"+ "updated": "20260921090531"},"Children": [{@@ -57,6 +57,47 @@}]},+ {+ "ID": "20260921090531-u48uhj6",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260921090531-u48uhj6",+ "updated": "20260921090531"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "在編輯器中向右滑動可開啟左側欄,向左滑動可開啟右側欄,每次滑動都會開啟該側第一個可見功能。可在 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "設定"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "外觀"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "左右佈局"+ },+ {+ "Type": "NodeText",+ "Data": " 中調整功能順序。"+ }+ ]+ },{"ID": "20240113110513-zvmefnd","Type": "NodeHeading",diff --git a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.syindex 62f75c92e4..f334f6dfbc 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy@@ -8,7 +8,7 @@"id": "20240530101000-e6z5okf","title": "モバイルアプリ","type": "doc",- "updated": "20260829104731"+ "updated": "20260921090531"},"Children": [{@@ -18,7 +18,7 @@"Properties": {"ID": "20240530101000-peznsnc","id": "20240530101000-2nn9stf",- "updated": "20250114214341"+ "updated": "20260921090531"},"Children": [{@@ -41,6 +41,47 @@}]},+ {+ "ID": "20260921090531-0l8vdyb",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260921090531-0l8vdyb",+ "updated": "20260921090531"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "エディターで右にスワイプすると左サイドバー、左にスワイプすると右サイドバーが開きます。スワイプするたびに、その側で表示されている先頭の機能が開きます。機能の順序は "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "設定"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "スタイル"+ },+ {+ "Type": "NodeText",+ "Data": " - "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "水平レイアウト"+ },+ {+ "Type": "NodeText",+ "Data": " で変更できます。"+ }+ ]+ },{"ID": "20240530101000-tylg3qg","Type": "NodeHeading",diff --git a/app/src/mobile/util/sidebar.test.ts b/app/src/mobile/util/sidebar.test.tsindex 61a2d1c16a..22e4ac8648 100644--- a/app/src/mobile/util/sidebar.test.ts+++ b/app/src/mobile/util/sidebar.test.ts@@ -20,7 +20,10 @@ test("sidebar opening restores the active dock, falls back to visible docks andlet closed = 0;let blurred = 0;let cellEditorsClosed = 0;- const moduleExports: {openSidebar?: (side: string) => void} = {};+ const moduleExports: {+ openSidebar?: (side: string) => void;+ popSidebar?: (side: string, render: boolean, preferFirst: boolean) => void;+ } = {};const source = readFileSync(resolve(process.cwd(), "src/mobile/util/sidebar.ts"), "utf8");const code = transpileModule(source, {compilerOptions: {module: ModuleKind.CommonJS}}).outputText;runInNewContext(code, {@@ -57,4 +60,20 @@ test("sidebar opening restores the active dock, falls back to visible docks andassert.equal(blurred, 2);assert.equal(cellEditorsClosed, 2);assert.equal(rendered.length, 2);++ tabs = [tab("tag", false, true), tab("bookmark", false), tab("file", true)];+ moduleExports.popSidebar("left", true, true);+ assert.equal(rendered.at(-1), "bookmark");+ const plugin = tab("plugin-custom", false);+ Object.assign(plugin.dataset, {mobilePluginDockTab: "custom-plugin-tab"});+ tabs = [plugin, tab("file", true)];+ moduleExports.popSidebar("left", true, true);+ assert.equal(rendered.at(-1), "custom-plugin-tab");+ tabs = [tab("file", false), plugin];+ moduleExports.popSidebar("left", true, true);+ assert.equal(rendered.at(-1), "file");+ tabs = [];+ moduleExports.popSidebar("left", true, true);+ assert.equal(rendered.length, 5);+ assert.equal(left.style.transform, "");});diff --git a/app/src/mobile/util/sidebar.ts b/app/src/mobile/util/sidebar.tsindex eabb3bfac6..6d8acfb44f 100644--- a/app/src/mobile/util/sidebar.ts+++ b/app/src/mobile/util/sidebar.ts@@ -7,16 +7,17 @@ export const getSidebarElement = (side: MobileSidebarSide) => {return document.getElementById(side === "left" ? "sidebar" : "sidebarRight");};-export const getSidebarDock = (sidebarElement: HTMLElement | null) => {+export const getSidebarDock = (sidebarElement: HTMLElement | null, preferFirst = false) => {if (!sidebarElement) {return;}const toolbarElement = sidebarElement.querySelector(".toolbar--border");const tabElements = Array.from(toolbarElement?.querySelectorAll<HTMLElement>("[data-type]") || []);- const activeElement = tabElements.find(item =>- item.classList.contains("toolbar__icon--active") && !item.classList.contains("fn__none")) ||+ const activeElement = (!preferFirst && tabElements.find(item =>+ item.classList.contains("toolbar__icon--active") && !item.classList.contains("fn__none"))) ||tabElements.find(item => !item.classList.contains("fn__none"));- const type = activeElement?.dataset.type?.replace(/^sidebar-/, "").replace(/-tab$/, "");+ const type = activeElement?.dataset.mobilePluginDockTab ||+ activeElement?.dataset.type?.replace(/^sidebar-/, "").replace(/-tab$/, "");if (toolbarElement && type) {return {toolbarElement, type};}@@ -36,7 +37,7 @@ export const switchToNextSidebarTab = (side: MobileSidebarSide) => {nextTab.scrollIntoView({block: "nearest", inline: "nearest"});};-export const popSidebar = (side: MobileSidebarSide, render = true) => {+export const popSidebar = (side: MobileSidebarSide, render = true, preferFirst = false) => {activeBlur();const sidebarElement = getSidebarElement(side);if (!sidebarElement) {@@ -44,7 +45,7 @@ export const popSidebar = (side: MobileSidebarSide, render = true) => {}let dock: ReturnType<typeof getSidebarDock>;if (render) {- dock = getSidebarDock(sidebarElement);+ dock = getSidebarDock(sidebarElement, preferFirst);if (!dock) {sidebarElement.style.removeProperty("transform");closePanel();diff --git a/app/src/mobile/util/sidebarSwipe.test.ts b/app/src/mobile/util/sidebarSwipe.test.tsindex be90c94bf0..365c0e25ac 100644--- a/app/src/mobile/util/sidebarSwipe.test.ts+++ b/app/src/mobile/util/sidebarSwipe.test.ts@@ -68,12 +68,18 @@ test("sidebar cycling follows visible tab order and dispatches plugin activationassert.equal(activated.length, 4);});-const createTouchHarness = (side: "left" | "right", options: {scrollable?: boolean, disabled?: boolean} = {}) => {+const createTouchHarness = (side: "left" | "right", options: {+ scrollable?: boolean, disabled?: boolean, closed?: boolean,+} = {}) => {const actions: string[] = [];- const panel = {classList: classList(), style: {transform: "translateX(0px)"}, contains: () => false};- const mask = {classList: classList(), style: {}};+ const panel = {+ classList: classList(),+ style: {transform: "translateX(0px)", removeProperty() { this.transform = ""; }},+ contains: () => false,+ };+ const mask = {classList: classList(...(options.closed ? ["fn__none"] : [])), style: {}};const target = {- id: side === "left" ? "sidebar" : "sidebarRight",+ id: options.closed ? "editor" : side === "left" ? "sidebar" : "sidebarRight",tagName: "DIV", dataset: {}, parentElement: null as HTMLElement | null,closest: (): null => null,scrollWidth: options.scrollable ? 600 : 300, clientWidth: 300, scrollLeft: 100,@@ -82,7 +88,11 @@ const createTouchHarness = (side: "left" | "right", options: {scrollable?: booleconst modules: Record<string, unknown> = {"./sidebar": {getSidebarElement: () => panel,- popSidebar: () => { panel.style.transform = "translateX(0px)"; actions.push("restore"); },+ getSidebarDock: () => ({}),+ popSidebar: (value: string, _render: boolean, preferFirst: boolean) => {+ panel.style.transform = "translateX(0px)";+ actions.push(preferFirst ? `first:${value}` : "restore");+ },switchToNextSidebarTab: (value: string) => actions.push(`next:${value}`),},"./touchPanelGesture": gestures,@@ -128,6 +138,20 @@ const createTouchHarness = (side: "left" | "right", options: {scrollable?: boolefor (const side of ["left", "right"] as const) {const nextX = side === "left" ? 240 : 120;const closeX = side === "left" ? 120 : 240;+ test(`${side} sidebar opens its first visible tab only after a committed swipe`, () => {+ const harness = createTouchHarness(side, {closed: true});+ harness.start();+ harness.move(nextX);+ assert.deepEqual(harness.actions, []);+ harness.end(nextX);+ assert.deepEqual(harness.actions, [`first:${side}`]);+ const disabled = createTouchHarness(side, {closed: true, disabled: true});+ disabled.start();+ disabled.move(nextX);+ disabled.end(nextX);+ assert.deepEqual(disabled.actions, []);+ });+test(`${side} sidebar switches once on release and retains closing gestures`, () => {const next = createTouchHarness(side, {disabled: true});next.start();diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.tsindex b23b66cdb8..5cbf8617e5 100644--- a/app/src/mobile/util/touch.ts+++ b/app/src/mobile/util/touch.ts@@ -297,7 +297,7 @@ export const handleTouchEnd = (event: TouchEvent) => {return;}- popSidebar(getOpeningSidebar(firstDirection));+ popSidebar(getOpeningSidebar(firstDirection), true, true);};export const handleTouchCancel = () => {