Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(docs): unify doc comment card actions and selection (MUL-10209) (#11577)

Jiayuan Zhang12a7f95bd344
diff --git a/e2e/docs.spec.ts b/e2e/docs.spec.ts
index b498fb1334..4e7169c61d 100644
--- a/e2e/docs.spec.ts
+++ b/e2e/docs.spec.ts
@@ -494,4 +494,11 @@ test("comment on selected text, reply, find it again after reload, resolve and r
await panel.getByRole("button", { name: "Reopen", exact: true }).click();
await expect(panel.getByRole("tab", { name: "Open 1" })).toHaveAttribute("aria-selected", "true");
await expect(panel.getByRole("group", { name: selected! })).toBeVisible();
+
+ // Clicking elsewhere in the text lets go of it: the card folds to its first
+ // message and a reply count.
+ await expect(panel.getByRole("group", { name: selected! }).getByText("Yes, with CONCURRENTLY.", { exact: true })).toBeVisible();
+ await editor.getByText("Confirm the rollback owner.").click();
+ await expect(panel.getByRole("group", { name: selected! }).getByText("Yes, with CONCURRENTLY.", { exact: true })).toHaveCount(0);
+ await expect(panel.getByRole("group", { name: selected! })).toContainText("1 reply");
});
diff --git a/packages/views/docs/components/doc-comments-panel.test.tsx b/packages/views/docs/components/doc-comments-panel.test.tsx
new file mode 100644
index 0000000000..dd2bf6b3e1
--- /dev/null
+++ b/packages/views/docs/components/doc-comments-panel.test.tsx
@@ -0,0 +1,170 @@
+import { forwardRef, useImperativeHandle, useState } from "react";
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vitest";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { I18nProvider } from "@multica/core/i18n/react";
+import type { DocComment } from "@multica/core/types";
+import { DocCommentsPanel, groupDocThreads } from "./doc-comments-panel";
+import enDocs from "../../locales/en/docs.json";
+
+const { createMock, resolveMock, removeMock } = vi.hoisted(() => ({
+ createMock: vi.fn(),
+ resolveMock: vi.fn(),
+ removeMock: vi.fn(),
+}));
+
+vi.mock("@multica/core/docs", () => ({
+ docTaskRunsOptions: (_ws: string, docId: string) => ({ queryKey: ["doc-runs", docId], queryFn: async () => [] }),
+ useCreateDocComment: () => ({ mutateAsync: createMock, isPending: false }),
+ useSetDocCommentResolved: () => ({ mutateAsync: resolveMock, isPending: false }),
+ useDeleteDocComment: () => ({ mutateAsync: removeMock, isPending: false }),
+}));
+vi.mock("@multica/core/hooks", async (original) => ({
+ ...await original<object>(), useWorkspaceId: () => "ws-1",
+}));
+vi.mock("@multica/core/auth", () => ({
+ useAuthStore: (select: (s: { user: { id: string } }) => unknown) => select({ user: { id: "me" } }),
+}));
+vi.mock("@multica/core/appearance", () => ({ useReducedMotion: () => true }));
+vi.mock("@multica/core/workspace/hooks", () => ({
+ useActorName: () => ({ getActorName: (_type: string, id: string) => (id === "me" ? "Jiayuan" : "Lambda") }),
+}));
+vi.mock("../../common/actor-avatar", () => ({ ActorAvatar: () => null }));
+vi.mock("../../common/shortcut-keycaps", () => ({ ActionShortcutKeycaps: () => null }));
+vi.mock("../../issues/components/composer-frame", () => ({ QUIET_SEND_CLASS: "" }));
+vi.mock("./doc-thread-runs", () => ({ docThreadRuns: () => [], DocThreadRun: () => null }));
+vi.mock("../../editor", () => ({
+ ReadonlyContent: ({ content }: { content: string }) => <div>{content}</div>,
+ ContentEditor: forwardRef<unknown, { placeholder: string; onUpdate: (md: string) => void }>(
+ function ContentEditor({ placeholder, onUpdate }, ref) {
+ const [value, setValue] = useState("");
+ useImperativeHandle(ref, () => ({
+ getMarkdown: () => value,
+ clearContent: () => setValue(""),
+ focus: () => {},
+ }));
+ return (
+ <textarea
+ aria-label={placeholder}
+ value={value}
+ onChange={(e) => {
+ setValue(e.target.value);
+ onUpdate(e.target.value);
+ }}
+ />
+ );
+ },
+ ),
+}));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+const QUOTE = "Migrations must rehearse";
+
+function comment(id: string, extra: Partial<DocComment> = {}): DocComment {
+ return {
+ id, docId: "d1", parentId: null, authorType: "member", authorId: "me", content: `body of ${id}`,
+ anchorQuote: QUOTE, anchorPrefix: "", anchorSuffix: "",
+ resolvedAt: null, resolvedByType: null, resolvedById: null,
+ createdAt: "2026-11-25T09:00:00Z", updatedAt: "2026-11-25T09:00:00Z", ...extra,
+ };
+}
+
+const discussion = (rootExtra: Partial<DocComment> = {}) =>
+ groupDocThreads([
+ comment("c1", rootExtra),
+ comment("c2", { parentId: "c1", authorType: "agent", authorId: "agent-1" }),
+ ]);
+
+function mount(props: Partial<Parameters<typeof DocCommentsPanel>[0]> = {}) {
+ const handlers = { onActivate: vi.fn(), onDeactivate: vi.fn(), onDraftDone: vi.fn(), onClose: vi.fn() };
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ render(
+ <QueryClientProvider client={qc}>
+ <I18nProvider locale="en" resources={{ en: { docs: enDocs } }}>
+ <DocCommentsPanel
+ docId="d1"
+ threads={discussion()}
+ missing={new Set()}
+ activeId={null}
+ draft={null}
+ {...handlers}
+ {...props}
+ />
+ </I18nProvider>
+ </QueryClientProvider>,
+ );
+ return handlers;
+}
+
+it("folds a discussion that is not selected to its first message and a reply count", () => {
+ const { onActivate } = mount();
+ const thread = screen.getByRole("group", { name: QUOTE });
+ expect(thread.textContent).toContain("body of c1");
+ expect(thread.textContent).toContain("1 reply");
+ expect(screen.queryByText("body of c2")).toBeNull();
+ expect(screen.queryByRole("textbox", { name: "Reply, or @ someone..." })).toBeNull();
+
+ fireEvent.click(thread);
+ expect(onActivate).toHaveBeenCalledWith("c1");
+});
+
+it("opens a folded discussion from the keyboard", () => {
+ const { onActivate } = mount();
+ const thread = screen.getByRole("group", { name: QUOTE });
+ expect(thread.tabIndex).toBe(0);
+ fireEvent.keyDown(thread, { key: "Enter" });
+ expect(onActivate).toHaveBeenCalledWith("c1");
+});
+
+it("unfolds the selected discussion with its replies and a reply box that sends from inside it", async () => {
+ createMock.mockResolvedValue(comment("c3"));
+ mount({ activeId: "c1" });
+ expect(screen.getByText("body of c2")).toBeTruthy();
+ expect(screen.queryByText("1 reply")).toBeNull();
+
+ const send = screen.getByRole("button", { name: "Reply" });
+ expect((send as HTMLButtonElement).disabled).toBe(true);
+ fireEvent.change(screen.getByRole("textbox", { name: "Reply, or @ someone..." }), { target: { value: "On it" } });
+ expect((send as HTMLButtonElement).disabled).toBe(false);
+ fireEvent.click(send);
+ await waitFor(() => expect(createMock).toHaveBeenCalledWith({ content: "On it", parentId: "c1" }));
+});
+
+it("resolves the selected discussion from its header and lets go of it", async () => {
+ resolveMock.mockResolvedValue({});
+ const { onDeactivate } = mount({ activeId: "c1" });
+ fireEvent.click(screen.getByRole("button", { name: "Resolve" }));
+ await waitFor(() => expect(resolveMock).toHaveBeenCalledWith({ commentId: "c1", resolved: true }));
+ await waitFor(() => expect(onDeactivate).toHaveBeenCalled());
+});
+
+it("marks a discussion whose text was edited away on the quote line", () => {
+ mount({ missing: new Set(["c1"]) });
+ const tag = screen.getByText("Text changed");
+ expect(tag.getAttribute("title")).toBe("The commented text was changed");
+});
+
+it("deletes only the viewer's own messages", async () => {
+ removeMock.mockResolvedValue({});
+ mount({ activeId: "c1" });
+ const buttons = screen.getAllByRole("button", { name: "Delete comment" });
+ expect(buttons).toHaveLength(1);
+ fireEvent.click(buttons[0]!);
+ await waitFor(() => expect(removeMock).toHaveBeenCalledWith("c1"));
+});
+
+it("reopens a resolved discussion from its header", async () => {
+ resolveMock.mockResolvedValue({});
+ const { onActivate } = mount({
+ threads: discussion({ resolvedAt: "2026-11-25T10:00:00Z", resolvedByType: "member", resolvedById: "me" }),
+ });
+ fireEvent.click(screen.getByRole("tab", { name: "Resolved 1" }));
+ expect(screen.getByText(/Resolved by Jiayuan/)).toBeTruthy();
+ fireEvent.click(screen.getByRole("button", { name: "Reopen" }));
+ await waitFor(() => expect(resolveMock).toHaveBeenCalledWith({ commentId: "c1", resolved: false }));
+ await waitFor(() => expect(onActivate).toHaveBeenCalledWith("c1"));
+});
diff --git a/packages/views/docs/components/doc-comments-panel.tsx b/packages/views/docs/components/doc-comments-panel.tsx
index 1e54e6b96a..1a205f0b95 100644
--- a/packages/views/docs/components/doc-comments-panel.tsx
+++ b/packages/views/docs/components/doc-comments-panel.tsx
@@ -1,11 +1,13 @@
"use client";
-import { useEffect, useRef, useState } from "react";
+import { useEffect, useRef, useState, type ReactNode } from "react";
import { AnimatePresence, motion } from "motion/react";
import { useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { useReducedMotion } from "@multica/core/appearance";
-import { AlertTriangle, Check, MessageSquare, RotateCcw, Trash2, X } from "@multica/ui/icons";
+import { Check, CheckCircle2, MessageSquare, RotateCcw, Trash2, X } from "@multica/ui/icons";
import { Button } from "@multica/ui/components/ui/button";
+import { IconButton } from "@multica/ui/components/common/icon-button";
+import { SubmitButton } from "@multica/ui/components/common/submit-button";
import { UI_EASE_OUT } from "@multica/ui/lib/motion";
import { cn } from "@multica/ui/lib/utils";
import { useAuthStore } from "@multica/core/auth";
@@ -20,6 +22,8 @@ import type { DocComment, DocTaskRun } from "@multica/core/types";
import { useActorName } from "@multica/core/workspace/hooks";
import { ContentEditor, ReadonlyContent, type ContentEditorRef } from "../../editor";
import { ActorAvatar } from "../../common/actor-avatar";
+import { ActionShortcutKeycaps } from "../../common/shortcut-keycaps";
+import { QUIET_SEND_CLASS } from "../../issues/components/composer-frame";
import { useT, useTimeAgo } from "../../i18n";
import type { DocAnchor } from "./doc-comment-anchors";
import { DocThreadRun, docThreadRuns } from "./doc-thread-runs";
@@ -74,7 +78,7 @@ function Composer({
);
};
return (
- <div className="mt-2 rounded-md border bg-background px-2 py-1.5">
+ <div className="mt-3 flex items-end gap-1 rounded-lg border border-input bg-background py-1 pr-1 pl-2.5 transition-[border-color,box-shadow] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 motion-reduce:transition-none">
<ContentEditor
ref={ref}
defaultValue=""
@@ -84,77 +88,171 @@ function Composer({
onUpdate={(md) => setEmpty(!md.trim())}
onSubmit={submit}
debounceMs={0}
- className="min-h-6 text-body"
+ className="max-h-48 min-h-7 min-w-0 flex-1 overflow-y-auto py-1 text-body"
/>
- <div className="mt-1 flex justify-end gap-1.5">
- {onCancel && (
- <Button size="xs" variant="ghost" onClick={onCancel}>
- {t(($) => $.comments.cancel)}
- </Button>
- )}
- <Button size="xs" disabled={empty || pending} onClick={submit}>
- {submitLabel}
+ {onCancel && (
+ <Button size="xs" variant="ghost" className="mb-0.5" onClick={onCancel}>
+ {t(($) => $.comments.cancel)}
</Button>
- </div>
+ )}
+ <SubmitButton
+ className={QUIET_SEND_CLASS}
+ onClick={submit}
+ disabled={empty}
+ loading={pending}
+ ariaLabel={submitLabel}
+ tooltip={
+ <>
+ {submitLabel}
+ <ActionShortcutKeycaps action="send" />
+ </>
+ }
+ />
</div>
);
}
-function Message({ comment, onDelete }: { comment: DocComment; onDelete?: () => void }) {
+function Message({
+ comment,
+ clamp,
+ onDelete,
+ className,
+}: {
+ comment: DocComment;
+ /** A folded discussion shows the start of its first message only. */
+ clamp?: boolean;
+ onDelete?: () => void;
+ className?: string;
+}) {
const { t } = useT("docs");
const timeAgo = useTimeAgo();
const { getActorName } = useActorName();
return (
- <div className="group/message mt-2 flex gap-2 first:mt-0">
- <ActorAvatar actorType={comment.authorType} actorId={comment.authorId} size="sm" />
- <div className="min-w-0 flex-1">
- <div className="flex items-center gap-1.5 text-caption">
- <span className="font-medium text-foreground">
- {getActorName(comment.authorType, comment.authorId)}
- </span>
- <span className="text-muted-foreground">{timeAgo(comment.createdAt)}</span>
- {onDelete && (
- <button
- type="button"
- aria-label={t(($) => $.comments.delete)}
- title={t(($) => $.comments.delete)}
- className="ml-auto rounded-sm p-0.5 text-muted-foreground opacity-0 transition-opacity duration-100 hover:text-destructive focus-visible:opacity-100 group-hover/message:opacity-100 motion-reduce:transition-none"
- onClick={(e) => {
- e.stopPropagation();
- onDelete();
- }}
- >
- <Trash2 className="size-3.5" />
- </button>
- )}
- </div>
- <div className="text-body">
- <ReadonlyContent content={comment.content} />
- </div>
+ <div className={cn("group/message", className)}>
+ <div className="flex h-5 items-center gap-2">
+ <ActorAvatar actorType={comment.authorType} actorId={comment.authorId} size="sm" />
+ <span className="truncate text-label font-medium text-foreground">
+ {getActorName(comment.authorType, comment.authorId)}
+ </span>
+ <span className="shrink-0 text-caption text-muted-foreground">{timeAgo(comment.createdAt)}</span>
+ {onDelete && (
+ <IconButton
+ size="icon-xs"
+ variant="ghost"
+ label={t(($) => $.comments.delete)}
+ className="-mr-1 ml-auto text-muted-foreground opacity-0 transition-opacity duration-100 group-hover/message:opacity-100 focus-visible:opacity-100 motion-reduce:transition-none"
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete();
+ }}
+ >
+ <Trash2 />
+ </IconButton>
+ )}
+ </div>
+ <div className={cn("mt-0.5 pl-7 text-body", clamp && "line-clamp-2")}>
+ <ReadonlyContent content={comment.content} />
</div>
</div>
);
}
-function Quote({ text, missing }: { text: string; missing?: boolean }) {
+/**
+ * The quoted text a discussion is about, on one line with the discussion's
+ * action. Its bar takes the colour of the highlight in the doc while the
+ * highlight is painted.
+ */
+function Quote({
+ text,
+ missing,
+ painted = true,
+ children,
+}: {
+ text: string;
+ missing?: boolean;
+ painted?: boolean;
+ children?: ReactNode;
+}) {
const { t } = useT("docs");
return (
- <>
- {missing && (
- <div className="mb-1 flex items-center gap-1.5 text-caption text-muted-foreground">
- <AlertTriangle className="size-3.5 text-warning" />
- {t(($) => $.comments.quote_missing)}
- </div>
- )}
+ <div className="mb-2 flex min-h-6 items-center gap-2">
+ <span
+ aria-hidden
+ className={cn("my-1 w-0.5 shrink-0 self-stretch rounded-full", painted && !missing ? "bg-warning" : "bg-input")}
+ />
<p
className={cn(
- "mb-2 line-clamp-2 border-l-2 pl-2 text-caption text-muted-foreground",
- missing ? "border-border line-through" : "border-warning",
+ "min-w-0 flex-1 text-caption text-muted-foreground",
+ missing ? "truncate line-through decoration-faint-foreground" : "line-clamp-2",
)}
>
{text}
</p>
- </>
+ {missing && (
+ <span
+ title={t(($) => $.comments.quote_missing)}
+ className="shrink-0 rounded-sm bg-muted px-1.5 text-micro text-muted-foreground"
+ >
+ {t(($) => $.comments.quote_changed)}
+ </span>
+ )}
+ {children && <div className="-mr-1 flex shrink-0 items-center">{children}</div>}
+ </div>
+ );
+}
+
+/** Height reveal for the parts of a discussion that only an open card shows. */
+function Reveal({
+ show,
+ children,
+ onShown,
+}: {
+ show: boolean;
+ children: ReactNode;
+ onShown?: () => void;
+}) {
+ const reduceMotion = useReducedMotion();
+ return (
+ <AnimatePresence initial={false}>
+ {show && (
+ <motion.div
+ initial={reduceMotion ? false : { opacity: 0, height: 0, overflow: "hidden" }}
+ animate={{ opacity: 1, height: "auto", transitionEnd: { overflow: "visible" } }}
+ exit={{ opacity: 0, height: 0, overflow: "hidden" }}
+ transition={{ duration: reduceMotion ? 0 : 0.18, ease: UI_EASE_OUT }}
+ onAnimationComplete={(def) => {
+ if (typeof def === "object" && "height" in def && def.height === "auto") onShown?.();
+ }}
+ >
+ {children}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ );
+}
+
+function ReplySummary({ replies }: { replies: DocComment[] }) {
+ const { t } = useT("docs");
+ const timeAgo = useTimeAgo();
+ const last = replies[replies.length - 1];
+ if (!last) return null;
+ const authors = [
+ ...new Map(replies.map((c) => [`${c.authorType}:${c.authorId}`, c])).values(),
+ ].slice(0, 3);
+ return (
+ <div className="mt-2 flex items-center gap-1.5 pl-7 text-caption text-muted-foreground">
+ <span className="flex -space-x-1">
+ {authors.map((c) => (
+ <span key={`${c.authorType}:${c.authorId}`} className="rounded-full ring-2 ring-card">
+ <ActorAvatar actorType={c.authorType} actorId={c.authorId} size="xs" />
+ </span>
+ ))}
+ </span>
+ <span className="font-medium text-foreground">
+ {t(($) => $.comments.replies, { count: replies.length })}
+ </span>
+ <span>· {timeAgo(last.createdAt)}</span>
+ </div>
);
}
@@ -177,7 +275,7 @@ function ThreadCard({
onResolvedChange: (resolved: boolean) => void;
}) {
const { t } = useT("docs");
- const reduceMotion = useReducedMotion();
+ const timeAgo = useTimeAgo();
const { getActorName } = useActorName();
const userId = useAuthStore((s) => s.user?.id);
const reply = useCreateDocComment(docId);
@@ -185,6 +283,7 @@ function ThreadCard({
const remove = useDeleteDocComment(docId);
const ref = useRef<HTMLDivElement>(null);
const resolved = !!thread.root.resolvedAt;
+ const scrollIntoView = () => ref.current?.scrollIntoView({ block: "nearest", behavior: "smooth" });
useEffect(() => {
if (active) ref.current?.scrollIntoView({ block: "nearest", behavior: "smooth" });
}, [active]);
@@ -198,89 +297,105 @@ function ThreadCard({
() => onResolvedChange(value),
() => toast.error(t(($) => $.comments.errors.resolve)),
);
+ const action = resolved ? (
+ <Button
+ size="xs"
+ variant="ghost"
+ className="text-muted-foreground"
+ disabled={resolve.isPending}
+ onClick={(e) => {
+ e.stopPropagation();
+ void setResolved(false);
+ }}
+ >
+ <RotateCcw />
+ {t(($) => $.comments.reopen)}
+ </Button>
+ ) : (
+ <Button
+ size="xs"
+ variant="ghost"
+ // A folded card keeps the action out of the way until it is pointed at
+ // or tabbed to; the open card always shows it.
+ className={cn(
+ "text-muted-foreground",
+ !active &&
+ "pointer-events-none opacity-0 transition-opacity duration-100 group-hover/thread:pointer-events-auto group-hover/thread:opacity-100 focus-visible:pointer-events-auto focus-visible:opacity-100 motion-reduce:transition-none",
+ )}
+ disabled={resolve.isPending}
+ onClick={(e) => {
+ e.stopPropagation();
+ void setResolved(true);
+ }}
+ >
+ <Check />
+ {t(($) => $.comments.resolve)}
+ </Button>
+ );
return (
<div
ref={ref}
role="group"
aria-label={thread.root.anchorQuote}
data-thread-id={thread.root.id}
+ tabIndex={active ? undefined : 0}
// Clicks inside the open discussion (its reply box, its buttons) must not
// scroll the doc back to the quote.
onClick={() => {
if (!active) onActivate();
}}
+ onKeyDown={(e) => {
+ if (active || e.target !== e.currentTarget) return;
+ if (e.key === "Enter" || e.key === " ") {
+ e.preventDefault();
+ onActivate();
+ }
+ }}
className={cn(
- "rounded-lg border bg-card px-3 py-2.5 transition-colors",
- active ? "border-warning shadow-sm" : "hover:border-input",
+ "group/thread rounded-lg border bg-card px-3 py-2.5 outline-none transition-[border-color,box-shadow] focus-visible:ring-3 focus-visible:ring-ring/50 motion-reduce:transition-none",
+ active ? "border-input shadow-[var(--menu-shadow)]" : "cursor-pointer hover:border-input",
)}
>
- <Quote text={thread.root.anchorQuote} missing={missing} />
- {[thread.root, ...thread.replies].map((c) => (
- <Message key={c.id} comment={c} onDelete={own(c) ? () => void del(c) : undefined} />
- ))}
+ <Quote text={thread.root.anchorQuote} missing={missing} painted={!resolved || active}>
+ {action}
+ </Quote>
+ <Message
+ comment={thread.root}
+ clamp={!active}
+ onDelete={own(thread.root) ? () => void del(thread.root) : undefined}
+ />
+ <Reveal show={active} onShown={scrollIntoView}>
+ {thread.replies.map((c) => (
+ <Message
+ key={c.id}
+ comment={c}
+ className="mt-3"
+ onDelete={own(c) ? () => void del(c) : undefined}
+ />
+ ))}
+ </Reveal>
{runs.map((run) => (
<DocThreadRun key={run.id} docId={docId} run={run} />
))}
+ {!active && <ReplySummary replies={thread.replies} />}
{resolved ? (
- <div className="mt-2 flex items-center gap-2 border-t pt-2 text-caption text-muted-foreground">
- {t(($) => $.comments.resolved_by, {
- name: getActorName(thread.root.resolvedByType ?? "member", thread.root.resolvedById ?? ""),
- })}
- <Button
- size="xs"
- variant="outline"
- className="ml-auto"
- disabled={resolve.isPending}
- onClick={(e) => {
- e.stopPropagation();
- void setResolved(false);
- }}
- >
- <RotateCcw />
- {t(($) => $.comments.reopen)}
- </Button>
+ <div className="mt-2 flex items-center gap-1.5 pl-7 text-caption text-muted-foreground">
+ <CheckCircle2 className="size-3.5 shrink-0" />
+ <span className="truncate">
+ {t(($) => $.comments.resolved_by, {
+ name: getActorName(thread.root.resolvedByType ?? "member", thread.root.resolvedById ?? ""),
+ })}
+ {thread.root.resolvedAt && ` · ${timeAgo(thread.root.resolvedAt)}`}
+ </span>
</div>
) : (
- <AnimatePresence initial={false}>
- {active && (
- <motion.div
- key="thread-reply-box"
- initial={reduceMotion ? false : { opacity: 0, height: 0, overflow: "hidden" }}
- animate={{
- opacity: 1,
- height: "auto",
- transitionEnd: { overflow: "visible" },
- }}
- exit={{ opacity: 0, height: 0, overflow: "hidden" }}
- transition={{ duration: reduceMotion ? 0 : 0.18, ease: UI_EASE_OUT }}
- >
- <Composer
- placeholder={t(($) => $.comments.reply_placeholder)}
- submitLabel={t(($) => $.comments.reply)}
- onSubmit={(content) => reply.mutateAsync({ content, parentId: thread.root.id })}
- />
- <div className="mt-2 flex justify-end">
- <Button
- size="xs"
- variant="outline"
- disabled={resolve.isPending}
- onClick={(e) => {
- e.stopPropagation();
- void setResolved(true);
- }}
- >
- <Check />
- {t(($) => $.comments.resolve)}
- </Button>
- </div>
- </motion.div>
- )}
- </AnimatePresence>
- )}
- {!resolved && !active && thread.replies.length > 0 && (
- <div className="mt-2 text-caption text-muted-foreground">
- {t(($) => $.comments.replies, { count: thread.replies.length })}
- </div>
+ <Reveal show={active} onShown={scrollIntoView}>
+ <Composer
+ placeholder={t(($) => $.comments.reply_placeholder)}
+ submitLabel={t(($) => $.comments.reply)}
+ onSubmit={(content) => reply.mutateAsync({ content, parentId: thread.root.id })}
+ />
+ </Reveal>
)}
</div>
);
@@ -291,7 +406,7 @@ const NO_RUNS: DocTaskRun[] = [];
/**
* The doc's discussions, beside the text. Open and resolved discussions sit
* on separate tabs; a discussion being started from a selection appears on
- * top until it is sent or cancelled.
+ * top until it is sent or cancelled. Only the selected discussion unfolds.
*/
export function DocCommentsPanel({
docId,
@@ -356,13 +471,13 @@ export function DocCommentsPanel({
</button>
))}
</div>
- <Button size="icon-xs" variant="ghost" aria-label={t(($) => $.comments.close)} onClick={onClose}>
- <X className="size-3.5" />
- </Button>
+ <IconButton size="icon-xs" variant="ghost" label={t(($) => $.comments.close)} onClick={onClose}>
+ <X />
+ </IconButton>
</div>
<div className="min-h-0 flex-1 space-y-2.5 overflow-y-auto p-3">
{draft && tab === "open" && (
- <div className="rounded-lg border border-warning bg-card px-3 py-2.5 shadow-sm">
+ <div className="rounded-lg border border-input bg-card px-3 py-2.5 shadow-[var(--menu-shadow)]">
<Quote text={draft.quote} />
<Composer
autoFocus
diff --git a/packages/views/docs/components/doc-page.tsx b/packages/views/docs/components/doc-page.tsx
index 1b8e61037a..477ae2b420 100644
--- a/packages/views/docs/components/doc-page.tsx
+++ b/packages/views/docs/components/doc-page.tsx
@@ -360,7 +360,8 @@ function DocEditor({ doc }: { doc: Doc }) {
}),
[t],
);
- // A click inside highlighted text opens its discussion.
+ // A click inside highlighted text opens its discussion; a click anywhere
+ // else in the text lets go of the open one.
const onBodyClick = () => {
const selection = window.getSelection();
if (!selection?.isCollapsed || !selection.anchorNode) return;
@@ -368,6 +369,8 @@ function DocEditor({ doc }: { doc: Doc }) {
if (id) {
setActiveThread(id);
setCommentsOpen(true);
+ } else {
+ setActiveThread(null);
}
};
const titleValue = solo ? draft.title : liveTitle.value;
diff --git a/packages/views/docs/components/use-doc-comment-highlights.ts b/packages/views/docs/components/use-doc-comment-highlights.ts
index 5d35cefd54..6f8a7b72a6 100644
--- a/packages/views/docs/components/use-doc-comment-highlights.ts
+++ b/packages/views/docs/components/use-doc-comment-highlights.ts
@@ -16,6 +16,21 @@ function canHighlight() {
return typeof Highlight !== "undefined" && typeof CSS !== "undefined" && !!CSS.highlights;
}
+/** Whether the range is fully inside the visible part of its scroll container. */
+function inView(range: Range, from: HTMLElement): boolean {
+ if (typeof range.getBoundingClientRect !== "function") return false;
+ const box = range.getBoundingClientRect();
+ let port = { top: 0, bottom: window.innerHeight };
+ for (let el: HTMLElement | null = from.parentElement; el; el = el.parentElement) {
+ if (/(auto|scroll)/.test(getComputedStyle(el).overflowY)) {
+ const r = el.getBoundingClientRect();
+ port = { top: Math.max(port.top, r.top), bottom: Math.min(port.bottom, r.bottom) };
+ break;
+ }
+ }
+ return box.top >= port.top && box.bottom <= port.bottom;
+}
+
/**
* Paints each open discussion's quoted text in the doc and keeps the ranges
* current while the doc is edited. Returns which discussions could not be
@@ -86,11 +101,13 @@ export function useDocCommentHighlights(
return null;
};
- /** Scrolls the discussion's quoted text into view. */
+ /** Scrolls the discussion's quoted text into view, unless it is in view. */
const reveal = (id: string) => {
const range = rangesRef.current.get(id);
const target = range?.startContainer.parentElement;
- target?.scrollIntoView({ block: "center", behavior: "smooth" });
+ if (!range || !target) return;
+ if (inView(range, target)) return;
+ target.scrollIntoView({ block: "center", behavior: "smooth" });
};
return { missing, threadAt, reveal };
diff --git a/packages/views/locales/en/docs.json b/packages/views/locales/en/docs.json
index 622d0a0c40..a59aab9a3b 100644
--- a/packages/views/locales/en/docs.json
+++ b/packages/views/locales/en/docs.json
@@ -81,6 +81,7 @@
"resolved": "Resolved {{count}}",
"close": "Close comments",
"quote_missing": "The commented text was changed",
+ "quote_changed": "Text changed",
"reply_placeholder": "Reply, or @ someone...",
"new_placeholder": "Add a comment, or @ someone...",
"submit": "Comment",
diff --git a/packages/views/locales/es/docs.json b/packages/views/locales/es/docs.json
index 794dcd8781..ab69e913d4 100644
--- a/packages/views/locales/es/docs.json
+++ b/packages/views/locales/es/docs.json
@@ -81,6 +81,7 @@
"resolved": "Resueltos {{count}}",
"close": "Cerrar comentarios",
"quote_missing": "El texto comentado cambió",
+ "quote_changed": "Texto cambiado",
"reply_placeholder": "Responde o menciona con @…",
"new_placeholder": "Añade un comentario o menciona con @ a alguien...",
"submit": "Comentar",
diff --git a/packages/views/locales/fr/docs.json b/packages/views/locales/fr/docs.json
index f4d16519a6..600d729a9b 100644
--- a/packages/views/locales/fr/docs.json
+++ b/packages/views/locales/fr/docs.json
@@ -81,6 +81,7 @@
"resolved": "Résolus {{count}}",
"close": "Fermer les commentaires",
"quote_missing": "Le texte commenté a été modifié",
+ "quote_changed": "Texte modifié",
"reply_placeholder": "Répondre, ou mentionner avec @…",
"new_placeholder": "Ajouter un commentaire, ou @ pour mentionner quelqu'un...",
"submit": "Commenter",
diff --git a/packages/views/locales/ja/docs.json b/packages/views/locales/ja/docs.json
index 481ac61f03..36ab88c172 100644
--- a/packages/views/locales/ja/docs.json
+++ b/packages/views/locales/ja/docs.json
@@ -81,6 +81,7 @@
"resolved": "解決済み {{count}}",
"close": "コメントを閉じる",
"quote_missing": "コメントされたテキストが変更されました",
+ "quote_changed": "本文が変更済み",
"reply_placeholder": "返信、または @ でメンション…",
"new_placeholder": "コメントを入力、または @ でメンション...",
"submit": "コメント",
diff --git a/packages/views/locales/ko/docs.json b/packages/views/locales/ko/docs.json
index 54cdc6e315..a25185a89f 100644
--- a/packages/views/locales/ko/docs.json
+++ b/packages/views/locales/ko/docs.json
@@ -81,6 +81,7 @@
"resolved": "해결됨 {{count}}",
"close": "댓글 닫기",
"quote_missing": "댓글을 단 텍스트가 변경되었습니다",
+ "quote_changed": "원문 변경됨",
"reply_placeholder": "답글 또는 @ 멘션…",
"new_placeholder": "댓글을 추가하거나 @로 멘션하세요...",
"submit": "댓글",
diff --git a/packages/views/locales/ru/docs.json b/packages/views/locales/ru/docs.json
index 9a9bbd455a..f8c098b223 100644
--- a/packages/views/locales/ru/docs.json
+++ b/packages/views/locales/ru/docs.json
@@ -81,6 +81,7 @@
"resolved": "Решённые {{count}}",
"close": "Закрыть комментарии",
"quote_missing": "Прокомментированный текст изменён",
+ "quote_changed": "Текст изменён",
"reply_placeholder": "Ответьте или упомяните через @…",
"new_placeholder": "Добавьте комментарий или упомяните кого-нибудь через @…",
"submit": "Комментировать",
diff --git a/packages/views/locales/zh-Hans/docs.json b/packages/views/locales/zh-Hans/docs.json
index d1d441ec8c..dc452b7bdb 100644
--- a/packages/views/locales/zh-Hans/docs.json
+++ b/packages/views/locales/zh-Hans/docs.json
@@ -81,6 +81,7 @@
"resolved": "已解决 {{count}}",
"close": "关闭评论",
"quote_missing": "原文已修改,找不到划线位置",
+ "quote_changed": "原文已修改",
"reply_placeholder": "回复,或 @ 某人...",
"new_placeholder": "写下评论,@ 提及某人...",
"submit": "评论",
diff --git a/packages/views/locales/zh-Hant/docs.json b/packages/views/locales/zh-Hant/docs.json
index da48737dcb..c0bcfe35e1 100644
--- a/packages/views/locales/zh-Hant/docs.json
+++ b/packages/views/locales/zh-Hant/docs.json
@@ -81,6 +81,7 @@
"resolved": "已解決 {{count}}",
"close": "關閉評論",
"quote_missing": "原文已修改,找不到劃線位置",
+ "quote_changed": "原文已修改",
"reply_placeholder": "回覆,或 @ 某人…",
"new_placeholder": "新增評論,或 @ 提及某人...",
"submit": "評論",