Skip to content

feat(chat): opt-in radial context menu on the transcript background - #1919

Merged
vastsa merged 5 commits into
vastsa:mainfrom
Linuxdazhao:feat/radial-context-menu
Oct 27, 2026
Merged

vastsa merged 5 commits into
vastsa:mainfrom
Linuxdazhao:feat/radial-context-menu

Conversation

@Linuxdazhao

@Linuxdazhao Linuxdazhao commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Implements the radial menu proposed in #1909, with the settings customization you asked for: one switch plus four direction pickers, so each user decides what their ring carries.

Closes #1909.

What it does

  • Opt-in. AppSettings.radialMenu.enabled defaults to off, so upgrading keeps the vertical background menu. The card lives in Settings → AI → Radial context menu, after Defaults.
  • One surface only. With the switch on, a right-click on the empty transcript background opens a four-sector ring centred on the pointer instead of the vertical conversation menu. Message rows, links, file references, tool rows, the sidebar, and the work panel keep their existing menus.
  • Per-direction actions. Each picker stores one RadialMenuAction: copy conversation, select conversation text, copy last answer, scroll to top, jump to latest, open the built-in browser, open the work panel, open the project folder, or Leave empty. An empty direction renders a disabled sector instead of reshaping the ring. Actions the surface cannot run stay visible and disabled: copy last answer before answer text exists, and the three open actions on a remote session (open project folder also without a project path). The work panel direction follows the panel: Open work panel while collapsed, Close work panel while open. There is no terminal action because the work panel ships no terminal surface.
  • Pointer and keyboard. The sector under the pointer highlights and a click runs it. Arrow keys walk the ring, Enter runs the highlighted action, Escape or Tab closes, and outside press, scroll, resize, or blur dismiss it. Focus returns to whatever the right-click interrupted.
  • Placement. Same floating-layer contract as ContextMenu: viewport-fixed portal measured before reveal, clamped inside the window with the 8 px margin.

Settings and validation

  • AppSettings.radialMenu is added to @pi-desktop/shared, with the action vocabulary and normalization shared by the renderer and Electron Main.
  • An absent preference, a non-boolean enabled, or an unknown action resolves per direction to the defaults (up: copy conversation, right: select conversation text, down: jump to latest, left: scroll to top).
  • Writes naming an unknown action are rejected at both boundaries (INVALID_PARAMS).

Specs and tests

  • docs/spec/04-ux/09-interaction-patterns.md §1.11 (new), docs/spec/04-ux/06-settings-ia.md, and the mirrored zh-CN pages.
  • New E2E scenario E2E-CHAT-radial-background-menu in docs/spec/06-delivery/04-e2e-test-plan.md and its zh-CN mirror.
  • New apps/desktop/test/radial-menu.test.mjs; settings-roundtrip.test.mjs now covers normalization and rejection on both sides.
  • All nine shipped catalogs carry the new strings, so packages/i18n key-parity and renderer-key checks pass.

Validation

  • pnpm --filter @pi-desktop/desktop typecheck — pass
  • pnpm --filter @pi-desktop/desktop build — pass
  • pnpm --filter @pi-desktop/desktop lint (style tokens) — pass
  • pnpm --filter @pi-desktop/i18n test — 31 pass
  • node --test on radial-menu, settings-roundtrip, and the three chat-context-menu suites — 27 pass
  • pnpm test:e2e:radial-menu — pass. The probe renders the real component in Chromium and checks the four labels, pointer highlight, click and hub paths, the disabled sector, Escape, arrow-key focus, and viewport clamping.
  • node --test test/*.test.mjs — 4423 pass, 2 fail, both environmental: the SSH askpass test reads this shell's SSH_ASKPASS=/usr/bin/false, and one MCP slow-server timeout passes when the file is rerun alone.
  • pnpm check:pr-base — head is the base (5aa253883c4e)

Manual run (macOS dev build, seeded local session)

  • Settings → AI shows the card; the switch gates the four pickers, and each picker lists all nine actions with the current one checked.
  • Right-clicking the empty transcript background opens the ring at the pointer. Clicking Open browser revealed the work panel on a blank Browser tab; with the panel open the work panel direction read Close work panel and collapsed it; Copy last answer put the newest answer on the clipboard.
  • The switch and the four directions survived app restarts.
  • First run showed truncated sector labels ("Open brows…"), so the labels moved to the hub; sectors now carry icons only.

Risks and gaps

  • The full desktop journey is manual. The component is exercised in Chromium, but the documented E2E-CHAT-radial-background-menu path through a real session and Settings is not automated.
  • Config sync. radialMenu is not added to the host-core portable application fields, so config sync would not carry this preference between machines. Say the word if that is in scope for this change.
  • No ADR. This changes presentation and adds one optional settings object; it does not move a process, IPC, or storage boundary. Happy to write an ADR if you would rather record the decision.

@vastsa

vastsa commented Oct 27, 2026

Copy link
Copy Markdown
Owner

感谢 PR,我会尽快审核!

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the geometry, the interaction model, and the settings path. The parts that usually go wrong in a radial control are right:

  • Opt-in is real and defensive. resolveRadialMenu (lib/radial-menu.ts) gates on raw?.enabled === true and resolves each direction independently through isRadialMenuAction, so a partial write, an unknown action from a newer build, or a missing object still yields four usable slots rather than a ring with holes.
  • The hit test agrees with the drawing. ITEM_ANGLES = [-90, 0, 90, 180] (up/right/down/left) matches slotAt's (degrees + 135 + 360) % 360 mapping, and the ±45° boundaries fall exactly on the drawn SECTOR_ANGLES, so a click near a seam lands in the sector the user sees highlighted.
  • Click resolves from the click point, not the last pointer move. That is the case a right-click followed immediately by a left-click would otherwise miss, and it is easy to get wrong.
  • Dismissal covers the floating-layer contract — outside pointerdown and contextmenu, scroll in capture, resize, blur, Escape with stopPropagation — and the ring restores focus to whatever owned it before the right-click instead of stranding focus on body.
  • It is a second presentation, not a second menu. The interception sits inside the existing background handler, so message rows, links and file references keep the vertical list.

Three non-blocking observations:

  1. A disabled slot is silent: select() returns without feedback and the sector stays clickable. A configured action that the current conversation cannot fill (for example copy-conversation on an empty thread) will look like a broken ring. aria-disabled on the item plus a dimmed sector would say "nothing to copy" rather than "the menu did nothing".
  2. onPointerMove drives activeIndex, and the effect at RadialMenu.tsx focuses itemRefs[activeIndex], so sweeping the pointer moves DOM focus. preventScroll: true already limits the damage, but if this ring ever opens over the settings dialog the focus churn will be visible. Consider focusing only for keyboard-driven changes (a modality flag).
  3. The viewport clamp is Math.max(MARGIN, Math.min(point - OUTER_RADIUS, innerWidth - width - MARGIN)). Below 2 * OUTER_RADIUS + 2 * MARGIN (336 px) the outer max wins and the 320 px ring extends past the right or bottom edge. Clamping the far edge after the near edge would keep it inside at any width.

The settings card placement under AI, after Defaults, matches how the other opt-in surfaces are grouped, and putting the four pickers next to the switch is what makes this discoverable without a second screen.

Keep keyboard navigation usable when a ring direction is disabled,
and match the transcript menu by disabling copy for empty sessions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 对话空白区右键改为四向环形快捷菜单

3 participants