mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
feat(app): try a per-message menu in the timeline gutter (#58164)
This commit is contained in:
committed by
GitHub
Unverified
parent
47d6a9d0e4
commit
4c66a516f3
@@ -0,0 +1,18 @@
|
||||
import { motionTuning } from "@opencode/ui/motion-tuning"
|
||||
import { createSignal } from "solid-js"
|
||||
|
||||
const toggle = motionTuning.toggle("session.messageMenu", {
|
||||
label: "Message menu",
|
||||
group: "Experiments",
|
||||
card: "Experiments",
|
||||
// Ahead of the card's other rows (order 1), so it sits at the top of the EXPERIMENTS card.
|
||||
order: 0,
|
||||
value: false,
|
||||
})
|
||||
|
||||
const [enabled, setEnabled] = createSignal(toggle())
|
||||
|
||||
motionTuning.subscribe(() => setEnabled(toggle()))
|
||||
|
||||
/** Experiment: a ⋯ menu per message in a 28px trailing gutter replaces the hover info line, and turns sit 24px apart. */
|
||||
export const messageMenu = enabled
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
import { SessionHeaderSpacer } from "@/session/header/session-header"
|
||||
import { SessionHeaderGap } from "@/session/header/drag-area"
|
||||
import { SessionWorkingIndicator } from "@/session/header/session-working-indicator"
|
||||
import { messageMenu } from "@/session/timeline/message-menu"
|
||||
|
||||
type BlockingTask = { type: "shell" | "subagent"; partID: string; id?: string; label?: string }
|
||||
|
||||
@@ -170,7 +171,8 @@ function MessageTimelineView(
|
||||
if (!directory) return
|
||||
void data.location.vcs.sync({ directory }).catch(() => undefined)
|
||||
})
|
||||
const turnPadding = () => "px-4 md:px-6"
|
||||
// The message menu experiment reserves a 28px trailing gutter (24px button + 4px gap) for its ⋯ button.
|
||||
const turnPadding = () => (messageMenu() ? "ps-4 pe-11 md:ps-6 md:pe-13" : "px-4 md:px-6")
|
||||
const showHeader = createMemo(() => !props.hideHeader && (props.data.showHeader() || workspaceSession()))
|
||||
const pinned = createMemo(() => props.pinned)
|
||||
const messageByID = projection.messageByID
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { DataProvider } from "@opencode/session-ui/context"
|
||||
import { MarkdownProvider, type ReadMarkdownImage } from "@opencode/session-ui/context/markdown"
|
||||
import { MessageMenuProvider } from "@opencode/session-ui/context/message-menu"
|
||||
import { messageMenu } from "@/session/timeline/message-menu"
|
||||
import { useNavigate, useParams } from "@solidjs/router"
|
||||
import { createMemo, type ParentProps } from "solid-js"
|
||||
import { useProviders } from "@/providers/catalog/providers"
|
||||
@@ -140,7 +142,7 @@ export function SessionUIProvider(
|
||||
}
|
||||
>
|
||||
<MarkdownProvider readImage={readImage()} openSession={openReferencedSession} sessionTitle={sessionTitle}>
|
||||
{props.children}
|
||||
<MessageMenuProvider enabled={messageMenu()}>{props.children}</MessageMenuProvider>
|
||||
</MarkdownProvider>
|
||||
</DataProvider>
|
||||
</LocalProvider>
|
||||
|
||||
@@ -1729,3 +1729,58 @@
|
||||
color: var(--v2-text-text-muted);
|
||||
transition: none;
|
||||
}
|
||||
|
||||
/* The message options button sits in the 28px gutter the timeline reserves on the trailing side. */
|
||||
[data-component="user-message"],
|
||||
[data-component="text-part"] {
|
||||
position: relative;
|
||||
|
||||
[data-slot="message-options"] {
|
||||
position: absolute;
|
||||
top: calc(0.5lh - 12px);
|
||||
inset-inline-end: -28px;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
transition: opacity 150ms ease-out;
|
||||
|
||||
@media (hover: hover) {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover [data-slot="message-options"],
|
||||
&:focus-within [data-slot="message-options"],
|
||||
[data-slot="message-options"]:has([data-expanded]) {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
:root[data-motion="reduce"] & [data-slot="message-options"] {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Centered on the bubble's first line. */
|
||||
[data-component="user-message"] [data-slot="message-options"] {
|
||||
top: calc(8px + 0.5lh - 12px);
|
||||
}
|
||||
|
||||
[data-slot="message-options-info"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
max-width: 340px;
|
||||
padding: 4px 8px;
|
||||
font-family: var(--v2-font-family-sans);
|
||||
font-size: 12px;
|
||||
font-weight: 440;
|
||||
line-height: var(--line-height-compact);
|
||||
color: var(--v2-text-text-faint);
|
||||
user-select: text;
|
||||
cursor: default;
|
||||
|
||||
> span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { createContext, useContext, type ParentProps } from "solid-js"
|
||||
|
||||
const context = createContext<() => boolean>(() => false)
|
||||
|
||||
/** Experiment: a ⋯ menu per message in a trailing gutter replaces the hover info line, and turns sit further apart. */
|
||||
export function MessageMenuProvider(props: ParentProps<{ enabled: boolean }>) {
|
||||
return <context.Provider value={() => props.enabled}>{props.children}</context.Provider>
|
||||
}
|
||||
|
||||
export function useMessageMenu() {
|
||||
return useContext(context)
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { Markdown } from "../components/markdown"
|
||||
import { linkSegments } from "../components/link-segments"
|
||||
import { sessionReferenceText, setupSessionLinks } from "../components/markdown-session-links"
|
||||
import { useMarkdown } from "../context/markdown"
|
||||
import { useMessageMenu } from "../context/message-menu"
|
||||
import { ImagePreview } from "@opencode/ui/image-preview"
|
||||
import { getFilename } from "@opencode/util/path"
|
||||
import { AttachmentCard } from "./attachment-card"
|
||||
@@ -115,6 +116,35 @@ function MessageActionButton(
|
||||
)
|
||||
}
|
||||
|
||||
function MessageOptions(props: { info: string[]; children: JSX.Element }) {
|
||||
const i18n = useI18n()
|
||||
|
||||
return (
|
||||
<div data-slot="message-options">
|
||||
<Menu gutter={4} modal={false} placement="bottom-end">
|
||||
<Menu.Trigger
|
||||
as={IconButton}
|
||||
icon={<Icon name="outline-dots" size="small" />}
|
||||
size="normal"
|
||||
variant="ghost-muted"
|
||||
aria-label={i18n.t("ui.message.options")}
|
||||
/>
|
||||
<Menu.Portal>
|
||||
<Menu.Content>
|
||||
<Show when={props.info.length > 0}>
|
||||
<div data-slot="message-options-info">
|
||||
<For each={props.info}>{(line) => <span dir="auto">{line}</span>}</For>
|
||||
</div>
|
||||
<Menu.Separator />
|
||||
</Show>
|
||||
{props.children}
|
||||
</Menu.Content>
|
||||
</Menu.Portal>
|
||||
</Menu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function UserMessageTransition(props: { active: boolean; children: JSX.Element }) {
|
||||
return (
|
||||
<span
|
||||
@@ -289,6 +319,7 @@ export function CurrentUserMessageDisplay(props: {
|
||||
const data = useData()
|
||||
const dialog = useDialog()
|
||||
const i18n = useI18n()
|
||||
const menu = useMessageMenu()
|
||||
|
||||
const [state, setState] = createStore({ copied: false, reverting: false, updating: false })
|
||||
|
||||
@@ -317,6 +348,14 @@ export function CurrentUserMessageDisplay(props: {
|
||||
|
||||
const stamp = createMemo(() => timefmt().format(props.message.time.created))
|
||||
|
||||
const info = createMemo(() =>
|
||||
[
|
||||
waiting() ? i18n.t("ui.message.pending") : "",
|
||||
[agentLabel(props.agent, data.agents), model()].filter(Boolean).join(" \u00B7 "),
|
||||
fulltimefmt().format(props.message.time.created),
|
||||
].filter(Boolean),
|
||||
)
|
||||
|
||||
// In a run, only the last message keeps the meta line; the others offer their actions beside the bubble.
|
||||
// Bubble corners tighten where two bubbles meet, as in the iOS app's grouped corners.
|
||||
const folded = createMemo(() => !!props.run?.below && !!props.text)
|
||||
@@ -539,6 +578,29 @@ export function CurrentUserMessageDisplay(props: {
|
||||
}}
|
||||
data-timeline-part-id={props.text ? `${props.message.id}:text:0` : undefined}
|
||||
>
|
||||
<Show when={menu() && (props.text || comments().length > 0 || pending())}>
|
||||
<MessageOptions info={info()}>
|
||||
<Show when={props.actions?.pending && pending()}>
|
||||
<Menu.Item disabled={state.updating} onSelect={() => void updatePending("queue")}>
|
||||
{i18n.t("ui.message.moveToQueue")}
|
||||
</Menu.Item>
|
||||
<Menu.Item disabled={state.updating} onSelect={() => void updatePending("remove")}>
|
||||
{i18n.t("ui.message.deletePending")}
|
||||
</Menu.Item>
|
||||
</Show>
|
||||
<Show when={props.actions?.revert && !pending()}>
|
||||
<Menu.Item disabled={state.reverting} onSelect={() => void revert()}>
|
||||
{i18n.t("ui.message.revertMessage")}
|
||||
</Menu.Item>
|
||||
</Show>
|
||||
<Show when={props.text}>
|
||||
<Menu.Item onSelect={() => void copy(props.text)}>{i18n.t("ui.message.copyMessage")}</Menu.Item>
|
||||
</Show>
|
||||
<Show when={props.voice}>
|
||||
<Menu.Item onSelect={() => void copy(props.message.text)}>{i18n.t("ui.message.copyFullMessage")}</Menu.Item>
|
||||
</Show>
|
||||
</MessageOptions>
|
||||
</Show>
|
||||
{renderAttachments()}
|
||||
<Show
|
||||
when={props.text}
|
||||
@@ -562,13 +624,14 @@ export function CurrentUserMessageDisplay(props: {
|
||||
<UserMessageComments comments={comments()} bounded />
|
||||
</Show>
|
||||
</div>
|
||||
<Show when={folded()}>
|
||||
<Show when={!menu() && folded()}>
|
||||
<div data-slot="user-message-run-actions">{renderActions()}</div>
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
{/* Like the TUI, a pending steer of only attachments still offers its actions. */}
|
||||
<Show when={props.text || comments().length > 0 || pending()}>
|
||||
{/* With the message menu, a pending steer still keeps its Pending label and actions in view. */}
|
||||
<Show when={menu() ? waiting() : props.text || comments().length > 0 || pending()}>
|
||||
<div data-slot="user-message-copy-wrapper">
|
||||
<span data-slot="user-message-meta-wrap">
|
||||
<span data-slot="user-message-meta">
|
||||
@@ -818,6 +881,7 @@ export function AssistantTextContent(props: {
|
||||
}) {
|
||||
const data = useData()
|
||||
const i18n = useI18n()
|
||||
const menu = useMessageMenu()
|
||||
const numfmt = createMemo(() => new Intl.NumberFormat(i18n.locale()))
|
||||
|
||||
const interrupted = () => {
|
||||
@@ -878,7 +942,17 @@ export function AssistantTextContent(props: {
|
||||
<div data-slot="text-part-body">
|
||||
<PacedMarkdown text={props.text} cacheKey={props.id} streaming={props.message.time.completed === undefined} />
|
||||
</div>
|
||||
<Show when={props.showCopy}>
|
||||
<Show when={menu() && props.showCopy}>
|
||||
<MessageOptions
|
||||
info={[
|
||||
[agentLabel(props.message.agent, data.agents), model()].filter(Boolean).join(" \u00B7 "),
|
||||
[duration(), interrupted() ? i18n.t("ui.message.interrupted") : ""].filter(Boolean).join(" \u00B7 "),
|
||||
].filter(Boolean)}
|
||||
>
|
||||
<Menu.Item onSelect={() => void copy()}>{i18n.t("ui.message.copyResponse")}</Menu.Item>
|
||||
</MessageOptions>
|
||||
</Show>
|
||||
<Show when={!menu() && props.showCopy}>
|
||||
<div data-slot="text-part-copy-wrapper" data-interrupted={interrupted() ? "" : undefined}>
|
||||
<MessageActionButton
|
||||
icon={copied() ? "check" : "copy"}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { springStyle } from "@opencode/ui/motion/solid"
|
||||
import { Dynamic } from "solid-js/web"
|
||||
import type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
|
||||
import { useData } from "../context"
|
||||
import { useMessageMenu } from "../context/message-menu"
|
||||
import { TimelineSeparator } from "../components/timeline-separator"
|
||||
import {
|
||||
SessionAssistantContent,
|
||||
@@ -87,6 +88,7 @@ export function createSessionTimelineRowRenderer(input: {
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
const data = useData()
|
||||
const menu = useMessageMenu()
|
||||
// Cached timelines retain file-change subgroup identities alongside their disclosure choices.
|
||||
const patchGroupKeys = input.disclosure.patchGroupKeys ?? new Map<string, string>()
|
||||
const patchPartKeys = new WeakMap<SessionMessageAssistant["content"][number], string>()
|
||||
@@ -823,9 +825,10 @@ export function createSessionTimelineRowRenderer(input: {
|
||||
function TurnGap(props: { messageID: string }) {
|
||||
let element: HTMLDivElement | undefined
|
||||
const joined = run(props.messageID)
|
||||
const turn = () => (menu() ? 24 : 16)
|
||||
springStyle(
|
||||
() => element,
|
||||
() => ({ height: joined()?.above ? 4 : 16 }),
|
||||
() => ({ height: joined()?.above ? 4 : turn() }),
|
||||
(el, value) => {
|
||||
el.style.height = `${value.height}px`
|
||||
},
|
||||
@@ -837,7 +840,7 @@ export function createSessionTimelineRowRenderer(input: {
|
||||
ref={element}
|
||||
data-timeline-row="TurnGap"
|
||||
aria-hidden="true"
|
||||
style={{ height: untrack(joined)?.above ? "4px" : "16px" }}
|
||||
style={{ height: untrack(joined)?.above ? "4px" : `${untrack(turn)}px` }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ const source = {
|
||||
"ui.message.expand": "Expand message",
|
||||
"ui.message.collapse": "Collapse message",
|
||||
"ui.message.copy": "Copy",
|
||||
"ui.message.options": "Message options",
|
||||
"ui.message.copyMessage": "Copy message",
|
||||
"ui.message.copyFullMessage": "Copy full message",
|
||||
"ui.message.forkMessage": "Fork to new session",
|
||||
|
||||
Reference in New Issue
Block a user