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(channels): enter on edit don't make new reply (#5523)
teo940a20577747
diff --git a/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts b/apps/web/src/features/channel/Channel/create-channel-hotkeys.tsindex fffe847b6b..d4de361026 100644--- a/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts+++ b/apps/web/src/features/channel/Channel/create-channel-hotkeys.ts@@ -115,7 +115,11 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {hotkeyToken: TOKENS.channel.replyToMessage,description: 'Reply to message',condition: canRunSelectionActionHotkeys,- keyDownHandler: () => {+ keyDownHandler: (event) => {+ // Saving an inline edit returns focus to the selected message before+ // Enter is released. Capture browser key-repeat events so that same+ // physical press cannot immediately open the reply input.+ if (event?.repeat) return true;const msg = getSelectedMessage();if (!msg) return false;const actions = options.getMessageActions(msg);diff --git a/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx b/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsxnew file mode 100644index 0000000000..bd3a35d6cd--- /dev/null+++ b/apps/web/src/features/channel/Channel/tests/create-channel-hotkeys.test.tsx@@ -0,0 +1,139 @@+import {+ attachGlobalDOMScope,+ useHotKeyRoot,+ useHotkeyDOMScope,+} from '@core/hotkey/hotkeys';+import type { ApiChannelMessage } from '@service-storage/generated/schemas/apiChannelMessage';+import { fireEvent, render, screen } from '@solidjs/testing-library';+import { createSignal, onMount, Show } from 'solid-js';+import { describe, expect, it, vi } from 'vitest';+import type { MessageData } from '../../Message';+import { createChannelHotkeys } from '../create-channel-hotkeys';++const originalMessage: MessageData = {+ id: 'message-1',+ content: 'before edit',+ sender_id: 'user-1',+ created_at: '2026-08-07T00:00:00.000Z',+ updated_at: '2026-08-07T00:00:00.000Z',+ attachments: [],+ reactions: [],+};++function TestMessageEditor(props: { onSave: () => void }) {+ const [attachEditorHotkeys] = useHotkeyDOMScope('message-editor');+ let editor!: HTMLDivElement;++ onMount(() => editor.focus());++ return (+ <div+ ref={(element) => {+ editor = element;+ attachEditorHotkeys(element);+ }}+ contenteditable+ data-testid="message-editor"+ onKeyDown={(event) => {+ if (event.key === 'Enter') props.onSave();+ }}+ />+ );+}++function ChannelEditHarness(props: {+ onSave: ReturnType<typeof vi.fn>;+ onReply: ReturnType<typeof vi.fn>;+}) {+ useHotKeyRoot();++ const [isEditing, setIsEditing] = createSignal(false);++ const { attachMessageListRef } = createChannelHotkeys({+ selection: {+ selectedId: () => originalMessage.id,+ select: vi.fn(),+ clear: vi.fn(),+ selectFirst: vi.fn(),+ selectPrevious: vi.fn(),+ selectNext: vi.fn(),+ },+ navigation: () => undefined,+ messageById: () =>+ new Map([[originalMessage.id, originalMessage as ApiChannelMessage]]),+ getMessageActions: () => ({+ onEdit: () => {+ setIsEditing(true);+ },+ onReply: props.onReply,+ }),+ userId: () => 'user-1',+ isInputEmpty: () => true,+ isEditing,+ onOpenFindBar: vi.fn(),+ onGoToBottom: vi.fn(),+ });++ return (+ <div ref={attachGlobalDOMScope}>+ <div ref={attachMessageListRef} tabIndex={-1} data-testid="message-list">+ <Show when={isEditing()}>+ <TestMessageEditor+ onSave={() => {+ props.onSave();+ setIsEditing(false);+ }}+ />+ </Show>+ </div>+ </div>+ );+}++describe('createChannelHotkeys', () => {+ it('does not turn the Enter that saves an edit into a reply', () => {+ const onSave = vi.fn();+ const onReply = vi.fn();+ render(() => <ChannelEditHarness onSave={onSave} onReply={onReply} />);++ const messageList = screen.getByTestId('message-list');+ messageList.focus();++ fireEvent.keyDown(messageList, { key: 'e' });+ const editor = screen.getByTestId('message-editor');+ expect(document.activeElement).toBe(editor);++ fireEvent.keyDown(editor, { key: 'Enter' });+ expect(onSave).toHaveBeenCalledOnce();+ expect(screen.queryByTestId('message-editor')).toBeNull();+ expect(document.activeElement).toBe(messageList);++ fireEvent.keyDown(messageList, { key: 'Enter', repeat: true });+ expect(onReply).not.toHaveBeenCalled();+ });++ it('does not turn a straggler keyup after saving an edit into a reply', () => {+ const onSave = vi.fn();+ const onReply = vi.fn();+ render(() => <ChannelEditHarness onSave={onSave} onReply={onReply} />);++ const messageList = screen.getByTestId('message-list');+ messageList.focus();++ fireEvent.keyDown(messageList, { key: 'e' });+ const editor = screen.getByTestId('message-editor');+ expect(document.activeElement).toBe(editor);++ // Fast typing rolls over: Enter goes down before the last typed letter+ // is released, so the letter's keyup lands after the editor closed and+ // focus returned to the message list — with 'enter' still pressed.+ fireEvent.keyDown(editor, { key: 'd' });+ fireEvent.keyDown(editor, { key: 'Enter' });+ expect(onSave).toHaveBeenCalledOnce();+ expect(document.activeElement).toBe(messageList);++ fireEvent.keyUp(messageList, { key: 'd' });+ fireEvent.keyUp(messageList, { key: 'Enter' });+ expect(onReply).not.toHaveBeenCalled();+ });+});diff --git a/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts b/apps/web/src/features/channel/Thread/create-thread-hotkeys.tsindex a8fb60f401..1c5b19401b 100644--- a/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts+++ b/apps/web/src/features/channel/Thread/create-thread-hotkeys.ts@@ -173,7 +173,10 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {isThreadFocused: options.isThreadFocused(),isEditing: options.isEditing(),}),- keyDownHandler: () => {+ keyDownHandler: (event) => {+ // Saving an inline edit returns focus to the thread before Enter is+ // released. Consume browser key-repeat events without opening a reply.+ if (event?.repeat) return true;const parentMsg = options.parentMessage();const actions = options.getMessageActions(parentMsg);actions?.onReply?.({ message: parentMsg });diff --git a/apps/web/src/lib/core/hotkey/utils.ts b/apps/web/src/lib/core/hotkey/utils.tsindex 975cdd7c7d..7896371161 100644--- a/apps/web/src/lib/core/hotkey/utils.ts+++ b/apps/web/src/lib/core/hotkey/utils.ts@@ -444,6 +444,14 @@ export function runCommand(let commandScopeActivated = false;let stopPropagation = false;+ // Key-rollover keyups re-match commands for the keys still held (e.g. the+ // Enter that saved a message edit), so only keydown events — or programmatic+ // calls without an event — may run keydown handlers or activate scopes.+ // keyUpHandlers run through hotkeysAwaitingKeyUp, not here.+ if (e?.type === 'keyup') {+ return { commandCaptured, commandScopeActivated, stopPropagation };+ }+if (!command.condition || command.condition()) {if (command.activateCommandScopeId) {const commandScope = hotkeyScopeTree.get(command.activateCommandScopeId);diff --git a/apps/web/tests/e2e/local-channel-edit.spec.ts b/apps/web/tests/e2e/local-channel-edit.spec.tsnew file mode 100644index 0000000000..dc73d28028--- /dev/null+++ b/apps/web/tests/e2e/local-channel-edit.spec.ts@@ -0,0 +1,132 @@+import { expect, type Locator, type Page, test } from '@playwright/test';++import { localE2ESeed } from './fixtures/local-e2e-seed';+import {+ fillEditable,+ gotoApp,+ LOCAL_E2E,+ uniqueE2EText,+} from './helpers/local-app';++test.skip(+ !LOCAL_E2E,+ 'local channel edit tests require LOCAL_E2E=true and seeded local data'+);++test.describe('local channel message edit hotkeys', () => {+ test.describe.configure({ timeout: 60_000 });++ test('saving an edit with Enter does not open the reply input', async ({+ page,+ }) => {+ const messageId = await startInlineEditOfOwnMessage(+ page,+ uniqueE2EText('edit enter plain')+ );++ await page.keyboard.press('Enter');++ await expectEditSavedWithoutReplyInput(page, messageId);+ });++ test('saving an edit with a rolled-over Enter does not open the reply input', async ({+ page,+ }) => {+ const messageId = await startInlineEditOfOwnMessage(+ page,+ uniqueE2EText('edit enter rollover')+ );++ // Fast typing rolls keys over: Enter goes down before the last typed+ // letter is released, so the letter's keyup lands after the editor has+ // closed and focus has returned to the message list.+ await page.keyboard.down('d');+ await page.keyboard.down('Enter');+ await page.keyboard.up('d');+ await page.keyboard.up('Enter');++ await expectEditSavedWithoutReplyInput(page, messageId);+ });+});++/**+ * Sends a fresh message, selects it with the keyboard (ArrowUp from the empty+ * channel input), and opens the inline editor with the `e` hotkey. Returns+ * the message id.+ */+async function startInlineEditOfOwnMessage(+ page: Page,+ messageText: string+): Promise<string> {+ const channel = localE2ESeed.smoke.generalChannel;+ const channelId = channel.channel_id;++ await openSeededChannel(page, channelId);+ const message = await sendChannelMessage(page, channelId, messageText);+ const messageId = await message.getAttribute('data-message-id');+ expect(messageId).toBeTruthy();++ await page.keyboard.press('ArrowUp');+ await page.keyboard.press('e');++ const editor = page+ .locator(`[data-input-id="edit-message-input-${messageId}"]`)+ .locator('[contenteditable="true"]')+ .first();+ await expect(editor).toBeVisible({ timeout: 10_000 });+ await expect(editor).toBeFocused({ timeout: 10_000 });++ return messageId as string;+}++async function expectEditSavedWithoutReplyInput(page: Page, messageId: string) {+ await expect(+ page.locator(`[data-input-id="edit-message-input-${messageId}"]`)+ ).toHaveCount(0, { timeout: 10_000 });++ // The straggler keyup (or a key repeat) fires synchronously after the+ // editor closes; give the reply input a beat to appear before asserting+ // that it did not.+ await page.waitForTimeout(500);+ await expect(+ page.locator(`[data-input-id="thread-reply-input-${messageId}"]`)+ ).toHaveCount(0);+}++async function openSeededChannel(page: Page, channelId: string) {+ const channelName =+ localE2ESeed.smoke.generalChannel.channel_name ?? 'general';++ await gotoApp(page, `/channel/${channelId}`);+ await expect(+ page.getByText(channelName, { exact: true }).first()+ ).toBeVisible({ timeout: 30_000 });+ await expect(page.locator('[data-channel-message-list]')).toBeVisible({+ timeout: 30_000,+ });+}++async function sendChannelMessage(+ page: Page,+ channelId: string,+ text: string+): Promise<Locator> {+ const input = page.locator(`[data-input-id="channel-input-${channelId}"]`);+ const editable = input.locator('[contenteditable="true"]').first();+ await fillEditable(editable, text);++ const sendButton = input.locator('[data-input-action="send"]');+ await expect(sendButton).toBeEnabled({ timeout: 10_000 });+ await sendButton.click();++ const message = page+ .locator('[data-message]')+ .filter({ hasText: text })+ .last();+ await expect(message).toBeVisible({ timeout: 30_000 });++ // Keyboard selection starts from the channel input; clicking Send moved+ // focus to the button, so return it to the input first.+ await editable.click();+ return message;+}