Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(comments): fold long margin comments behind show more (#8459)

Jacob Beckerman937213b8ab96
diff --git a/apps/web/src/features/block-md/comments/CommentMargin.tsx b/apps/web/src/features/block-md/comments/CommentMargin.tsx
index 1533be9501..9a8bbd633d 100644
--- a/apps/web/src/features/block-md/comments/CommentMargin.tsx
+++ b/apps/web/src/features/block-md/comments/CommentMargin.tsx
@@ -51,9 +51,7 @@ const useCommentsContext = (
export const CommentMargin = (props: { wideEnough: boolean }) => {
const { state } = useMarkdownDocument();
const commentState = state.comments;
- const { notebookHeight, setThreadHeights, threadPositions } =
- createCommentLayout();
- const maxHeight = createMemo(() => notebookHeight() ?? undefined);
+ const { setThreadHeights, threadPositions } = createCommentLayout();
// NOTE: this is a big of a hack because you can select
// multiple threads at once from the editor but only one thread in the margin
@@ -111,7 +109,6 @@ export const CommentMargin = (props: { wideEnough: boolean }) => {
comment={thread()}
layout={layout()}
isActive={isThreadActive(thread())}
- maxHeight={maxHeight()}
expandable={!isTouchDevice()}
/>
}
@@ -120,7 +117,6 @@ export const CommentMargin = (props: { wideEnough: boolean }) => {
comment={thread()}
layout={layout()}
isActive={isThreadActive(thread())}
- maxHeight={maxHeight()}
/>
</Show>
</div>
diff --git a/apps/web/src/features/block-md/comments/commentLayout.test.tsx b/apps/web/src/features/block-md/comments/commentLayout.test.tsx
index 81023fd4fa..bd738edc71 100644
--- a/apps/web/src/features/block-md/comments/commentLayout.test.tsx
+++ b/apps/web/src/features/block-md/comments/commentLayout.test.tsx
@@ -2,7 +2,11 @@ import { cleanup, render } from '@solidjs/testing-library';
import { createEditor } from 'lexical';
import { createStore } from 'solid-js/store';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { createCommentLayout } from './commentLayout';
+import {
+ createCommentLayout,
+ MIN_THREAD_GAP,
+ stackMarginThreads,
+} from './commentLayout';
import type { MarkStore } from './commentType';
const listeners = vi.hoisted(() => ({
@@ -147,3 +151,58 @@ describe('comment layout during document reflow', () => {
}
);
});
+
+describe('stacking margin threads', () => {
+ const thread = (id: string, top: number, height: number) => ({
+ id,
+ height,
+ layout: { originalYPosition: top },
+ });
+ const tops = (layouts: ReturnType<typeof stackMarginThreads>) =>
+ layouts.map((layout) => layout.layout.calculatedYPos);
+ const expectNoOverlap = (
+ threads: ReturnType<typeof thread>[],
+ layouts: ReturnType<typeof stackMarginThreads>
+ ) => {
+ for (let i = 1; i < layouts.length; i++) {
+ const previous = layouts[i - 1].layout;
+ expect(layouts[i].layout.calculatedYPos).toBeGreaterThanOrEqual(
+ previous.calculatedYPos + threads[i - 1].height + MIN_THREAD_GAP
+ );
+ }
+ for (const layout of layouts) {
+ expect(layout.layout.calculatedYPos).toBeGreaterThanOrEqual(0);
+ }
+ };
+
+ it('keeps each thread beside its mark when they fit', () => {
+ const threads = [thread('a', 100, 50), thread('b', 400, 50)];
+ expect(tops(stackMarginThreads(threads, 0, 2000))).toEqual([100, 400]);
+ });
+
+ it('pushes the threads below a tall active thread past its end', () => {
+ const threads = [thread('a', 100, 900), thread('b', 200, 300)];
+ const layouts = stackMarginThreads(threads, 0, 2000);
+ expect(tops(layouts)).toEqual([100, 100 + 900 + MIN_THREAD_GAP]);
+ expectNoOverlap(threads, layouts);
+ });
+
+ it('never stacks a thread above the top of a short page', () => {
+ // A long active thread low on a short page: fitting it inside the page
+ // would push the thread above it out the top, out of reach.
+ const threads = [
+ thread('above', 230, 400),
+ thread('active', 350, 1300),
+ thread('below', 600, 500),
+ ];
+ const layouts = stackMarginThreads(threads, 1, 750);
+ expect(tops(layouts)[0]).toBe(0);
+ expectNoOverlap(threads, layouts);
+ });
+
+ it('moves the active thread up only to end inside the page', () => {
+ const threads = [thread('a', 50, 40), thread('active', 700, 200)];
+ const layouts = stackMarginThreads(threads, 1, 800);
+ expect(tops(layouts)).toEqual([50, 600]);
+ });
+});
diff --git a/apps/web/src/features/block-md/comments/commentLayout.ts b/apps/web/src/features/block-md/comments/commentLayout.ts
index 7d3b2cbc34..871434a1b1 100644
--- a/apps/web/src/features/block-md/comments/commentLayout.ts
+++ b/apps/web/src/features/block-md/comments/commentLayout.ts
@@ -32,6 +32,60 @@ export const MIN_THREAD_GAP = 10;
// the throttle time for layout updates.
const LAYOUT_THROTTLE = 60;
+type StackInput<T> = CommentViewerInitialLayout<T> & { height: number };
+
+/**
+ * Stacks margin threads (sorted by their marks' positions) so no two cards
+ * overlap and none starts above the top of the margin, where it could never
+ * be scrolled to. The anchor (the active thread) sits beside its mark, moved
+ * up only as far as it takes to end inside the page; threads above it are
+ * pushed up and threads below it are pushed down. When the threads above do
+ * not fit between the top of the page and the anchor, the whole stack is
+ * pushed down instead. Threads below may run past the page's bottom; the
+ * document scrolls to them.
+ */
+export function stackMarginThreads<T>(
+ threads: readonly StackInput<T>[],
+ anchorIndex: number,
+ pageHeight: number
+): Array<CommentLayout<T>> {
+ const anchor = threads[anchorIndex];
+ if (!anchor) return [];
+ const tops = threads.map((thread) => thread.layout.originalYPosition);
+
+ tops[anchorIndex] = Math.max(
+ 0,
+ Math.min(tops[anchorIndex], pageHeight - anchor.height)
+ );
+ for (let i = anchorIndex + 1; i < threads.length; i++) {
+ const previousEnd = tops[i - 1] + threads[i - 1].height;
+ tops[i] = Math.max(tops[i], previousEnd + MIN_THREAD_GAP);
+ }
+ for (let i = anchorIndex - 1; i >= 0; i--) {
+ tops[i] = Math.min(
+ tops[i],
+ tops[i + 1] - threads[i].height - MIN_THREAD_GAP
+ );
+ }
+
+ // Threads pushed above the top come back down, and push the rest down.
+ let floor = 0;
+ for (let i = 0; i < threads.length; i++) {
+ tops[i] = Math.max(tops[i], floor);
+ floor = tops[i] + threads[i].height + MIN_THREAD_GAP;
+ }
+
+ return threads.map((thread, i): CommentLayout<T> => {
+ const end = tops[i] + thread.height;
+ const overflow: Overflow =
+ end >= pageHeight ? 'bottom' : tops[i] <= 0 ? 'top' : null;
+ return {
+ ...thread,
+ layout: { height: thread.height, calculatedYPos: tops[i], overflow },
+ };
+ });
+}
+
export function createCommentLayout() {
const { state } = useMarkdownDocument();
const commentState = state.comments;
@@ -141,57 +195,6 @@ export function createCommentLayout() {
setMarkLayouts(layouts);
});
- function computeLayout<T>({
- initialAnchor,
- input,
- direction,
- containerHeight,
- containerPadding = 0,
- }: {
- initialAnchor: number;
- input: (CommentViewerInitialLayout<T> & { height: number })[];
- direction: 'up' | 'down';
- containerHeight: number;
- containerPadding?: number;
- }): Array<CommentLayout<T>> {
- let anchor = initialAnchor;
- if (direction === 'up') {
- input.reverse();
- }
- const out = input.map((i): CommentLayout<T> => {
- let calculatedYPos = 0;
- if (direction === 'up') {
- calculatedYPos = Math.min(
- anchor - i.height - MIN_THREAD_GAP,
- i.layout.originalYPosition
- );
- anchor = calculatedYPos;
- } else {
- calculatedYPos = Math.max(
- anchor + MIN_THREAD_GAP,
- i.layout.originalYPosition
- );
- anchor = calculatedYPos + i.height;
- }
-
- let overflow: Overflow = null;
- if (calculatedYPos <= 0 + containerPadding) overflow = 'top';
- if (anchor >= containerHeight - containerPadding) overflow = 'bottom';
- return {
- ...i,
- layout: {
- height: i.height,
- calculatedYPos,
- overflow,
- },
- };
- });
- if (direction === 'up') {
- out.reverse();
- }
- return out;
- }
-
createEffect(() => {
const pageHeight = notebookHeight();
@@ -235,67 +238,17 @@ export function createCommentLayout() {
middleMarkId ?? sortedThreadsByOriginalPosition[0].id;
if (!anchorPositionId) return;
- let sliceTo = sortedThreadsByOriginalPosition.findIndex(
- (thread) => thread.id === anchorPositionId
+ const anchorIndex = Math.max(
+ 0,
+ sortedThreadsByOriginalPosition.findIndex(
+ (thread) => thread.id === anchorPositionId
+ )
+ );
+ const out = stackMarginThreads(
+ sortedThreadsByOriginalPosition,
+ anchorIndex,
+ pageHeight - CONTAINER_PADDING
);
- if (sliceTo === -1) {
- sliceTo = 0;
- }
- const sliceFrom = sliceTo + 1;
-
- // all threads on page above the anchor with height
- const sliceAboveAnchor = sortedThreadsByOriginalPosition.slice(0, sliceTo);
- // all threads on page below the anchor with height
- const sliceBelowAnchor = sortedThreadsByOriginalPosition.slice(sliceFrom);
-
- // calculate closest fit for anchor within bounds of container
- const anchorElement = sortedThreadsByOriginalPosition[sliceTo];
- const anchorHeight = anchorElement.height;
-
- // check if original y plus height fits inside bounds for anchor
- const paddedHeight = pageHeight - CONTAINER_PADDING;
- let anchorTop = anchorElement.layout.originalYPosition;
- let anchorEnd = anchorTop + anchorHeight;
- if (anchorEnd > paddedHeight) {
- const anchorOverflow = anchorEnd - paddedHeight;
- anchorTop -= anchorOverflow;
- }
-
- // handle edge case where anchor element is larger than container
- if (anchorTop < 0) {
- anchorTop = 0;
- }
- anchorEnd = anchorTop + anchorHeight;
-
- const layoutAboveAnchor = computeLayout({
- initialAnchor: anchorTop,
- direction: 'up',
- input: sliceAboveAnchor,
- containerHeight: pageHeight,
- containerPadding: CONTAINER_PADDING,
- });
-
- const layoutBelowAnchor = computeLayout({
- initialAnchor: anchorEnd,
- direction: 'down',
- input: sliceBelowAnchor,
- containerHeight: pageHeight,
- containerPadding: CONTAINER_PADDING,
- });
-
- // the positioning of all threads on the page
- const out: CommentLayout<{ id: MarkId }>[] = [
- ...layoutAboveAnchor,
- {
- ...anchorElement,
- layout: {
- height: anchorHeight,
- calculatedYPos: anchorTop,
- overflow: null,
- },
- },
- ...layoutBelowAnchor,
- ];
for (const layout of out) {
setThreadPositions(layout.id, layout);
@@ -303,7 +256,6 @@ export function createCommentLayout() {
});
return {
- notebookHeight,
setThreadHeights,
threadPositions,
};
diff --git a/apps/web/src/features/block-write/core/comment-layout.test.ts b/apps/web/src/features/block-write/core/comment-layout.test.ts
index 55609dc1c0..df1107b0cc 100644
--- a/apps/web/src/features/block-write/core/comment-layout.test.ts
+++ b/apps/web/src/features/block-write/core/comment-layout.test.ts
@@ -40,6 +40,22 @@ describe('layoutMarginCards', () => {
});
it('pins the active card and moves its neighbours around it', () => {
+ const placed = layoutMarginCards(
+ [
+ { id: 'a', top: 100 },
+ { id: 'b', top: 110 },
+ { id: 'c', top: 120 },
+ ],
+ heights,
+ 'b',
+ 10
+ );
+ expect(placed.get('b')).toBe(110);
+ expect(placed.get('a')).toBe(50);
+ expect(placed.get('c')).toBe(170);
+ });
+
+ it('pushes the stack down rather than above the top of the margin', () => {
const placed = layoutMarginCards(
[
{ id: 'a', top: 0 },
@@ -50,8 +66,8 @@ describe('layoutMarginCards', () => {
'b',
10
);
- expect(placed.get('b')).toBe(10);
- expect(placed.get('a')).toBe(-50);
- expect(placed.get('c')).toBe(70);
+ expect(placed.get('a')).toBe(0);
+ expect(placed.get('b')).toBe(60);
+ expect(placed.get('c')).toBe(120);
});
});
diff --git a/apps/web/src/features/block-write/core/comment-layout.ts b/apps/web/src/features/block-write/core/comment-layout.ts
index 4f4a19f886..b3438e901e 100644
--- a/apps/web/src/features/block-write/core/comment-layout.ts
+++ b/apps/web/src/features/block-write/core/comment-layout.ts
@@ -3,7 +3,9 @@ export type MarginItem = { id: string; top: number };
/**
* Stack margin cards beside their anchors without overlap. The active card
* sits exactly at its anchor; cards above it are pushed up and cards below
- * are pushed down, the way a word processor's markup area behaves.
+ * are pushed down, the way a word processor's markup area behaves. No card
+ * starts above the top of the margin, where it could not be scrolled to:
+ * when the cards above the active one do not fit, the stack is pushed down.
*/
export function layoutMarginCards(
items: readonly MarginItem[],
@@ -40,5 +42,12 @@ export function layoutMarginCards(
placed.set(item.id, top);
ceiling = top;
}
+ if (ceiling >= 0) return placed;
+ let floor = 0;
+ for (const item of sorted) {
+ const top = Math.max(placed.get(item.id) ?? item.top, floor);
+ placed.set(item.id, top);
+ floor = top + height(item.id) + gap;
+ }
return placed;
}
diff --git a/apps/web/src/features/channel/Message/Content.tsx b/apps/web/src/features/channel/Message/Content.tsx
index aae4144f3c..74b5f5b7fe 100644
--- a/apps/web/src/features/channel/Message/Content.tsx
+++ b/apps/web/src/features/channel/Message/Content.tsx
@@ -2,13 +2,32 @@ import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/S
import { channelTheme } from '@core/component/LexicalMarkdown/theme';
import { isEmojiOnly } from '@core/util/string';
-import { cn } from '@ui';
-import { createMemo, createSignal, Show } from 'solid-js';
+import CaretRight from '@phosphor/caret-right.svg';
+import { Button, cn } from '@ui';
+import {
+ createMemo,
+ createSignal,
+ type JSX,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
import { splitMessageContent } from './agent-session-link';
-import { useMessage, useSearchHighlightTermsLookup } from './context';
+import {
+ useCollapseLongContent,
+ useMessage,
+ useSearchHighlightTermsLookup,
+} from './context';
import { createSearchHighlightOverlay } from './highlightOverlay';
import { MentionedImages } from './MentionedImages';
+// Height (px) a long body is cut to while collapsed.
+const COLLAPSED_MAX_HEIGHT = 240;
+// Collapse only when that hides a few lines or more, never just the last one.
+const COLLAPSE_THRESHOLD = COLLAPSED_MAX_HEIGHT + 64;
+const FADE_HEIGHT = 32;
+const FADE_MASK = `linear-gradient(to bottom, black calc(100% - ${FADE_HEIGHT}px), transparent 100%)`;
+
type ContentProps = {
class?: string;
};
@@ -16,6 +35,7 @@ type ContentProps = {
export function Content(props: ContentProps) {
const message = useMessage();
const termsLookup = useSearchHighlightTermsLookup();
+ const collapseLongContent = useCollapseLongContent();
// The body only: an agent message's leading session node is chrome the
// sender line renders (`Message.AgentSessionLink`), not part of the text.
@@ -27,6 +47,18 @@ export function Content(props: ContentProps) {
createSearchHighlightOverlay({ root: markdownRoot, content, terms });
+ const body = () => (
+ <>
+ <StaticMarkdown
+ markdown={content()}
+ theme={channelTheme}
+ target="internal"
+ rootRef={setMarkdownRoot}
+ />
+ <MentionedImages content={content()} />
+ </>
+ );
+
return (
<Show when={content()}>
<div
@@ -37,14 +69,75 @@ export function Content(props: ContentProps) {
props.class
)}
>
- <StaticMarkdown
- markdown={content()}
- theme={channelTheme}
- target="internal"
- rootRef={setMarkdownRoot}
- />
- <MentionedImages content={content()} />
+ <Show when={collapseLongContent} fallback={body()}>
+ <CollapsibleBody>{body()}</CollapsibleBody>
+ </Show>
</div>
</Show>
);
}
+
+/** Cuts a long body to a faded preview with a "Show more" / "Show less" toggle. */
+function CollapsibleBody(props: { children: JSX.Element }) {
+ const [expanded, setExpanded] = createSignal(false);
+ const [overflowing, setOverflowing] = createSignal(false);
+ let measureRef!: HTMLDivElement;
+
+ onMount(() => {
+ // The unclamped inner box keeps its full height, so it reports growth
+ // (images loading, edits) even while the preview is cut.
+ const measure = () =>
+ setOverflowing(measureRef.offsetHeight > COLLAPSE_THRESHOLD);
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(measureRef);
+ onCleanup(() => observer.disconnect());
+ });
+
+ const collapsed = () => overflowing() && !expanded();
+
+ return (
+ <>
+ <div
+ data-collapsed={collapsed() ? '' : undefined}
+ class={cn(collapsed() && 'overflow-hidden')}
+ // Tabbing to a link under the cut (or in the fade) reveals it
+ // instead of focusing something hidden.
+ onFocusIn={(event) => {
+ if (!collapsed() || !(event.target instanceof Element)) return;
+ const cut = event.currentTarget.getBoundingClientRect().bottom;
+ const target = event.target.getBoundingClientRect().bottom;
+ if (target > cut - FADE_HEIGHT) setExpanded(true);
+ }}
+ style={
+ collapsed()
+ ? {
+ 'max-height': `${COLLAPSED_MAX_HEIGHT}px`,
+ 'mask-image': FADE_MASK,
+ '-webkit-mask-image': FADE_MASK,
+ }
+ : undefined
+ }
+ >
+ <div ref={measureRef}>{props.children}</div>
+ </div>
+ <Show when={overflowing()}>
+ <Button
+ type="button"
+ variant="ghost"
+ size="xs"
+ class="mt-1 -ml-1.5 text-ink-muted"
+ aria-expanded={expanded()}
+ onClick={() => setExpanded((prev) => !prev)}
+ >
+ <CaretRight
+ aria-hidden="true"
+ class="transition-transform"
+ classList={{ 'rotate-90': expanded() }}
+ />
+ {expanded() ? 'Show less' : 'Show more'}
+ </Button>
+ </Show>
+ </>
+ );
+}
diff --git a/apps/web/src/features/channel/Message/context.ts b/apps/web/src/features/channel/Message/context.ts
index 5432e01be3..d2de6fdb0a 100644
--- a/apps/web/src/features/channel/Message/context.ts
+++ b/apps/web/src/features/channel/Message/context.ts
@@ -18,12 +18,23 @@ export type SearchHighlightTermsLookup = (
const SearchHighlightTermsContext = createContext<SearchHighlightTermsLookup>();
+/**
+ * Hosts with narrow message cards (document margin comments) cap long message
+ * bodies behind "Show more". Channels and other full-width timelines leave it off.
+ */
+const CollapseLongContentContext = createContext(false);
+
export const MessageProvider = MessageContext.Provider;
export const MessageActionsProvider = MessageActionsContext.Provider;
export const MessageActionMenuVisibilityProvider =
MessageActionMenuVisibilityContext.Provider;
export const SearchHighlightTermsProvider =
SearchHighlightTermsContext.Provider;
+export const CollapseLongContentProvider = CollapseLongContentContext.Provider;
+
+export function useCollapseLongContent(): boolean {
+ return useContext(CollapseLongContentContext);
+}
export function useSearchHighlightTermsLookup():
| SearchHighlightTermsLookup
diff --git a/apps/web/src/features/channel/Message/tests/collapsible-content.test.tsx b/apps/web/src/features/channel/Message/tests/collapsible-content.test.tsx
new file mode 100644
index 0000000000..9d601bd613
--- /dev/null
+++ b/apps/web/src/features/channel/Message/tests/collapsible-content.test.tsx
@@ -0,0 +1,119 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { MessageData } from '@core/messages/types';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { Content } from '../Content';
+import { CollapseLongContentProvider, MessageProvider } from '../context';
+
+vi.mock(
+ '@core/component/LexicalMarkdown/component/core/StaticMarkdown',
+ () => ({
+ StaticMarkdown: (props: { markdown: string }) => <p>{props.markdown}</p>,
+ })
+);
+vi.mock('../MentionedImages', () => ({ MentionedImages: () => null }));
+
+const message = {
+ id: 'comment',
+ content: 'A very long comment',
+ sender_id: 'macro|[email protected]',
+ created_at: '2026-10-21T00:00:00.000Z',
+ updated_at: '2026-10-21T00:00:00.000Z',
+ attachments: [],
+ reactions: [],
+} as unknown as MessageData;
+
+function setBodyHeight(height: number) {
+ vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(
+ height
+ );
+}
+
+function renderContent(collapse: boolean) {
+ return render(() => (
+ <CollapseLongContentProvider value={collapse}>
+ <MessageProvider value={() => message}>
+ <Content />
+ </MessageProvider>
+ </CollapseLongContentProvider>
+ ));
+}
+
+describe('long message content', () => {
+ beforeEach(() => {
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ observe() {}
+ disconnect() {}
+ }
+ );
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+ });
+
+ it('folds behind Show more and expands and collapses again', () => {
+ setBodyHeight(800);
+ const view = renderContent(true);
+ const preview = () => view.container.querySelector('[data-collapsed]');
+
+ expect(preview()).not.toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Show more' }));
+ expect(preview()).toBeNull();
+ expect(screen.getByText('A very long comment')).toBeTruthy();
+
+ const less = screen.getByRole('button', { name: 'Show less' });
+ expect(less.getAttribute('aria-expanded')).toBe('true');
+ fireEvent.click(less);
+ expect(preview()).not.toBeNull();
+ expect(screen.getByRole('button', { name: 'Show more' })).toBeTruthy();
+ });
+
+ it('reveals a hidden link when focus moves into it', () => {
+ setBodyHeight(800);
+ const view = renderContent(true);
+ const preview = () => view.container.querySelector('[data-collapsed]');
+ const text = screen.getByText('A very long comment');
+ vi.spyOn(preview()!, 'getBoundingClientRect').mockReturnValue({
+ bottom: 240,
+ } as DOMRect);
+
+ // Focus above the cut leaves the preview alone.
+ vi.spyOn(text, 'getBoundingClientRect').mockReturnValue({
+ bottom: 100,
+ } as DOMRect);
+ fireEvent.focusIn(text);
+ expect(preview()).not.toBeNull();
+
+ // Focus under the cut expands so the focused link is visible.
+ vi.spyOn(text, 'getBoundingClientRect').mockReturnValue({
+ bottom: 400,
+ } as DOMRect);
+ fireEvent.focusIn(text);
+ expect(preview()).toBeNull();
+ expect(screen.getByRole('button', { name: 'Show less' })).toBeTruthy();
+ });
+
+ it('leaves a short comment whole', () => {
+ setBodyHeight(120);
+ const view = renderContent(true);
+
+ expect(view.container.querySelector('[data-collapsed]')).toBeNull();
+ expect(screen.queryByRole('button')).toBeNull();
+ });
+
+ it('never folds where the host does not ask for it', () => {
+ setBodyHeight(800);
+ const view = renderContent(false);
+
+ expect(view.container.querySelector('[data-collapsed]')).toBeNull();
+ expect(screen.queryByRole('button')).toBeNull();
+ });
+});
diff --git a/apps/web/src/lib/core/comments/MeasureContainer.tsx b/apps/web/src/lib/core/comments/MeasureContainer.tsx
index 335a0dadc5..8640c6cd6c 100644
--- a/apps/web/src/lib/core/comments/MeasureContainer.tsx
+++ b/apps/web/src/lib/core/comments/MeasureContainer.tsx
@@ -14,7 +14,6 @@ type MeasureContainerProps = {
alignmentOffset: number;
top: number;
ref?: Ref<HTMLDivElement>;
- maxHeight?: number;
threadId: ThreadId;
isActive: boolean;
forceWidth?: number;
@@ -69,7 +68,6 @@ export const MeasureContainer = (props: ParentProps<MeasureContainerProps>) => {
? { left: `${props.alignmentOffset}px` }
: { right: `${props.alignmentOffset}px` }),
top: `${props.top}px`,
- 'max-height': props.maxHeight ? `${props.maxHeight}px` : undefined,
'min-width': props.forceWidth ? `${props.forceWidth}px` : undefined,
'z-index': props.isActive
? 'calc(var(--z-index-placeable) + 1)'
diff --git a/apps/web/src/lib/core/comments/MinimizedThreads.tsx b/apps/web/src/lib/core/comments/MinimizedThreads.tsx
index b5a9285f95..ca39f7a9af 100644
--- a/apps/web/src/lib/core/comments/MinimizedThreads.tsx
+++ b/apps/web/src/lib/core/comments/MinimizedThreads.tsx
@@ -13,7 +13,6 @@ export function MinimizedThread(props: {
layout: Layout;
isActive: boolean;
theme?: EditorThemeClasses;
- maxHeight?: number;
/**
* When false, tapping only activates the thread instead of expanding the
* floating card in place — for hosts that present the active thread
@@ -79,7 +78,6 @@ export function MinimizedThread(props: {
alignmentOffset={0}
top={props.layout.calculatedYPos}
threadId={props.comment.threadId}
- maxHeight={props.maxHeight}
isActive={props.isActive}
transition={false}
>
diff --git a/apps/web/src/lib/core/comments/Thread.tsx b/apps/web/src/lib/core/comments/Thread.tsx
index 17ae1f2596..a538bafece 100644
--- a/apps/web/src/lib/core/comments/Thread.tsx
+++ b/apps/web/src/lib/core/comments/Thread.tsx
@@ -1,6 +1,7 @@
import { URL_PARAMS as MD_URL_PARAMS } from '@block-md/constants';
import { ChannelInput } from '@channel/Input';
import { buildPostMessageSendPayload } from '@channel/Input/message-payload';
+import { CollapseLongContentProvider } from '@channel/Message/context';
import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { createTheme } from '@core/component/LexicalMarkdown/theme';
import { UserIcon } from '@core/component/UserIcon';
@@ -251,7 +252,6 @@ export function Thread(props: {
layout: Layout;
isActive: boolean;
theme?: EditorThemeClasses;
- maxHeight?: number;
handleMouseDown?: (e: MouseEvent) => void;
}) {
let measureContainerRef!: HTMLDivElement;
@@ -272,7 +272,6 @@ export function Thread(props: {
ref={measureContainerRef}
top={props.layout.calculatedYPos}
threadId={props.comment.threadId}
- maxHeight={props.maxHeight}
isActive={props.isActive}
transition={false}
>
@@ -310,12 +309,15 @@ export function ThreadCard(props: {
width: props.width ? `${props.width}px` : 'auto',
}}
>
- <ThreadBody
- comment={props.comment}
- isActive={props.isActive}
- theme={props.theme}
- flatComposer
- />
+ {/* The card is narrow, so long comments fold behind "Show more". */}
+ <CollapseLongContentProvider value={true}>
+ <ThreadBody
+ comment={props.comment}
+ isActive={props.isActive}
+ theme={props.theme}
+ flatComposer
+ />
+ </CollapseLongContentProvider>
</div>
</Layer>
);
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index eead6b2be0..17727594df 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -2657,7 +2657,15 @@ on phones) and never in the bottom Discussion, including after live updates or
reloads. Links to these threads open the margin without changing the bottom
Discussion's timeline or expanding it. Existing highlights locate threads by
their stable mark IDs. Replies, attachments, reactions, and editing use the same
-message controls as channels.
+message controls as channels. In every floating comment card (the Markdown,
+PDF, and Word margins and expanded minimized threads), a long comment folds to
+a faded preview with **Show more**; **Show less** folds it again. Short
+comments, the phone drawer, the bottom Discussion, and channels always show the
+full text. Markdown and Word margin cards stack without overlapping: a tall or expanded card
+pushes the cards below it down (past the end of a short document if needed),
+and no card starts above the top of the document. Check this with a long
+thread active near the bottom of a short document that has another thread
+above and below it.
Removing the last marked text moves its retained conversation to Discussion,
where it remains after reload. Removing only part of a marked range keeps the
conversation anchored to the remaining text. On phones, the active Markdown