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: Restore continuous horizontal palette scrolling https://github.com/siyuan-note/siyuan/issues/20856
Danield67fb448adba
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex f6002b9e21..7989a3f160 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -2546,6 +2546,17 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,const start = {x: Math.round(bounds.right - 12), y: Math.round(bounds.top + bounds.height / 2)};const canvasPosition = {x: view.offsetX, y: view.offsetY, scale: view.scale};const settingsPosition = touchManager.getBoundingClientRect().left;+ await nativeInput([+ {type: "mouseMove", ...start},+ ...Array.from({length: 20}, () => ({type: "mouseWheel", ...start, deltaX: -2, deltaY: 0})),+ ]);+ check.ok(touchPalette.scrollLeft > 30, "a continuous trackpad gesture scrolls the actual node palette");+ check.equal(touchPalette.hasAttribute("data-scrolling"), true,+ "the actual node palette keeps snapping disabled during a horizontal gesture");+ await settlePalette();+ check.deepEqual({x: view.offsetX, y: view.offsetY, scale: view.scale}, canvasPosition);+ check.equal(touchManager.getBoundingClientRect().left, settingsPosition);+ touchPalette.scrollLeft = 0;await nativeInput([{type: "mouseMove", ...start},{type: "mouseWheel", ...start, deltaX: 0, deltaY: -60},diff --git a/app/src/protyle/render/listMindmap/paletteScroll.test.ts b/app/src/protyle/render/listMindmap/paletteScroll.test.tsindex c7cfd97acb..3c60f33cd9 100644--- a/app/src/protyle/render/listMindmap/paletteScroll.test.ts+++ b/app/src/protyle/render/listMindmap/paletteScroll.test.ts@@ -83,7 +83,7 @@ const browserCases = async (source: string, css: string) => {host.remove();}- // 横向、斜向和 Shift 滚轮交给原生滚动,手势末尾的纵向抖动不会切换到脚本路径。+ // 横向、斜向和 Shift 滚轮交给原生滚动,手势期间暂停吸附,纵向抖动不会改变方向。{const {host, palette, wheel} = make();const outer = document.createElement("div");@@ -103,7 +103,7 @@ const browserCases = async (source: string, css: string) => {}await frame();check.equal(palette.scrollLeft, 0, "synthetic native gestures do not trigger scripted movement");- check.equal(palette.hasAttribute("data-scrolling"), false);+ check.equal(palette.hasAttribute("data-scrolling"), true);check.equal(wheel(0, 50, {shiftKey: true}).defaultPrevented, false);for (const modifier of ["ctrlKey", "metaKey"]) {check.equal(wheel(0, 50, {[modifier]: true}).defaultPrevented, false, "zoom input stays native");@@ -118,7 +118,7 @@ const browserCases = async (source: string, css: string) => {await until(() => palette.scrollLeft > 0, "native horizontal wheel input scrolls the real palette");check.ok(blocked.length > 0);check.ok(blocked.every(value => !value), "native wheel default actions remain enabled");- check.equal(palette.hasAttribute("data-scrolling"), false);+ check.equal(palette.hasAttribute("data-scrolling"), true);await delay(80);check.equal(outer.scrollTop, 120, "diagonal palette scrolling preserves the outer document position");await require("electron").ipcRenderer.invoke("palette-wheel", {@@ -130,6 +130,32 @@ const browserCases = async (source: string, css: string) => {outer.remove();}+ // 连续细小横向输入必须跨过一列,不能在手势期间被强制吸附拉住。+ {+ const {host, palette, wheel} = make();+ const bounds = palette.getBoundingClientRect();+ const positions: number[] = [];+ for (let i = 0; i < 20; i++) {+ await require("electron").ipcRenderer.invoke("palette-wheel", {+ type: "mouseWheel", x: Math.round(bounds.left + bounds.width / 2),+ y: Math.round(bounds.top + bounds.height / 2), deltaX: 2, deltaY: 0,+ });+ await delay(20);+ positions.push(palette.scrollLeft);+ }+ check.ok(palette.scrollLeft > 30, "continuous fine horizontal wheel input makes progress: " + JSON.stringify(positions));+ check.equal(palette.hasAttribute("data-scrolling"), true, "snapping stays disabled throughout the gesture");+ await delay(180);+ palette.scrollBy({left: 1, behavior: "instant"});+ await delay(180);+ check.equal(palette.hasAttribute("data-scrolling"), true, "continued native scrolling delays alignment after the last wheel event");+ check.equal(wheel(0, -3).defaultPrevented, false,+ "late vertical jitter during horizontal inertia does not switch to scripted scrolling");+ await until(() => !palette.hasAttribute("data-scrolling"), "horizontal input aligns after the gesture");+ check.ok(palette.scrollLeft > 30);+ host.remove();+ }+// 原生惯性滚动不受纵向滚轮的定时对齐干扰;新的输入可中断平滑停靠。{const {host, palette, step, wheel, settled} = make();@@ -154,7 +180,8 @@ const browserCases = async (source: string, css: string) => {wheel(0, 13);await frame();wheel(10, 0);- check.equal(palette.hasAttribute("data-scrolling"), false, "horizontal input cancels scripted alignment");+ check.equal(palette.hasAttribute("data-scrolling"), true, "horizontal input keeps snapping disabled while scrolling");+ await settled();const nativePosition = palette.scrollLeft;await delay(650);check.equal(palette.scrollLeft, nativePosition, "a stale timer cannot change a native gesture");diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 96a02b6626..c3cd009991 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -3921,14 +3921,15 @@ export class ListMindmapView {control.insertAdjacentHTML("beforeend",'<svg class="color__square-mark" aria-hidden="true"><use xlink:href="#iconSelect"></use></svg>');});- // 触屏和横向滚轮沿用原生滚动,纵向滚轮累计小数位移;拖动完成后不触发色卡点击。+ // 滚轮手势期间暂停吸附,横向位移由浏览器处理,纵向位移累计后写入;触屏沿用原生滚动。let drag: {id: number, x: number, scroll: number, scale: number};let moved = false;let wheel: {position: number, direction: number, target?: number};let wheelFrame = 0;let wheelTimer: number;let settleTimer: number;- let nativeWheelUntil = 0;+ let nativeScrolling = false;+ let nativeDirection = 0;const stopWheel = (restore = true) => {window.clearTimeout(wheelTimer);window.clearTimeout(settleTimer);@@ -3938,6 +3939,7 @@ export class ListMindmapView {palette.scrollTo({left: palette.scrollLeft, behavior: "instant"});}wheel = undefined;+ nativeScrolling = false;if (restore && !drag) {palette.removeAttribute("data-scrolling");}@@ -3970,6 +3972,18 @@ export class ListMindmapView {stopWheel();}, 500);};+ const waitForNativeScroll = () => {+ window.clearTimeout(wheelTimer);+ wheelTimer = window.setTimeout(() => {+ nativeScrolling = false;+ snap(nativeDirection);+ }, 240);+ };+ palette.addEventListener("scroll", () => {+ if (nativeScrolling) {+ waitForNativeScroll();+ }+ }, {passive: true});palette.addEventListener("scrollend", () => {if (wheel?.target !== undefined && Math.abs(palette.scrollLeft - wheel.target) < 1) {stopWheel();@@ -3978,7 +3992,6 @@ export class ListMindmapView {palette.addEventListener("keydown", () => stopWheel());palette.addEventListener("pointerdown", (event: PointerEvent) => {stopWheel();- nativeWheelUntil = 0;moved = false;if (event.pointerType !== "mouse" || event.button !== 0 ||palette.scrollWidth <= palette.clientWidth) {@@ -4037,9 +4050,19 @@ export class ListMindmapView {return;}// 同一横向手势即使末尾只剩纵向抖动,也由浏览器处理,避免轴向切换。- if (event.deltaX || event.shiftKey || performance.now() < nativeWheelUntil) {- nativeWheelUntil = performance.now() + 240;- stopWheel();+ if (event.deltaX || event.shiftKey || nativeScrolling) {+ if (!nativeScrolling) {+ stopWheel(false);+ nativeScrolling = true;+ nativeDirection = 0;+ palette.setAttribute("data-scrolling", "");+ }+ if (event.deltaX) {+ nativeDirection = Math.sign(event.deltaX);+ } else if (event.shiftKey && event.deltaY) {+ nativeDirection = Math.sign(event.deltaY);+ }+ waitForNativeScroll();return;}if (!event.deltaY) {