Repository navigation
feat(plugins): let panels add tab menu actions #4267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,11 @@ export type PanelWorkspaceItem = { | |
| /** Header icon actions for this tab's content, shown while it is selected. */ | ||
| toolbar?: ReactNode; | ||
| }; | ||
| type Identity = { label: string; icon?: ReactNode }; | ||
| type Identity = { | ||
| label: string; | ||
| icon?: ReactNode; | ||
| actions?: readonly TabAction[] | undefined; | ||
| }; | ||
| /** `keepOwner`: the owner stays open; only its detail tabs are cleared. */ | ||
| type Close = (options?: { keepOwner?: boolean }) => void; | ||
| type Local = { id: string; label: string; owner: string; close: Close }; | ||
|
|
@@ -60,15 +64,19 @@ export function usePanelTabHost() { | |
| return useContext(TabHost); | ||
| } | ||
|
|
||
| export function usePanelTabTitle(label: string, icon?: ReactNode) { | ||
| export function usePanelTabTitle( | ||
| label: string, | ||
| icon?: ReactNode, | ||
| actions?: readonly TabAction[], | ||
| ) { | ||
| const host = usePanelTabHost(); | ||
| const title = host?.title; | ||
| const owner = host?.owner; | ||
| useLayoutEffect(() => { | ||
| if (!title || !owner) return; | ||
| title(owner, { label, icon }); | ||
| title(owner, { label, icon, actions }); | ||
| return () => title(owner, undefined); | ||
| }, [title, owner, label, icon]); | ||
| }, [title, owner, label, icon, actions]); | ||
| } | ||
|
|
||
| // Keyboard opens and reduced motion skip the push. Deciding here, rather than | ||
|
|
@@ -214,16 +222,22 @@ export function PanelWorkspace({ | |
| (tab) => tab.id === localSelection && tab.owner === value, | ||
| ); | ||
| const selected = selectedLocal?.id ?? value; | ||
| const tabs = items.flatMap((item) => [ | ||
| { | ||
| ...item, | ||
| ...titles[item.id], | ||
| icon: titles[item.id]?.icon ?? item.icon ?? <BrowserIcon size="1rem" />, | ||
| }, | ||
| ...owned | ||
| .filter((tab) => tab.owner === item.id) | ||
| .map((tab) => ({ ...tab, icon: <TerminalWindowIcon size="1rem" /> })), | ||
| ]); | ||
| const tabs = items.flatMap((item) => { | ||
| const title = titles[item.id]; | ||
| return [ | ||
| { | ||
| ...item, | ||
| ...title, | ||
| icon: title?.icon ?? item.icon ?? <BrowserIcon size="1rem" />, | ||
| actions: title?.actions | ||
| ? [...title.actions, ...(item.actions ?? [])] | ||
| : item.actions, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [P3] Preserve keyboard focus when a highlighted dynamic action disappears With a host action and a plugin action present, open the tab menu with Shift+F10, use ArrowDown to focus the plugin item, then withdraw that contribution. In the actual application under Playwright WebKit, focus moves to body while the mixed menu remains open, and ArrowDown stops navigating (4/4 repeats). Escape recovers; Chromium instead focuses the host action. This also reproduces on the earlier feature head 6245640, so it is a gap in the new dynamic-action path rather than a regression specific to the final fix commit. Native WKWebView was not tested. When removal takes away the focused item, move focus to a remaining item/popup or close the menu and return focus to the tab. Add a WebKit regression for this mixed-menu case. |
||
| }, | ||
| ...owned | ||
| .filter((tab) => tab.owner === item.id) | ||
| .map((tab) => ({ ...tab, icon: <TerminalWindowIcon size="1rem" /> })), | ||
| ]; | ||
| }); | ||
| const active = tabs.find((tab) => tab.id === selected); | ||
| const choose = (id: string) => { | ||
| const local = owned.find((tab) => tab.id === id); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,13 +373,19 @@ export function TabMenu({ | |
| closeOthers: (() => boolean) | undefined; | ||
| children: ReactNode; | ||
| }) { | ||
| const hasMenu = !!(actions?.length || onRename || closeAll || closeOthers); | ||
| const [open, setOpen] = useState(false); | ||
| const trigger = useRef<HTMLElement>(null); | ||
| const [anchor, setAnchor] = useState<HTMLElement>(); | ||
| const closingAll = useRef(false); | ||
| // A host action runs once the menu has closed, from its tab, so a | ||
| // destination it opens can take focus from there. | ||
| const afterClose = useRef<() => void>(undefined); | ||
| useLayoutEffect(() => { | ||
| if (hasMenu) return; | ||
| afterClose.current = undefined; | ||
| setOpen(false); | ||
| }, [hasMenu]); | ||
| // Middle-click closes a closable tab, without the browser's own default. | ||
| const item = { | ||
| className: "buzz-tabs-item", | ||
|
|
@@ -393,20 +399,23 @@ export function TabMenu({ | |
| onClose(); | ||
| }, | ||
| }; | ||
| if (!actions?.length && !onRename && !closeAll) | ||
| return <span {...item}>{children}</span>; | ||
| return ( | ||
| <ContextMenuRoot | ||
| open={open} | ||
| onOpenChange={(next) => { | ||
| disabled={!hasMenu} | ||
| open={hasMenu && open} | ||
| onOpenChange={(next, details) => { | ||
| if (next && !hasMenu) { | ||
| details.cancel(); | ||
| return; | ||
| } | ||
| if (next) closingAll.current = false; | ||
| setOpen(next); | ||
| }} | ||
| onOpenChangeComplete={(next) => { | ||
| if (next) return; | ||
| const action = afterClose.current; | ||
| afterClose.current = undefined; | ||
| if (!action) return; | ||
| if (!hasMenu || !action) return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [P3] Cancel a withdrawn queued action even when host menu items remain Select a plugin action, then withdraw its contribution before the exit animation finishes. With plugin-only actions the queued callback is cleared, but when a host action or closeAll remains, hasMenu stays true and the retired callback still runs. An actual-app probe reproduced this in Chromium and WebKit 4/4 each, withdrawing 80–110 ms before close completion and observing the callback run after its contributor unmounted. A component probe independently gives runs=0 without host actions and runs=1 with them. The earlier finding #4267 (comment) is fixed for whole-menu withdrawal; the mixed-menu case exposes the remaining limitation of this fix. Apply one cancellation rule based on whether the selected contribution remains current, rather than global menu availability. Add a committed regression covering selected-action withdrawal both with and without host actions. Removing both cancellation guards still leaves all 242 panel/design-system tests passing; the new component probe detects the plugin-only regression as well as the mixed-menu defect. |
||
| trigger.current | ||
| ?.querySelector<HTMLElement>('[role="tab"], button') | ||
| ?.focus(); | ||
|
|
@@ -422,8 +431,9 @@ export function TabMenu({ | |
| onTouchStart={() => setAnchor(undefined)} | ||
| onKeyDown={(event) => { | ||
| if ( | ||
| event.key === "ContextMenu" || | ||
| (event.shiftKey && event.key === "F10") | ||
| hasMenu && | ||
| (event.key === "ContextMenu" || | ||
| (event.shiftKey && event.key === "F10")) | ||
| ) { | ||
| event.preventDefault(); | ||
| closingAll.current = false; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.