Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Keep menu mouse scrolling responsive from either edge https://github.com/siyuan-note/siyuan/issues/20882

Danielb660a6d5e478
diff --git a/app/src/menus/menuLayout.dom.test.ts b/app/src/menus/menuLayout.dom.test.ts
index 9d8b7320ac..d6c4b39672 100644
--- a/app/src/menus/menuLayout.dom.test.ts
+++ b/app/src/menus/menuLayout.dom.test.ts
@@ -495,6 +495,32 @@ const browserCases = async (sources: Record<string, string>, css: string,
check.equal(clicked, Number(nativeHit.textContent.trim().replace("Mouse item ", "")), "Native click selects the visible item");
dispose(following);
+ const abovePointer = createMenu();
+ addItems(abovePointer, 80);
+ abovePointer.popup({x: 60, y: innerHeight - 30, h: 20});
+ await settle();
+ const aboveItems = abovePointer.element.lastElementChild as HTMLElement;
+ check.ok(aboveItems.getBoundingClientRect().bottom <= innerHeight - 30);
+ for (const entry of [.99, .7, .4]) {
+ aboveItems.scrollTop = 0;
+ abovePointer.resetMouseScroll();
+ pointer(aboveItems, entry);
+ check.equal(aboveItems.scrollTop, 0, "Opening above the pointer still starts at the first item");
+ pointer(aboveItems, entry - .05);
+ check.ok(aboveItems.scrollTop > 0, "Moving upward after entry follows the pointer without a wheel event");
+ pointer(aboveItems, .99);
+ check.equal(aboveItems.scrollTop, aboveItems.scrollHeight - aboveItems.clientHeight);
+ pointer(aboveItems, .01);
+ check.equal(aboveItems.scrollTop, 0);
+ }
+ aboveItems.scrollTop = aboveItems.scrollHeight - aboveItems.clientHeight;
+ abovePointer.resetMouseScroll();
+ pointer(aboveItems, .01);
+ pointer(aboveItems, .06);
+ check.ok(aboveItems.scrollTop < aboveItems.scrollHeight - aboveItems.clientHeight,
+ "Moving downward after entry at the last item also follows the pointer");
+ dispose(abovePointer);
+
window.siyuan.config.appearance.menuMouseScroll = true;
const mouseSubmenus = createMenu();
mouseSubmenus.addItem({label: "Scrollable children", submenu: Array.from({length: 80}, (_, i) => ({label: `Child ${i}`}))});
diff --git a/app/src/menus/menuMouseScroll.ts b/app/src/menus/menuMouseScroll.ts
index e4aa5bebea..103ff269dd 100644
--- a/app/src/menus/menuMouseScroll.ts
+++ b/app/src/menus/menuMouseScroll.ts
@@ -47,7 +47,11 @@ export const bindMenuMouseScroll = (menu: HTMLElement, enabled: () => boolean, r
if (!anchor || anchor.items !== items || anchor.top !== rect.top || anchor.height !== rect.height ||
anchor.scrollHeight !== items.scrollHeight || Math.abs(anchor.currentScrollTop - items.scrollTop) > 1) {
// 进入菜单或其他操作改变滚动位置后建立基准,首次移动不跳转。
- anchor = {items, y: event.clientY, lastY: event.clientY, scrollTop: items.scrollTop,
+ // 位于首尾时将基准放在对应边缘,避免从另一端进入后朝菜单内部移动没有可滚动内容。
+ const inset = Math.min(24, rect.height / 4);
+ const y = items.scrollTop <= 1 ? rect.top + inset :
+ maxScroll - items.scrollTop <= 1 ? rect.bottom - inset : event.clientY;
+ anchor = {items, y, lastY: event.clientY, scrollTop: items.scrollTop,
currentScrollTop: items.scrollTop, top: rect.top, height: rect.height, scrollHeight: items.scrollHeight};
return;
}