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(paste): make the pasted text viewer selectable and copyable (#7918)

teo196b06589af1
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
index a0589a0077..316dbd30b2 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
@@ -12,6 +12,7 @@ import {
type LexicalEditor,
} from 'lexical';
import { createSignal } from 'solid-js';
+import { Portal } from 'solid-js/web';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { RepositoryPicker } from '../views/RepositoryPicker';
import { ChatComposer, ChatSessionInput } from './ChatComposer';
@@ -97,7 +98,13 @@ vi.mock(
vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({
MarkdownShell: (props: { placeholder?: string }) => (
- <div data-testid="editor">{props.placeholder}</div>
+ <div data-testid="editor">
+ {props.placeholder}
+ {/* Decorators portal their popups (the paste viewer) out of the editor. */}
+ <Portal>
+ <pre data-testid="portaled-text">Pasted text</pre>
+ </Portal>
+ </div>
),
}));
@@ -439,6 +446,22 @@ describe('Chat session input', () => {
screen.getByRole('textbox', { name: 'Filter models' }).dispatchEvent(event);
expect(event.defaultPrevented).toBe(false);
});
+
+ it('leaves presses in portaled editor popups to the browser so their text can be selected', () => {
+ render(() => <ChatSessionInput onSend={vi.fn()} />);
+ const press = (target: Element, type: string) => {
+ const event = new MouseEvent(type, { bubbles: true, cancelable: true });
+ target.dispatchEvent(event);
+ return event.defaultPrevented;
+ };
+ const surface = document.querySelector('[data-agent-composer="chat"]')!;
+ const portaled = screen.getByTestId('portaled-text');
+ expect(surface.contains(portaled)).toBe(false);
+ for (const type of ['pointerdown', 'mousedown']) {
+ expect(press(surface, type)).toBe(true);
+ expect(press(portaled, type)).toBe(false);
+ }
+ });
});
it('expands for a short quote and collapses when replaced with a paragraph', () => {
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsx
index 1a567c3701..c6bf376f96 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx
@@ -217,6 +217,10 @@ export function ChatComposer(props: {
target.closest('[data-composer-controls], button, input, select, a')
)
return;
+ // Solid delegates events from popups the editor portals out of the
+ // composer (the paste viewer) through here; cancelling them blocks
+ // selecting their text.
+ if (!(event.currentTarget as Node).contains(target)) return;
if (editor.lexical.getRootElement()?.contains(target)) return;
event.preventDefault();
if (event.type === 'pointerdown') editor.controls.focus();
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
index 8592ed9c88..b49dc70165 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
@@ -14,6 +14,7 @@ import {
import { preloadAgentFold } from '@core/agent-fold/client';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { Portal } from 'solid-js/web';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AGENT_INPUT_TEXT_AREA_ID, AgentInput } from './AgentInput';
@@ -91,6 +92,10 @@ vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({
MarkdownShell: (props: { disabled?: boolean; initialValue?: string }) => (
<div data-testid="agent-input-editor" data-disabled={props.disabled}>
{props.initialValue}
+ {/* Decorators portal their popups (the paste viewer) out of the editor. */}
+ <Portal>
+ <pre data-testid="portaled-text">Pasted text</pre>
+ </Portal>
</div>
),
}));
@@ -393,6 +398,22 @@ describe('attachments', () => {
});
});
+it('leaves presses in portaled editor popups to the browser so their text can be selected', () => {
+ const { container } = render(() => <AgentInput onSend={vi.fn()} />);
+ const press = (target: Element, type: string) => {
+ const event = new MouseEvent(type, { bubbles: true, cancelable: true });
+ target.dispatchEvent(event);
+ return event.defaultPrevented;
+ };
+ const padding = container.querySelector('[data-composer-compact]')!;
+ const portaled = screen.getByTestId('portaled-text');
+ expect(container.contains(portaled)).toBe(false);
+ for (const type of ['pointerdown', 'mousedown']) {
+ expect(press(padding, type)).toBe(true);
+ expect(press(portaled, type)).toBe(false);
+ }
+});
+
it('expands for a short quote and collapses when replaced with a paragraph', () => {
const { container } = render(() => <AgentInput onSend={vi.fn()} />);
const layout = container.querySelector('[data-composer-compact]');
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsx
index 777402c074..18f21ea62e 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx
@@ -314,11 +314,14 @@ export function AgentInput(props: AgentInputProps) {
// mousedown too because a real iPhone still synthesises it after a
// cancelled pointerdown (see `keepEditorFocus` in TouchSelectionToolbar).
// Taps inside the contenteditable keep their defaults so the caret lands
- // under the finger.
+ // under the finger. So do presses in popups the editor portals out of the
+ // composer (the paste viewer): Solid still delegates their events through
+ // here, and cancelling them blocks selecting their text.
const focusEditor = (event: Event) => {
if (props.readOnly) return;
const target = event.target as HTMLElement | null;
if (!target || target.closest('button')) return;
+ if (!(event.currentTarget as Node).contains(target)) return;
if (editor.lexical.getRootElement()?.contains(target)) return;
event.preventDefault();
if (event.type === 'pointerdown') editor.controls.focus();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/paste/PasteTextViewer.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/paste/PasteTextViewer.tsx
index 1f897fc21a..16554b944c 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/paste/PasteTextViewer.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/paste/PasteTextViewer.tsx
@@ -39,7 +39,7 @@ export function PasteTextViewer(props: {
);
const fullText = () => (
- <pre class="font-mono text-sm leading-relaxed bg-message p-4 m-0 whitespace-pre-wrap wrap-break-word overflow-auto">
+ <pre class="font-mono text-sm leading-relaxed bg-message p-4 m-0 whitespace-pre-wrap wrap-break-word overflow-auto select-text">
{props.content}
</pre>
);
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index a8e007674d..9d598c1f54 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -1130,6 +1130,9 @@ choose **Reply to this** above the selection. The composer inserts a single-line
**Replying to** preview with the same quote-reply styling as channel replies.
Click the preview to open the full **Referenced text** viewer. While editable,
hover the preview for its menu: **Copy**, **Convert to text**, or **Delete**.
+A plain-text paste over 1500 characters collapses into a **pasted** chip that
+opens the same viewer, titled **Pasted text**. Text in either viewer can be
+drag-selected and copied, from the composer and from sent messages.
Selecting text in the composer or outside the transcript must not show the reply
button; clearing the transcript selection dismisses it.