Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(sidebar): keep row menus inside the viewport

vastsad7cb84408deb
diff --git a/apps/desktop/src/components/Sidebar.tsx b/apps/desktop/src/components/Sidebar.tsx
index 0ae84dde3..6acc66c04 100644
--- a/apps/desktop/src/components/Sidebar.tsx
+++ b/apps/desktop/src/components/Sidebar.tsx
@@ -16,6 +16,10 @@ import { TooltipButton, cx } from "./ui";
/** Default number of most-recent sessions shown per project group before the rest fold. */
const MAX_VISIBLE_SESSIONS = 10;
import { portalToBody } from "../lib/portal-visibility";
+import {
+ clampSidebarFloatingMenuTop,
+ SIDEBAR_MENU_VIEWPORT_PADDING,
+} from "../lib/sidebar-floating-menu";
import { useTranslation } from "react-i18next";
import { api } from "../lib/api";
import { SessionHoverCard } from "../features/sessions/SessionHoverCard";
@@ -102,9 +106,6 @@ type ProjectEntry = {
branch?: string;
};
-const VIEWPORT_PADDING = 8;
-const SIDEBAR_FLOATING_MENU_MAX_HEIGHT = 360;
-
/** Private MIME so a sidebar session drag is never mistaken for an OS file drop. */
const SESSION_DRAG_MIME = "application/x-pi-desktop-session";
@@ -498,14 +499,8 @@ export function Sidebar({
const placeMenu = useCallback((event: ReactMouseEvent<HTMLButtonElement>) => {
const rect = event.currentTarget.getBoundingClientRect();
setMenuPosition({
- top: Math.max(
- VIEWPORT_PADDING,
- Math.min(
- rect.bottom + 4,
- window.innerHeight - SIDEBAR_FLOATING_MENU_MAX_HEIGHT - VIEWPORT_PADDING,
- ),
- ),
- left: Math.max(VIEWPORT_PADDING, rect.right + 4),
+ top: clampSidebarFloatingMenuTop(rect.bottom + 4, window.innerHeight),
+ left: Math.max(SIDEBAR_MENU_VIEWPORT_PADDING, rect.right + 4),
});
}, []);
@@ -513,14 +508,8 @@ export function Sidebar({
// of the trigger or pointer; they never flip to the left at the viewport edge.
const placeMenuAtPoint = useCallback((x: number, y: number) => {
setMenuPosition({
- top: Math.max(
- VIEWPORT_PADDING,
- Math.min(
- y + 4,
- window.innerHeight - SIDEBAR_FLOATING_MENU_MAX_HEIGHT - VIEWPORT_PADDING,
- ),
- ),
- left: Math.max(VIEWPORT_PADDING, x + 4),
+ top: clampSidebarFloatingMenuTop(y + 4, window.innerHeight),
+ left: Math.max(SIDEBAR_MENU_VIEWPORT_PADDING, x + 4),
});
}, []);
diff --git a/apps/desktop/src/lib/sidebar-floating-menu.ts b/apps/desktop/src/lib/sidebar-floating-menu.ts
new file mode 100644
index 000000000..3fe0a0e5d
--- /dev/null
+++ b/apps/desktop/src/lib/sidebar-floating-menu.ts
@@ -0,0 +1,16 @@
+export const SIDEBAR_MENU_VIEWPORT_PADDING = 8;
+export const SIDEBAR_FLOATING_MENU_MAX_HEIGHT = 360;
+
+/** Keep a floating sidebar menu inside the viewport with room for its full height. */
+export function clampSidebarFloatingMenuTop(
+ anchorTop: number,
+ viewportHeight: number,
+): number {
+ return Math.max(
+ SIDEBAR_MENU_VIEWPORT_PADDING,
+ Math.min(
+ anchorTop,
+ viewportHeight - SIDEBAR_FLOATING_MENU_MAX_HEIGHT - SIDEBAR_MENU_VIEWPORT_PADDING,
+ ),
+ );
+}
diff --git a/apps/desktop/src/styles/sessions.css b/apps/desktop/src/styles/sessions.css
index f9b359e55..760de9b55 100644
--- a/apps/desktop/src/styles/sessions.css
+++ b/apps/desktop/src/styles/sessions.css
@@ -479,7 +479,7 @@
bottom: auto;
z-index: 60;
min-width: 172px;
- max-height: calc(100vh - 16px);
+ max-height: min(360px, calc(100vh - 16px));
overflow-y: auto;
padding: 5px;
border: 1px solid var(--ds-border-subtle);
diff --git a/apps/desktop/test/sidebar-floating-menu.test.mjs b/apps/desktop/test/sidebar-floating-menu.test.mjs
new file mode 100644
index 000000000..12793f26c
--- /dev/null
+++ b/apps/desktop/test/sidebar-floating-menu.test.mjs
@@ -0,0 +1,26 @@
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import test from "node:test";
+
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+
+const {
+ clampSidebarFloatingMenuTop,
+ SIDEBAR_FLOATING_MENU_MAX_HEIGHT,
+ SIDEBAR_MENU_VIEWPORT_PADDING,
+} = await import("../src/lib/sidebar-floating-menu.ts");
+
+test("sidebar floating menu stays within the viewport at the lower edge", () => {
+ const top = clampSidebarFloatingMenuTop(850, 900);
+
+ assert.equal(top, 900 - SIDEBAR_FLOATING_MENU_MAX_HEIGHT - SIDEBAR_MENU_VIEWPORT_PADDING);
+ assert.equal(top + SIDEBAR_FLOATING_MENU_MAX_HEIGHT + SIDEBAR_MENU_VIEWPORT_PADDING, 900);
+});
+
+test("sidebar floating menu keeps its anchor position when there is room", () => {
+ assert.equal(clampSidebarFloatingMenuTop(240, 900), 240);
+});
+
+test("sidebar floating menu uses viewport padding in a short window", () => {
+ assert.equal(clampSidebarFloatingMenuTop(240, 300), SIDEBAR_MENU_VIEWPORT_PADDING);
+});
diff --git a/apps/desktop/test/sidebar-navigation.test.mjs b/apps/desktop/test/sidebar-navigation.test.mjs
index a790c2eba..e5926830a 100644
--- a/apps/desktop/test/sidebar-navigation.test.mjs
+++ b/apps/desktop/test/sidebar-navigation.test.mjs
@@ -185,10 +185,12 @@ test("sidebar floating menus open to the anchor's right", () => {
assert.match(triggerPlacement, /left:\s*Math\.max\(/);
assert.match(triggerPlacement, /rect\.right \+ 4/);
+ assert.match(triggerPlacement, /top:\s*clampSidebarFloatingMenuTop\(rect\.bottom \+ 4, window\.innerHeight\)/);
assert.doesNotMatch(triggerPlacement, /window\.innerWidth/);
assert.doesNotMatch(triggerPlacement, /right:\s*Math\.max/);
assert.match(pointPlacement, /left:\s*Math\.max\(/);
assert.match(pointPlacement, /x \+ 4/);
+ assert.match(pointPlacement, /top:\s*clampSidebarFloatingMenuTop\(y \+ 4, window\.innerHeight\)/);
assert.doesNotMatch(pointPlacement, /window\.innerWidth/);
assert.match(sidebarSource, /placeMenuAtPoint\(event\.clientX, event\.clientY\)/);
assert.match(sidebarSource, /left: menuPosition\.left/);
@@ -204,7 +206,7 @@ test("portaled sort menu does not stretch to the viewport edge", () => {
assert.match(basePopoverRule, /position:\s*fixed;/);
assert.doesNotMatch(basePopoverRule, /position:\s*absolute;/);
- assert.match(basePopoverRule, /max-height:\s*calc\(100vh - 16px\);/);
+ assert.match(basePopoverRule, /max-height:\s*min\(360px,\s*calc\(100vh - 16px\)\);/);
assert.match(basePopoverRule, /overflow-y:\s*auto;/);
assert.match(floatingPopoverRule, /top:\s*auto;/);
assert.match(floatingPopoverRule, /right:\s*auto;/);
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 2637abde0..41e3d7769 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -271,7 +271,8 @@ may be retained while exactly one workspace supplies the visible shell context.
permanent delete, and the folder on disk is never touched. A project whose
turn is still live still opens the confirmation dialog that names those
sessions and stops them first; an idle project is removed on that second
- click.
+ click. Sidebar overflow menus stay inside the window; a tall menu scrolls
+ within the available viewport so its last action remains reachable.
- **Create branch** snapshots an idle conversation's complete active
transcript into an independent session in the same project/Temporary scope.
The command is disabled while the source runs. Success selects the child and
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 6093b0f3c..abe612b25 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -2823,13 +2823,18 @@ identify the platform validation still needed.
#### E2E-021: Delete session works
-- **Preconditions**: Session exists.
-- **Steps**: 1) Delete a session. 2) Observe session list.
-- **Expected**: Session removed from list; data gone.
-- **Specs linked**: `03-runtime/04-data-storage.md`
+- **Preconditions**: A session exists near the bottom of the expanded Sidebar.
+- **Steps**: 1) Open its overflow menu. 2) Verify the menu and Delete action stay
+ inside the window. 3) Repeat in a short window and scroll the menu to its last
+ action. 4) Delete the session and observe the session list.
+- **Expected**: The menu stays within the viewport, the last action is reachable,
+ and the deleted session disappears from the list with its data removed.
+- **Specs linked**: `03-runtime/04-data-storage.md`,
+ `04-ux/09-interaction-patterns.md`
- **Acceptance**: F (delete session)
- **Milestone**: M2
-- **Status**: Draft
+- **Status**: Unit-covered (`sidebar-floating-menu.test.mjs`,
+ `sidebar-navigation.test.mjs`); rendered viewport scenario Draft
#### E2E-021a: Rename session title persists without changing activity
diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
index 379f31dcf..448de7e80 100644
--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
@@ -214,6 +214,7 @@
该行。武装会在几秒后自行失效,因此一行永远不会停留在“再点一次就永久删除”的状态,磁盘
上的文件夹也永远不会被触碰。仍有运行中轮次的项目依然会打开确认对话框,由它指明这些会话
并先将其停止;空闲的项目在第二次点击时即被移除。
+ 侧边栏溢出菜单保持在窗口范围内;较高的菜单会在可用视口内滚动,确保最后一项仍可访问。
- **创建分支**快照空闲对话的完整活动状态
转录到同一 project/Temporary 范围内的独立会话中。
当源运行时该命令被禁用。成功选择了孩子
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 6eff2b4e0..29fc08f03 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -1191,13 +1191,16 @@ task-candidate E2E 从请求工作树运行,但使用主工作区已经准备
#### E2E-021:删除会话作品
-- **先决条件**:会话存在。
-- **步骤**:1) 删除会话。 2) 观察会话列表。
-- **预期**:会话已从列表中删除;数据不见了。
-- **链接规格**:`03-runtime/04-data-storage.md`
+- **先决条件**:展开的侧边栏底部附近有一个会话。
+- **步骤**:1) 打开该会话的溢出菜单。 2) 确认菜单和“删除”操作均处于窗口范围内。
+ 3) 在较短的窗口中重复,并滚动菜单到最后一项。 4) 删除会话并观察会话列表。
+- **预期**:菜单保持在视口内,最后一项可访问;删除后会话从列表消失且数据已移除。
+- **链接规格**:`03-runtime/04-data-storage.md`、
+ `04-ux/09-interaction-patterns.md`
- **接受**:F(删除会话)
- **里程碑**:M2
-- **状态**:草案
+- **状态**:单元测试覆盖(`sidebar-floating-menu.test.mjs`、
+ `sidebar-navigation.test.mjs`);视口交互场景仍为草案
#### E2E-036:设置会话导入目的地已移除