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.

fix(composer): space composer paragraphs like the message they send (#9107)

Peter Chinmanbc9fc677c724
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 3f19197854..b8f98c7032 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -141,7 +141,8 @@ ranking and insertion on desktop and phone.
Channel composer draft persistence has a backend-free browser regression:
`bunx playwright test --config src/features/channel/Input/browser-test/playwright.config.ts`.
-It checks draft blank lines across remounts and pending sends on desktop and phone: clear immediately, restore failed sends, and preserve a new draft typed during delivery.
+It checks draft blank lines across remounts, that a sent message renders its
+lines with the spacing the draft showed, and pending sends on desktop and phone: clear immediately, restore failed sends, and preserve a new draft typed during delivery.
It also pastes a Macro link and Markdown into a code block, which must keep both as literal text.
Block formatting passes a forward copy of the selection to Lexical's
@@ -244,6 +245,9 @@ Keep persistent list hotkeys free of mounted-view closures, and clear
virtualizer accessors when their view unmounts.
Keep editor newline handling local; result-opening handlers must yield
Shift+Enter while an editor owns focus instead of adding shared hotkey flags.
+A composer renders paragraphs with the spacing its sent message renders with,
+so a draft reads as what it will send; drop only the draft's first and last
+margins, which the compact single-row layout measures.
- Reuse `src/components/WorkspaceTexture.tsx` for the onboarding and Create
detail panel grain; pass the surface accent and a unique SVG filter ID.
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsx
index 1b98687b7b..d150e04dcc 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx
@@ -286,7 +286,7 @@ export function ChatComposer(props: {
class="min-w-0 flex-1 self-center overflow-y-auto px-[9.375px] not-touch:group-data-[composer-compact=false]/composer:px-1.5 group-data-[composer-compact=true]/composer:px-0 group-data-[composer-coding=true]/composer:min-h-[58px] touch:group-data-[composer-compact=false]/composer:min-h-18 group-data-[composer-compact=false]/composer:flex-none group-data-[composer-compact=false]/composer:basis-full"
>
<MarkdownShell
- class="h-auto min-h-6 text-base leading-6 [&_[data-markdown-editable]]:min-h-6 [&_[data-markdown-editable]]:outline-none [&_[data-markdown-editable]>.md-p]:my-0 [&_[data-markdown-placeholder]]:max-w-full [&_[data-markdown-placeholder]>p]:m-0 [&_[data-markdown-placeholder]>p]:truncate"
+ class="h-auto min-h-6 text-base leading-6 [&_[data-markdown-editable]]:min-h-6 [&_[data-markdown-editable]]:outline-none [&_[data-markdown-editable]>.md-p:first-child]:mt-0 [&_[data-markdown-editable]>.md-p:last-child]:mb-0 [&_[data-markdown-placeholder]]:max-w-full [&_[data-markdown-placeholder]>p]:m-0 [&_[data-markdown-placeholder]>p]:truncate"
config={editor}
initialValue={props.draft}
placeholder={
diff --git a/apps/web/src/features/channel/Input/browser-test/README.md b/apps/web/src/features/channel/Input/browser-test/README.md
index f0e958a2c0..2691809415 100644
--- a/apps/web/src/features/channel/Input/browser-test/README.md
+++ b/apps/web/src/features/channel/Input/browser-test/README.md
@@ -1,4 +1,4 @@
-# Channel composer draft browser regression
+# Channel composer browser regressions
From `apps/web`, run:
@@ -16,6 +16,11 @@ blank line, unmounts the composer and mounts it again over the persisted draft,
which is the round trip through internal markdown that used to drop every blank
line.
+The line-break regression sends a draft into the renderer channel messages use
+and compares the message's rendered line spacing with the draft's. The composer
+used to flatten its paragraphs, so lines the draft showed together were spaced
+out on send.
+
The send regression checks desktop and phone: a pending send clears the editor,
a rejected send restores its draft, and a rejection preserves a newer draft
typed while delivery was pending. The fixture controls completion locally.
diff --git a/apps/web/src/features/channel/Input/browser-test/spacing.browser.e2e.ts b/apps/web/src/features/channel/Input/browser-test/spacing.browser.e2e.ts
new file mode 100644
index 0000000000..fddc5b3832
--- /dev/null
+++ b/apps/web/src/features/channel/Input/browser-test/spacing.browser.e2e.ts
@@ -0,0 +1,65 @@
+import { expect, test } from '@playwright/test';
+
+/** Distance in pixels between the tops of a box's rendered text lines. */
+const lineGaps = (selector: string) => {
+ const box = document.querySelector(selector);
+ if (!box) throw new Error(`No ${selector}`);
+ const range = document.createRange();
+ const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT);
+ const tops: number[] = [];
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
+ if (!node.textContent?.trim()) continue;
+ range.selectNodeContents(node);
+ tops.push(Math.round(range.getBoundingClientRect().top));
+ }
+ const sorted = [...new Set(tops)].sort((a, b) => a - b);
+ return sorted.slice(1).map((top, index) => top - sorted[index]);
+};
+
+test('a sent message keeps the line spacing of the draft that wrote it', async ({
+ page,
+}) => {
+ // The composer and the message renderer run over synthetic props; no hosted
+ // data is read or written.
+ await page.route('**/*', async (route) => {
+ const url = new URL(route.request().url());
+ if (url.hostname === 'localhost') {
+ await route.continue();
+ } else {
+ await route.fulfill({
+ status: 401,
+ contentType: 'application/json',
+ body: JSON.stringify({ responses: [] }),
+ });
+ }
+ });
+ await page.routeWebSocket('**/*', (socket) => socket.close());
+ await page.goto('/src/features/channel/Input/browser-test/spacing.html');
+
+ const editor = page.locator('[data-markdown-editable]');
+ await expect(editor).toBeVisible({ timeout: 30_000 });
+ await editor.click();
+ // Shift+Enter is the composer's newline; Enter sends. Two in a row leave a
+ // blank line.
+ await page.keyboard.type('Line 1');
+ await page.keyboard.press('Shift+Enter');
+ await page.keyboard.type('Line 2');
+ await page.keyboard.press('Shift+Enter');
+ await page.keyboard.press('Shift+Enter');
+ await page.keyboard.type('Line 4');
+
+ const draftGaps = await page.evaluate(lineGaps, '[data-markdown-editable]');
+ // One line down, then a line and the blank one between.
+ expect(draftGaps).toHaveLength(2);
+ expect(draftGaps[1]).toBeGreaterThan(draftGaps[0] * 1.5);
+
+ await page.keyboard.press('Enter');
+ await expect(page.locator('[data-sent-message]')).toHaveCount(1);
+
+ const messageGaps = await page.evaluate(lineGaps, '[data-sent-message]');
+ // The composer's line height is a fraction of a pixel off the message's.
+ expect(messageGaps).toHaveLength(draftGaps.length);
+ for (const [index, gap] of messageGaps.entries()) {
+ expect(Math.abs(gap - draftGaps[index])).toBeLessThanOrEqual(1);
+ }
+});
diff --git a/apps/web/src/features/channel/Input/browser-test/spacing.html b/apps/web/src/features/channel/Input/browser-test/spacing.html
new file mode 100644
index 0000000000..0a2767cc66
--- /dev/null
+++ b/apps/web/src/features/channel/Input/browser-test/spacing.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<html lang="en">
+ <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Channel composer spacing</title></head>
+ <body><div id="root"></div><script type="module" src="./spacing.tsx"></script></body>
+</html>
diff --git a/apps/web/src/features/channel/Input/browser-test/spacing.tsx b/apps/web/src/features/channel/Input/browser-test/spacing.tsx
new file mode 100644
index 0000000000..7050833b67
--- /dev/null
+++ b/apps/web/src/features/channel/Input/browser-test/spacing.tsx
@@ -0,0 +1,77 @@
+import '@app/index.css';
+import { AnalyticsContextProvider } from '@app/lib/analytics/analytics-context';
+import { PosthogProvider } from '@app/lib/analytics/posthog';
+import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
+import { channelTheme } from '@core/component/LexicalMarkdown/theme';
+import { ChannelsContextProvider } from '@core/context/channels';
+import { QuickAccessProvider } from '@core/context/quickAccess/QuickAccessProvider';
+import { UserContextProvider } from '@core/context/user';
+import { useHotKeyRoot } from '@core/hotkey/hotkeys';
+import { EntityProvider } from '@entity';
+import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
+import { createSignal, For, onCleanup } from 'solid-js';
+import { render } from 'solid-js/web';
+import { ChannelInput } from '../ChannelInput';
+
+/**
+ * The real channel composer above the renderer channel messages use, so a
+ * draft and the message it sends can be compared line for line.
+ */
+function Fixture() {
+ useHotKeyRoot();
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ onCleanup(() => client.clear());
+ const [sent, setSent] = createSignal<string[]>([]);
+ return (
+ <QueryClientProvider client={client}>
+ <AnalyticsContextProvider>
+ <PosthogProvider>
+ <EntityProvider>
+ <UserContextProvider>
+ <ChannelsContextProvider>
+ <QuickAccessProvider>
+ <main class="min-h-screen bg-page p-4 text-ink space-y-4">
+ <section data-sent-messages class="space-y-2">
+ <For each={sent()}>
+ {(markdown) => (
+ <div
+ data-sent-message
+ class="whitespace-pre-wrap wrap-break-word max-w-full text-base"
+ >
+ <StaticMarkdown
+ markdown={markdown}
+ theme={channelTheme}
+ target="internal"
+ />
+ </div>
+ )}
+ </For>
+ </section>
+ <ChannelInput
+ input={{
+ mode: 'channel',
+ id: 'channel-input-spacing',
+ placeholder: 'Message #spacing',
+ }}
+ participants={() => []}
+ bots={() => []}
+ onSend={(snapshot) => {
+ setSent((previous) => [...previous, snapshot.value]);
+ }}
+ />
+ </main>
+ </QuickAccessProvider>
+ </ChannelsContextProvider>
+ </UserContextProvider>
+ </EntityProvider>
+ </PosthogProvider>
+ </AnalyticsContextProvider>
+ </QueryClientProvider>
+ );
+}
+
+const root = document.getElementById('root');
+if (!root) throw new Error('Fixture root missing');
+render(() => <Fixture />, root);
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/ComposerEditor.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/ComposerEditor.tsx
index 6f5906b70b..325144cd0c 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/ComposerEditor.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/ComposerEditor.tsx
@@ -4,14 +4,19 @@ import {
type MarkdownShellProps,
} from '../builder/MarkdownShell';
-/** Shared message editor sizing and colors. */
+/**
+ * Shared message editor sizing and colors. Paragraphs keep the markdown
+ * theme's spacing, which is what the sent message renders with; only the
+ * draft's first and last margins go, so one paragraph fills the composer's
+ * row exactly.
+ */
export function ComposerEditor(props: MarkdownShellProps) {
return (
<MarkdownShell
{...props}
class={cn(
'not-touch:min-h-[24.375px] text-base not-touch:leading-[24.375px] not-touch:text-composer-ink',
- 'not-touch:[&>[data-markdown-editable]]:min-h-[24.375px] not-touch:[&>[data-markdown-editable]]:max-h-[195px] not-touch:[&>[data-markdown-editable]]:overflow-y-auto not-touch:[&>[data-markdown-editable]>p]:my-0 not-touch:[&>[data-markdown-editable]>p:first-child]:mt-0 not-touch:[&>[data-markdown-editable]>p:last-child]:mb-0',
+ 'not-touch:[&>[data-markdown-editable]]:min-h-[24.375px] not-touch:[&>[data-markdown-editable]]:max-h-[195px] not-touch:[&>[data-markdown-editable]]:overflow-y-auto not-touch:[&>[data-markdown-editable]>p:first-child]:mt-0 not-touch:[&>[data-markdown-editable]>p:last-child]:mb-0',
'not-touch:[&>[data-markdown-placeholder]]:text-composer-placeholder not-touch:[&>[data-markdown-placeholder]>p]:my-0',
props.class
)}
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 8f06c6b17f..3293cf1ad8 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -333,6 +333,10 @@ wrapping paragraph should stay expanded without briefly collapsing; check this
after reopening the channel with a draft already saved. Open reply composers always place the editor
above the action row, including for empty and single-line drafts, so the
attachment, delete-reply, and send controls have their own space.
+Shift+Enter adds a line to the draft; Enter sends. The composer spaces its
+paragraphs the way the sent message does, so a multi-line draft reads as what
+it will send. Check a multi-line message against the draft that wrote it: the
+spacing must not change on send.
Both the expanded and collapsed composers start with a `+` button (`Add`). It
opens a menu on desktop and a bottom drawer on mobile: `Mention` (opens the `@` typeahead), `Attach files` (the file
picker; the iOS media picker on iOS), `GIF` (the same picker as `/gif`), then under `Create` the same actions as