Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(web): composer popover arrow-scroll, per-channel draft cache, full-width messages
Gusa010c0b5c7c3
diff --git a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsxindex 88174848a..b8d3a53ab 100644--- a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx+++ b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx@@ -1001,6 +1001,7 @@ function ChannelView() {replyingTo={replyTo?.authorName}onCancelReply={() => setReplyTo(null)}autoFocus={bp !== "mobile"}+ draftKey={`${serverId}/${channelId}`}/></main>@@ -1150,6 +1151,7 @@ function ChannelView() {replyingTo={replyTo?.authorName}onCancelReply={() => setReplyTo(null)}autoFocus={bp !== "mobile"}+ draftKey={`${serverId}/${channelId}`}/></main>diff --git a/src/web/src/app/c/me/[dmId]/page.tsx b/src/web/src/app/c/me/[dmId]/page.tsxindex 3eaf0e631..975efb32f 100644--- a/src/web/src/app/c/me/[dmId]/page.tsx+++ b/src/web/src/app/c/me/[dmId]/page.tsx@@ -397,6 +397,7 @@ function DmView() {replyingTo={replyTo?.authorName}onCancelReply={() => setReplyTo(null)}autoFocus={bp !== "mobile"}+ draftKey={`dm/${dmId}`}/>)}</main>diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.cssindex 70f576745..226e44aac 100644--- a/src/web/src/app/globals.css+++ b/src/web/src/app/globals.css@@ -1410,6 +1410,16 @@text-decoration-thickness: 1.5px;}+/* Community chat markdown — messages span the full row width. The base+ `.markdown p` caps paragraphs at 65ch (a reading measure for long-form+ surfaces: blog, agent chat, calendar). Chat rows are already width-bounded+ by the message column, so the extra cap only leaves dead space on wide+ viewports; lift it here so a message line extends to the full row. */+.markdown-chat p,+.markdown-chat [data-md-p] {+ max-width: none;+}+/* User bubble markdown — inherit text color from primary-foreground parent */.markdown-user,.markdown-user code:not(pre code) {diff --git a/src/web/src/components/community/composer.tsx b/src/web/src/components/community/composer.tsxindex 216425b02..0d74eac81 100644--- a/src/web/src/components/community/composer.tsx+++ b/src/web/src/components/community/composer.tsx@@ -8,6 +8,8 @@ import StarterKit from "@tiptap/starter-kit"import Placeholder from "@tiptap/extension-placeholder"import { DOMParser as PMDOMParser } from "@tiptap/pm/model"import { buildPasteDom } from "@/lib/community/paste-plain-text"+import { nextListScrollTop } from "@/lib/community/popup-scroll"+import { readComposerDraft, writeComposerDraft, clearComposerDraft } from "@/lib/community/composer-draft"import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@/components/ui/dropdown-menu"import { Skeleton } from "@/components/ui/skeleton"import { useFileAttachments, type PendingFile } from "@/hooks/use-file-attachments"@@ -98,6 +100,12 @@ export type ComposerProps = {// keystroke. Used by the forum-post orchestrator to drive the footer button's// `disabled` state without mirroring editor content in parent React state.onDirty?: (hasContent: boolean) => void+ // When set, the composer persists its unsent text under this localStorage+ // scope (per channel/DM) and restores it on mount — the view remounts on+ // every channel switch (keyed by id), so this is what survives navigation.+ // Text only; attachments/replies are not cached. Omitted for forumPostBody+ // (the parent owns that draft lifecycle).+ draftKey?: string}// Composer — plain-text TipTap editor with a chat-style @-mention popover.@@ -124,6 +132,7 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function CompohideEmoji = false,hideAttach = false,onDirty,+ draftKey,}, ref) {const isForumPostBody = mode === "forumPostBody"const {@@ -146,6 +155,13 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function Compo})const typingTimer = useRef<NodeJS.Timeout | null>(null)+ // Draft cache key, held in a ref so the editor's `onUpdate` closure (captured+ // once at build) always persists under the current scope. Restore is+ // suppressed via this flag so hydrating the editor doesn't fire `onTyping`.+ const draftKeyRef = useRef(draftKey)+ useEffect(() => { draftKeyRef.current = draftKey }, [draftKey])+ const restoringDraftRef = useRef(false)+const [mentionPopup, setMentionPopup] = useState<MentionPopupState>(EMPTY_MENTION_STATE)const mentionPopupRef = useRef(mentionPopup)useEffect(() => { mentionPopupRef.current = mentionPopup }, [mentionPopup])@@ -307,12 +323,42 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function Compo})},},- onUpdate: () => {+ onUpdate: ({ editor }) => {+ // Restore writes into the editor programmatically — don't treat that as+ // the user typing (would fire a spurious typing indicator + re-save).+ if (restoringDraftRef.current) returnfireTyping()emitDirtyTransition()+ const key = draftKeyRef.current+ if (key && !isForumPostBody) {+ writeComposerDraft(key, editor.isEmpty ? "" : editor.getText({ blockSeparator: "\n\n" }))+ }},})+ // Restore a cached draft on mount / when the scope key changes. The view+ // remounts on channel switch, so this fires once per composer instance for+ // the common case; the `draftKey` dep also covers a same-instance scope+ // change. Uses the paste pipeline so paragraph/hard-break structure round-+ // trips exactly like `getText({blockSeparator:"\n\n"})` serialized it.+ useEffect(() => {+ if (!editor || isForumPostBody || !draftKey) return+ const text = readComposerDraft(draftKey)+ if (!text) return+ restoringDraftRef.current = true+ try {+ // `buildPasteDom` produces the same `<p>`/`<br>` block structure the+ // paste path uses; its innerHTML round-trips through tiptap's own HTML+ // parser, so the restored paragraphs/hard-breaks match what was saved.+ editor.commands.setContent(buildPasteDom(text, document).innerHTML)+ } finally {+ restoringDraftRef.current = false+ }+ // Only re-run when the editor instance or scope key changes — not on every+ // render. Restoring is a mount-time (per-instance) concern.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [editor, draftKey])+// Emitted-emptiness ref — used by the onDirty transition logic below to fire// only when the boolean flips. Initialized to false because the editor mounts// empty and no attachments exist yet.@@ -350,6 +396,7 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function Compo// Reset is delegated to the parent via `resetAfterSubmit()` on the ref.if (isForumPostBody) returneditor.commands.clearContent()+ if (draftKeyRef.current) clearComposerDraft(draftKeyRef.current)setPendingFiles([])setMentionPopup(EMPTY_MENTION_STATE)setChannelRefPopup(EMPTY_CHANNEL_REF_STATE)@@ -519,6 +566,24 @@ function itemsEqual(a: MentionItem[], b: MentionItem[]): boolean {return true}+// Scroll the currently-highlighted row of a suggestion popover into view.+// Looks the row up by `aria-selected="true"` (not child index) — the mention+// list interleaves a "Members" section-header sibling, so an index lookup is+// off-by-one; the attribute is exact. Drives `scrollTop` directly (the popup is+// a fixed/transformed portal where `scrollIntoView` misbehaves). Row offsets+// are container-relative because the list container is `position:relative`.+function scrollSelectedRowIntoView(list: HTMLDivElement | null): void {+ if (!list) return+ const row = list.querySelector<HTMLElement>('[aria-selected="true"]')+ if (!row) return+ list.scrollTop = nextListScrollTop(+ list.scrollTop,+ list.clientHeight,+ row.offsetTop,+ row.offsetHeight,+ )+}+// Portal-rendered popup. Anchored above the caret via clientRect() from// @tiptap/suggestion. Highlighted row syncs to hover so keyboard + pointer agree.function CommunityMentionList({ state }: { state: MentionPopupState }) {@@ -526,9 +591,7 @@ function CommunityMentionList({ state }: { state: MentionPopupState }) {const { items, selectedIndex, command, rect } = stateuseEffect(() => {- if (!listRef.current) return- const el = listRef.current.children[selectedIndex] as HTMLElement | undefined- el?.scrollIntoView({ block: "nearest" })+ scrollSelectedRowIntoView(listRef.current)}, [selectedIndex])if (!rect || items.length === 0 || !command) return null@@ -551,7 +614,7 @@ function CommunityMentionList({ state }: { state: MentionPopupState }) {className="fixed z-100 w-64 rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-(--e2)"style={{ top: rect.top - 4, left: clampedLeft, transform: "translateY(-100%)" }}>- <div ref={listRef} className="max-h-60 overflow-x-hidden overflow-y-auto thin-scrollbar">+ <div ref={listRef} className="relative max-h-60 overflow-x-hidden overflow-y-auto thin-scrollbar">{items.map((item, i) => {const selected = i === selectedIndexreturn (@@ -588,9 +651,7 @@ function ChannelRefList({ state }: { state: ChannelRefPopupState }) {const { items, selectedIndex, command, rect } = stateuseEffect(() => {- if (!listRef.current) return- const el = listRef.current.children[selectedIndex] as HTMLElement | undefined- el?.scrollIntoView({ block: "nearest" })+ scrollSelectedRowIntoView(listRef.current)}, [selectedIndex])if (!rect || items.length === 0 || !command) return null@@ -612,7 +673,7 @@ function ChannelRefList({ state }: { state: ChannelRefPopupState }) {className="fixed z-100 w-64 rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-(--e2)"style={{ top: rect.top - 4, left: clampedLeft, transform: "translateY(-100%)" }}>- <div ref={listRef} className="max-h-60 overflow-x-hidden overflow-y-auto thin-scrollbar">+ <div ref={listRef} className="relative max-h-60 overflow-x-hidden overflow-y-auto thin-scrollbar">{items.map((item, i) => (<ChannelRefRowkey={item.id}diff --git a/src/web/src/components/community/message-body.tsx b/src/web/src/components/community/message-body.tsxindex 0e440387c..03e1159f9 100644--- a/src/web/src/components/community/message-body.tsx+++ b/src/web/src/components/community/message-body.tsx@@ -98,7 +98,7 @@ function MessageBodyImpl({[onOpenProfile, messageRefContext],)return (- <div className="markdown wrap-anywhere text-[15px] leading-snug">+ <div className="markdown markdown-chat wrap-anywhere text-[15px] leading-snug"><StreamdownparseIncompleteMarkdown={false}plugins={{ mermaid, cjk, math }}diff --git a/src/web/src/lib/community/composer-draft.test.ts b/src/web/src/lib/community/composer-draft.test.tsnew file mode 100644index 000000000..4255f0c2b--- /dev/null+++ b/src/web/src/lib/community/composer-draft.test.ts@@ -0,0 +1,63 @@+import { describe, it, expect, beforeEach, vi } from "vitest"+import {+ draftStorageKey,+ readComposerDraft,+ writeComposerDraft,+ clearComposerDraft,+} from "./composer-draft"++describe("composer-draft", () => {+ let storage: Record<string, string>++ beforeEach(() => {+ storage = {}+ vi.stubGlobal("window", {})+ vi.stubGlobal("localStorage", {+ getItem: vi.fn((key: string) => storage[key] ?? null),+ setItem: vi.fn((key: string, value: string) => {+ storage[key] = value+ }),+ removeItem: vi.fn((key: string) => {+ delete storage[key]+ }),+ })+ })++ it("namespaces the key under the composer-draft prefix", () => {+ expect(draftStorageKey("srv/chan")).toBe("c-composer-draft:srv/chan")+ })++ it("returns empty string when no draft is stored", () => {+ expect(readComposerDraft("srv/chan")).toBe("")+ })++ it("round-trips written text", () => {+ writeComposerDraft("srv/chan", "hello\n\nworld")+ expect(readComposerDraft("srv/chan")).toBe("hello\n\nworld")+ })++ it("scopes drafts independently per conversation", () => {+ writeComposerDraft("srv/a", "draft A")+ writeComposerDraft("srv/b", "draft B")+ expect(readComposerDraft("srv/a")).toBe("draft A")+ expect(readComposerDraft("srv/b")).toBe("draft B")+ })++ it("removes the key when the draft is empty or whitespace-only", () => {+ writeComposerDraft("srv/chan", "something")+ writeComposerDraft("srv/chan", " \n ")+ expect(storage["c-composer-draft:srv/chan"]).toBeUndefined()+ expect(readComposerDraft("srv/chan")).toBe("")+ })++ it("clear removes a stored draft", () => {+ writeComposerDraft("srv/chan", "text")+ clearComposerDraft("srv/chan")+ expect(readComposerDraft("srv/chan")).toBe("")+ })++ it("returns empty string when window is undefined (SSR)", () => {+ vi.stubGlobal("window", undefined)+ expect(readComposerDraft("srv/chan")).toBe("")+ })+})diff --git a/src/web/src/lib/community/composer-draft.ts b/src/web/src/lib/community/composer-draft.tsnew file mode 100644index 000000000..d39f4e49b--- /dev/null+++ b/src/web/src/lib/community/composer-draft.ts@@ -0,0 +1,46 @@+// Per-channel-per-server composer draft cache. The community composer remounts+// on every channel/DM switch (`ChannelView`/`DmView` are keyed by id), so its+// in-editor text is otherwise lost on navigate. These helpers persist the raw+// message text (only text — attachments/replies are not cached) under a key+// scoped to the conversation, so returning restores the draft.+//+// Pure wrappers over localStorage (guarded for SSR/quota) rather than the+// `useLocalStorage` hook: the composer's text lives in the tiptap editor, not+// React state, so it hydrates/persists imperatively at mount/update/send.++const PREFIX = "c-composer-draft:"++export function draftStorageKey(scope: string): string {+ return `${PREFIX}${scope}`+}++export function readComposerDraft(scope: string): string {+ if (typeof window === "undefined") return ""+ try {+ return localStorage.getItem(draftStorageKey(scope)) ?? ""+ } catch {+ return ""+ }+}++export function writeComposerDraft(scope: string, text: string): void {+ if (typeof window === "undefined") return+ const key = draftStorageKey(scope)+ try {+ // An empty (or whitespace-only) draft is the absence of a draft — remove+ // the key so a stale entry never resurfaces and localStorage stays clean.+ if (text.trim() === "") localStorage.removeItem(key)+ else localStorage.setItem(key, text)+ } catch {+ /* quota exceeded — silently ignore, same as useLocalStorage */+ }+}++export function clearComposerDraft(scope: string): void {+ if (typeof window === "undefined") return+ try {+ localStorage.removeItem(draftStorageKey(scope))+ } catch {+ /* ignore */+ }+}diff --git a/src/web/src/lib/community/popup-scroll.test.ts b/src/web/src/lib/community/popup-scroll.test.tsnew file mode 100644index 000000000..83437650d--- /dev/null+++ b/src/web/src/lib/community/popup-scroll.test.ts@@ -0,0 +1,31 @@+import { describe, it, expect } from "vitest"+import { nextListScrollTop } from "./popup-scroll"++// container viewport 100px tall, rows 40px each. scrollTop 0 shows rows 0..1+// and a sliver of row 2.+describe("nextListScrollTop", () => {+ it("scrolls up when the selected row is above the viewport", () => {+ // row 0 at top 0, currently scrolled down to 200+ expect(nextListScrollTop(200, 100, 0, 40)).toBe(0)+ })++ it("scrolls up to just above the row (minus margin) for a mid-list row above view", () => {+ // row at top 120, scrolled to 200 → bring top into view at 120-4+ expect(nextListScrollTop(200, 100, 120, 40)).toBe(116)+ })++ it("scrolls down so the row's bottom aligns to the viewport bottom", () => {+ // row 3 at top 120, height 40 → bottom 160; viewport 0..100 → scroll to+ // 160 - 100 + 4 = 64+ expect(nextListScrollTop(0, 100, 120, 40)).toBe(64)+ })++ it("leaves scrollTop unchanged when the row is already fully visible", () => {+ // row at top 40, height 40 → bottom 80, within viewport 0..100+ expect(nextListScrollTop(0, 100, 40, 40)).toBe(0)+ })++ it("never returns a negative scrollTop", () => {+ expect(nextListScrollTop(0, 100, 0, 40)).toBe(0)+ })+})diff --git a/src/web/src/lib/community/popup-scroll.ts b/src/web/src/lib/community/popup-scroll.tsnew file mode 100644index 000000000..900b76723--- /dev/null+++ b/src/web/src/lib/community/popup-scroll.ts@@ -0,0 +1,33 @@+// Keyboard-driven scroll for the composer's suggestion popovers (@-mention,+// /-channel-ref). Pure so it's unit-testable without a DOM: given the list+// container's current scroll offset + viewport height and the selected row's+// container-relative top + height, returns the scrollTop that keeps the row+// fully visible with the least movement.+//+// Why not `element.scrollIntoView({block:"nearest"})`: the popover is a+// `position:fixed` portal transformed by `translateY(-100%)`, and the mention+// list interleaves a "Members" section-header sibling — both break the+// index/geometry `scrollIntoView` relies on, so the highlight moved while the+// list never scrolled. Setting `scrollTop` from container-relative `offsetTop`+// sidesteps both.++const MARGIN = 4++export function nextListScrollTop(+ scrollTop: number,+ clientHeight: number,+ elemTop: number,+ elemHeight: number,+): number {+ // Above the viewport → pull the row's top into view.+ if (elemTop < scrollTop + MARGIN) {+ return Math.max(0, elemTop - MARGIN)+ }+ // Below the viewport → align the row's bottom to the viewport bottom.+ const elemBottom = elemTop + elemHeight+ if (elemBottom > scrollTop + clientHeight - MARGIN) {+ return elemBottom - clientHeight + MARGIN+ }+ // Already fully visible → no movement.+ return scrollTop+}