Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(comments): Enter and Escape shortcuts for comment bubbles (#8356)
Jacob Beckermanbf850aa1e4cb
diff --git a/apps/web/src/features/channel/Thread/ThreadReplyChannelInput.tsx b/apps/web/src/features/channel/Thread/ThreadReplyChannelInput.tsxindex c457646e82..bd49b8316e 100644--- a/apps/web/src/features/channel/Thread/ThreadReplyChannelInput.tsx+++ b/apps/web/src/features/channel/Thread/ThreadReplyChannelInput.tsx@@ -138,6 +138,10 @@ export function ThreadReplyChannelInput(props: ThreadReplyChannelInputProps) {props.setReplyInputState(undefined);props.onExit();}}+ onEscape={() => {+ props.setReplyInputState(undefined);+ props.onExit();+ }}onSend={(snapshot) => {const senderId = userId();if (!senderId) return;diff --git a/apps/web/src/lib/core/comments/Thread.tsx b/apps/web/src/lib/core/comments/Thread.tsxindex a538bafece..3f564b0fb2 100644--- a/apps/web/src/lib/core/comments/Thread.tsx+++ b/apps/web/src/lib/core/comments/Thread.tsx@@ -134,6 +134,7 @@ export function ThreadBody(props: ThreadBodyProps) {flat={props.flatComposer}input={{ mode: 'reply', placeholder: 'Leave a comment...' }}onClose={() => context.setActiveThread(null)}+ onEscape={() => context.setActiveThread(null)}onSend={async (snapshot) => {const { thread_id: _threadId, ...message } =buildPostMessageSendPayload({ snapshot }).message;@@ -163,6 +164,7 @@ export function ThreadBody(props: ThreadBodyProps) {canWrite={context.canComment()}canModerate={context.isDocumentOwner()}monorail+ keyboardActive={props.isActive}hideReplyInput={props.hideReplyInput}onEditingChange={context.setMessageEditing}targetId={targetId()}@@ -294,6 +296,7 @@ export function ThreadCard(props: {/** Nudge the active card toward the text it annotates. */shifted?: boolean;}) {+ const context = useContext(CommentsContext);return (<Layer depth={2}><div@@ -308,6 +311,11 @@ export function ThreadCard(props: {style={{width: props.width ? `${props.width}px` : 'auto',}}+ onKeyDown={(e) => {+ if (e.key !== 'Escape' || e.defaultPrevented) return;+ e.preventDefault();+ context.setActiveThread(null);+ }}>{/* The card is narrow, so long comments fold behind "Show more". */}<CollapseLongContentProvider value={true}>diff --git a/apps/web/src/lib/core/comments/discussion/Discussion.tsx b/apps/web/src/lib/core/comments/discussion/Discussion.tsxindex 91516bc5ff..5ed0496663 100644--- a/apps/web/src/lib/core/comments/discussion/Discussion.tsx+++ b/apps/web/src/lib/core/comments/discussion/Discussion.tsx@@ -408,6 +408,9 @@ export function DiscussionThreadView(props: {onClose={() => {setIsReplying(false);}}+ onEscape={() => {+ setIsReplying(false);+ }}onReady={(handle) => {replyInputHandle = handle;}}@@ -503,6 +506,9 @@ function DiscussionMessageView(props: {onClose={() => {props.onEditCancel();}}+ onEscape={() => {+ props.onEditCancel();+ }}/></Show></Message.Slot>diff --git a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsxindex c123908972..cf1fcd8115 100644--- a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx+++ b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx@@ -22,6 +22,7 @@ import { addMediaFromFile } from '@core/component/LexicalMarkdown/plugins/media'import { singleLineMarkdownTheme } from '@core/component/LexicalMarkdown/theme';import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';import { toast } from '@core/component/Toast/Toast';+import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';import { isMobile } from '@core/mobile/isMobile';import { isTouchDevice } from '@core/mobile/isTouchDevice';import type { IUser } from '@core/user/types';@@ -52,6 +53,8 @@ export type DiscussionInputProps = InputCallbacks & {collapsible?: boolean;/** Blur and collapse after onSend completes; other inputs retain focus. */blurOnSend?: boolean;+ /** Dismiss the host after Escape has closed inline menus. */+ onEscape?: () => void;};function AttachImagesAction() {@@ -271,6 +274,21 @@ export function DiscussionInput(props: DiscussionInputProps) {},});+ const [attach, scopeId] = useHotkeyDOMScope('discussion-input-intercept');+ registerHotkey({+ scopeId,+ description: 'block escape from moving up scope',+ hotkey: ['escape'],+ runWithInputFocused: true,+ hide: true,+ keyDownHandler: () => {+ if (markdownEditor.controls.isInlineMenuOpen()) return true;+ if (!props.onEscape) return false;+ props.onEscape();+ return true;+ },+ });+return (<Input.Root input={inputView()} commands={commands}><Show when={isCollapsed()}>@@ -343,6 +361,7 @@ export function DiscussionInput(props: DiscussionInputProps) {initialValue={inputView().value}autofocus={!isMobile() && (props.autofocus ?? true)}class="text-base"+ refFn={attach}/></Input.Editor></Input.Layout.Editor>diff --git a/apps/web/src/lib/core/messages/MessageThread.test.tsx b/apps/web/src/lib/core/messages/MessageThread.test.tsxindex a7f9de6367..dbe35984a3 100644--- a/apps/web/src/lib/core/messages/MessageThread.test.tsx+++ b/apps/web/src/lib/core/messages/MessageThread.test.tsx@@ -23,13 +23,28 @@ vi.mock('@core/component/Toast/Toast', () => ({}));vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => true }));vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));+const hotkeyMocks = vi.hoisted(() => ({+ registrations: [] as Array<{+ hotkey?: string | string[];+ condition?: () => boolean;+ keyDownHandler?: (event?: KeyboardEvent) => boolean;+ }>,+}));vi.mock('@core/hotkey/hotkeys', () => ({useHotkeyDOMScope: () => [() => {}, 'scope'],+ registerHotkey: (options: (typeof hotkeyMocks.registrations)[number]) => {+ hotkeyMocks.registrations.push(options);+ return {+ dispose: () => {},+ hotkey: () => undefined,+ withGroup: () => ({ dispose: () => {}, hotkey: () => undefined }),+ };+ },}));vi.mock('@channel/Channel/create-message-editor', () => ({createMessageEditor: (options: unknown) => {mocks.editor(options);- return { start: mocks.edit };+ return { start: mocks.edit, state: () => undefined };},}));vi.mock('@channel/Channel/create-delete-message-confirmation', () => ({@@ -117,6 +132,7 @@ vi.mock('@channel/Mobile/ActionDrawer', () => ({afterEach(() => {cleanup();vi.clearAllMocks();+ hotkeyMocks.registrations.length = 0;});const message: MessageListItem = {@@ -219,6 +235,19 @@ describe('document discussion controls', () => {view.queryByRole('button', { name: 'Delete discussion' })).toBeNull();});++ it('opens a reply when Enter is pressed on an active comment bubble', () => {+ const view = render(() => (+ <MessageThread data={message} canWrite keyboardActive />+ ));+ expect(view.queryByRole('textbox', { name: 'Reply composer' })).toBeNull();+ const enter = hotkeyMocks.registrations.find(+ (registration) => registration.hotkey === 'enter'+ );+ expect(enter?.condition?.()).toBe(true);+ expect(enter?.keyDownHandler?.()).toBe(true);+ expect(view.getByRole('textbox', { name: 'Reply composer' })).toBeTruthy();+ });});it('offers a durable copy link without write actions for saved call chat', () => {diff --git a/apps/web/src/lib/core/messages/MessageThread.tsx b/apps/web/src/lib/core/messages/MessageThread.tsxindex fdb3259ff9..aaff504c4b 100644--- a/apps/web/src/lib/core/messages/MessageThread.tsx+++ b/apps/web/src/lib/core/messages/MessageThread.tsx@@ -7,7 +7,7 @@ import { ChannelThread } from '@channel/Thread/ChannelThread';import { createFocusRequest } from '@channel/Thread/focus-request';import { buildMessageLink } from '@channel/Thread/utils/message-actions';import { useUserId } from '@core/context/user';-import { useHotkeyDOMScope } from '@core/hotkey/hotkeys';+import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';import { fireAndForget } from '@core/util/fireAndForget';import {useDeleteMessageMutation,@@ -23,7 +23,7 @@ import type {MessageParent,MessageThread as ThreadData,} from '@service-storage/messages';-import { createSignal, Show } from 'solid-js';+import { createEffect, createSignal, Show } from 'solid-js';import type { MessageActionHandler, MessageData } from './types';export function threadListItem(thread: ThreadData): MessageListItem {@@ -56,6 +56,11 @@ type ThreadOptions = {hideRail?: boolean;onEditingChange?: (id: string, editing: boolean) => void;monorail?: boolean;+ /**+ * Document comment bubble is the focused surface: Enter opens a reply+ * (same as chat on a selected message) and the thread accepts keyboard focus.+ */+ keyboardActive?: boolean;};/** Document and source-channel threads compose the existing channel thread and message controls. */@@ -68,6 +73,7 @@ export function MessageThread(const [draft, setDraft] = createSignal<InputSnapshot>();const [handle, setHandle] = createSignal<InputHandle>();const [attachScope, scopeId] = useHotkeyDOMScope('message-thread');+ let scopeElement: HTMLDivElement | undefined;const focus = createFocusRequest();const remove = useDeleteMessageMutation();const confirm = createDeleteMessageConfirmation(remove.mutate);@@ -79,6 +85,18 @@ export function MessageThread(patchMessage: patch.mutate,onEditEnded: (message) => props.onEditingChange?.(message.id, false),});+ const startReply = () => {+ if (props.onReply) {+ fireAndForget(+ Promise.resolve(props.onReply({ message: props.data })),+ 'message-thread'+ );+ return;+ }+ setExpanded(true);+ setReplying(true);+ focus.request();+ };const actions = createChannelMessageActions({parent: () => props.data.parent,userId,@@ -102,12 +120,42 @@ export function MessageThread(focus.request();},});+ // Comment bubbles are not channel-selected messages; take Enter here instead.+ registerHotkey({+ scopeId,+ hotkey: 'enter',+ description: 'Reply to comment',+ condition: () =>+ !!props.keyboardActive &&+ props.canWrite &&+ !props.hideReplyInput &&+ !replying() &&+ !editor.state(),+ keyDownHandler: (event) => {+ if (event?.repeat) return true;+ startReply();+ return true;+ },+ });+ // Keep the bubble in the hotkey DOM scope while it is the active comment.+ createEffect(() => {+ if (!props.keyboardActive) return;+ if (replying() || editor.state()) return;+ const el = scopeElement;+ if (!el) return;+ if (el.contains(document.activeElement)) return;+ el.focus({ preventScroll: true });+ });return (<MaybeMessageActionDrawerManager><div- ref={attachScope}+ ref={(el) => {+ scopeElement = el;+ attachScope(el);+ }}data-message-thread={props.data.id}- class="relative isolate"+ tabindex={props.keyboardActive ? -1 : undefined}+ class="relative isolate outline-none"><confirm.ConfirmationDialog /><ChannelThreaddiff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex 69c2ffa191..9d969c8f10 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -2585,8 +2585,10 @@ and inline input.Comments anchored to selected text open in a floating margin card on desktop anda `Comments` drawer on touch devices. Hovering a desktop card reveals its actionswithout changing the card size or header text wrapping. New comments, replies,-and edits use plain inputs on the card or drawer's background. The pinned reply-keeps at least 16px of+and edits use plain inputs on the card or drawer's background. On desktop, with+the margin card focused: Enter opens a reply (same as the Reply action; Enter in+the composer then sends), and Escape closes the reply composer, then the card.+The pinned reply keeps at least 16px ofbottom clearance above the drawer's curve, including while the keyboard is open,and accounts for the home-indicator safe area when the keyboard is closed.