Skip to content

maple-agent: one popup primitive for every menu (fixes #997) - #1002

Merged
AnthonyRonning merged 5 commits into
masterfrom
codex-popups-maple
Sep 23, 2026
Merged

AnthonyRonning merged 5 commits into
masterfrom
codex-popups-maple

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #997. An alternative to #999, for comparison.

Why

Each popup in Maple Agent was wired by hand. Each one decided for itself how it opened, how it closed on an outside press, whether it blocked the pointer, whether it took focus, and whether the keyboard reached it. They had drifted apart, and #997 was one symptom. Reviewing #999 turned up these problems on master:

  • Second press (maple-agent: Clicking on a popup menu that is already open should dismiss it #997). A second press on a menu's button reopened it. The menu's outside-press handler closed it during the press, and the button's click opened it again.
  • Header project menu. It never closed on an outside press.
  • Sidebar menus. Presses went through them to the rows underneath.
  • Keyboard. Only the header project menu had arrow-key and Enter support. Application Vim reached the sidebar menus and settings dropdowns through special-case routing, and couldn't reach the composer menus at all.
  • Escape. Escape closed a menu only after everything else. With a permission card showing, Escape denied the permission and left the menu open.
  • Path field. Typing into the project menu's path field landed in the composer. Enter there picked the highlighted row instead of the typed path.
  • Switcher. Each project's "…" button never appeared, because its hover group was never declared.

#999 fixes the second press by taking every press on every popup button in the capture phase. That swallows the press before other popups see it. As a result:

  • Another open popup no longer closes.
  • A press on a sidebar menu item can open the menu of the row underneath.
  • The buttons lose their pressed state, and their tooltips stay up after the press.

What

ui/popup.rs is one shared implementation. It was written without copying Zed's code. The behavior follows native menus and Zed's PopoverMenu:

  • Popup<V, K>. Holds which of a view's menus is open, the highlighted item, and focus. Each view that owns menus has one. A menu inside another menu gets its own.
  • Popup::trigger. A click on the button opens or closes the menu. While the menu is open, a press on the button closes it and is consumed. A closed button stays an ordinary button: it shows its pressed state, and other open popups still see the press.
  • Menu and MenuItem. The open menu is rebuilt on every render from the view's state, so live changes show without a rebuild step. Menus can have items, headers, separators, radio rows, switch rows, custom content, and a row's own control such as a "…" button.
  • Keyboard. The open menu holds focus:
    • Up/Down and j/k move the highlight.
    • Home/End and g g/G jump to the first or last item.
    • Enter or Space picks the highlighted item.
    • Escape closes the menu.
    • Typing a letter jumps to the next item that starts with it.
    • The pointer moves the same highlight.
    • A text field inside a menu keeps its own keys.
  • Focus. Anything else that takes focus closes the open menu, so one menu is open per window across the chat, sidebar, settings, and text fields. Deactivating the window closes it too. Focus returns to where it was when the menu closes, even when the menu's view stops drawing it (the sidebar hidden with ⌘B).
  • Placement. A menu opens on its preferred side of its button. It flips to the other side when only that side has room, and it stays inside the window, so it doesn't cover its own button. In a window smaller than the menu, the menu narrows and scrolls to fit. A menu that opens on the current choice scrolls that choice into view.
  • Panels. Panels draw above everything and block the pointer. A menu opened inside another counts as inside it: a project's menu in the switcher, or a text field's right-click menu inside the project menu.
  • Accessibility. Assistive technology sees:
    • menu and menu-item roles, with names
    • the button's expanded state
    • the highlighted item
    • each settings dropdown's name and value

Every popup now uses it:

  • the header project menu
  • the composer's model, approval-mode, and integrations menus
  • the transcript's right-click menu
  • the text-field right-click menu with spelling suggestions
  • the sidebar's project switcher, with its per-project menus
  • the sidebar's per-task menus
  • the settings dropdowns

The project menu's key bindings become generic Menu bindings: menu.*, plus application_vim.menu.* for Application Vim. Overrides saved under the old slot ids still apply, and they move to the new ids on the next edit. The component guide now asks new popups to use the primitive.

Behavior changes to look at

  • Placement. Menus open next to the button that opened them. The composer menus used to open at a fixed spot above the composer. Near a window edge, a menu opens on the other side of its button.
  • Current choice. Every menu shows a check mark on the current choice, and a dropdown opens on it.
  • Keyboard. Sidebar menus and settings dropdowns take the keyboard.
    • Application Vim g g/G now work in dropdowns. They used to be refused with a notice.
    • Count prefixes such as 3j no longer apply inside a menu, because a digit there is type-ahead.
    • ctrl-w region moves wait until the menu closes.
  • "…" buttons. A row's "…" button stays visible and pressed while its menu is open, and its tooltip is hidden.
  • Renaming in the switcher. Escape in a project's rename field ends the rename, and the switcher stays open. Enter commits the rename, and the switcher stays open too.
  • Text-field menu. A text field's right-click menu no longer passes Backspace, the arrow keys, or paste through to the text behind it.
  • New-project button. The sidebar's new-project button is no longer nested inside the projects header button.

Testing

just ci passes: fmt, all four clippy configurations, and all tests.

New tests:

  • The primitive (ui/popup.rs, 22 tests):
    • a second press on the button, and a press outside
    • switching menus, one menu per window across views, and focus returning after one menu replaces another
    • the keyboard (arrows, Home/End, Space, disabled rows, type-ahead) and Application Vim
    • the pointer highlight, which skips disabled rows, and a highlight that stays on its item when rows arrive above it
    • occlusion and nested menus
    • a press on a row's own control, with each event delivered twice in one frame
    • the button's pressed state
    • closing when the window deactivates, and handing focus back when the view stops drawing the menu
    • opening above a button near the bottom of the window, fitting a window smaller than the menu, and the placement rules
    • scrolling the current row into view, also when the view renders twice in one frame
  • Chat (window tests):
    • maple-agent: Clicking on a popup menu that is already open should dismiss it #997 on every popup button
    • one menu at a time, opened by pointer or by shortcut
    • a press on a menu item that sits over another row's button runs that item
    • the header project menu closing on an outside press
    • the path field: focus, typing, Enter, Escape, Application Vim letters, and its own right-click menu
    • renaming a project in the switcher
    • hiding the sidebar with a sidebar menu open
  • Settings:
  • Text field: the right-click menu skips disabled rows, keeps keys away from the text, and returns focus to the field.
  • Shortcuts: overrides saved under a renamed slot still apply, and the conflict check covers the context pairs that menus make possible.

The tests for the main fixes fail when those fixes are reverted.

I also checked the running app with cua-driver:

  • maple-agent: Clicking on a popup menu that is already open should dismiss it #997 on the switcher, a task menu, the model chip, and a settings dropdown
  • nested project menus
  • menus flipping near the window's bottom edge, and the project menu in a window narrower than it
  • ⌘B with a menu open
  • renaming a project in the switcher
  • the voice dropdown opening on a choice far down its list
  • Backspace with the composer's right-click menu open
  • the accessibility tree

One note for automated checks: cua-driver's background clicks deliver each click twice in one frame. The popup's own rows handle that. A sidebar task row, though, still registers a click when one of its buttons is pressed that way. Real input can't do this, because a frame is drawn between two presses.

🤖 Generated with Claude Code

AnthonyRonning and others added 5 commits September 23, 2026 00:08
Every popup wired its own open flag, outside-press handler, occlusion,
focus, and keyboard handling, and they had drifted apart. A second
press on a menu's button reopened it (#997). The header's project menu
never closed on an outside press. Sidebar menus let presses through to
the rows beneath them. Only one menu took the keyboard.

ui/popup.rs now owns that behavior. A view keeps a Popup: which of its
menus is open, the highlighted row, and focus. It rebuilds the open
menu as a Menu of MenuItems on every render. A trigger takes the press
in the capture phase only while its menu is open, so a closed trigger
stays an ordinary button. The open menu holds focus: arrows or j/k
move the highlight, Enter or Space picks, Escape closes, a letter jumps
to a matching row, and focus returns where it was. Whatever takes focus
next closes the menu, so at most one menu is open per window, across
views.

The chat's project, composer, and transcript menus and the sidebar's
switcher, project, and task menus move onto it. The project menu's
key bindings become generic Menu bindings. Overrides saved under the
old slot ids still apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The settings dropdowns and a text field's right-click menu move onto
ui/popup.rs, so every menu in the app now behaves the same way. A
dropdown opens on its saved value and takes the keyboard. Application
Vim's j/k, g g, and G now work inside it. The first and last keys used
to be refused with a notice. The right-click menu skips its disabled
edit rows and gives the field its focus back when it closes.

widgets::menu_row has no callers left and is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Escape now closes any open menu, the chat's or the sidebar's, before it
does anything else, in chat and in Settings. An open menu normally
handles Escape itself because it has focus. This covers a menu that
has not taken focus yet.

The Agent guide now says every dropdown, overflow menu, and context
menu goes through ui/popup.rs, and what that module handles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An independent review of the popup primitive found these, fixed here:

- Near the window edge a menu shifted over its own trigger, so a second
  press ran the row under it. A menu now opens on its preferred side of
  the trigger, flips to the other side when only that one has room, and
  stays inside the window.
- A menu whose view stopped drawing it (the sidebar hidden with Cmd-B)
  left focus on a panel that was gone. Focus that did not move on goes
  back as soon as the menu closes. The popups' shared registry holds
  weak handles.
- A menu opened on a highlighted row did not scroll it into view: GPUI
  scrolls with the previous frame's viewport. The row now comes into
  view in the panel's second frame.
- The highlight is kept by item id, so a row that loads late above it
  (the trust row) no longer moves it to another item.
- A text field inside a menu keeps its keys. Application Vim's `g g`
  no longer holds back a typed "g", the path field gets focus when it
  is offered, and Escape goes to the view first: in a project's rename
  field it ends the rename and the switcher stays open. A menu opened
  inside another (a field's right-click menu) counts as inside it.
- A text field's right-click menu sits beside the field's key context,
  so keys it does not bind no longer edit the text behind it.
- A press on a row's own control (a project's "...") never clicks the
  row, even when the press arrives twice in one frame.
- Menu items and settings dropdowns have accessible names, and a
  disabled row no longer highlights under the pointer.

The shortcut conflict check learns the context pairs menus make
possible.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Placement moved a menu inside the window but kept its size, so a menu
wider than the window (the 480 px project menu in a narrow window) ran
past the right edge, and one taller than the window ran past the
bottom. The window has no minimum size. Every panel now takes the
window less its margins as its largest size and scrolls, so it always
fits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AnthonyRonning
AnthonyRonning marked this pull request as ready for review September 23, 2026 04:58
@AnthonyRonning
AnthonyRonning merged commit cef9054 into master Sep 23, 2026
22 checks passed
@AnthonyRonning
AnthonyRonning deleted the codex-popups-maple branch September 23, 2026 06:08
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.

maple-agent: Clicking on a popup menu that is already open should dismiss it

1 participant