Repository navigation
maple-agent: one popup primitive for every menu (fixes #997) - #1002
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
#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:
What
ui/popup.rsis one shared implementation. It was written without copying Zed's code. The behavior follows native menus and Zed'sPopoverMenu: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.MenuandMenuItem. 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.g g/Gjump to the first or last item.Every popup now uses it:
The project menu's key bindings become generic
Menubindings:menu.*, plusapplication_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
g g/Gnow work in dropdowns. They used to be refused with a notice.3jno longer apply inside a menu, because a digit there is type-ahead.ctrl-wregion moves wait until the menu closes.Testing
just cipasses: fmt, all four clippy configurations, and all tests.New tests:
ui/popup.rs, 22 tests):j,G,g g, Enter, Escape)The tests for the main fixes fail when those fixes are reverted.
I also checked the running app with cua-driver:
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