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(new-channels): prevent enter reply hotkey from triggering while editing (#2101)
teo39c4c2033e58
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex ef02ea93b0..86efc47a3e 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -196,6 +196,7 @@ export function Channel(props: ChannelProps) {messageById,getMessageActions,userId,+ isEditing: () => !!messageEditor.state(),isInputEmpty: () =>(channelInputSnapshot()?.value.trim().length ?? 0) === 0,});diff --git a/js/app/packages/channel/Channel/create-channel-hotkeys.ts b/js/app/packages/channel/Channel/create-channel-hotkeys.tsindex 55ddff9d95..f8d2184e8c 100644--- a/js/app/packages/channel/Channel/create-channel-hotkeys.ts+++ b/js/app/packages/channel/Channel/create-channel-hotkeys.ts@@ -14,8 +14,24 @@ type CreateChannelHotkeysOptions = {getMessageActions: (message: MessageData) => MessageActions | undefined;userId: Accessor<string | undefined>;isInputEmpty: Accessor<boolean>;+ isEditing: Accessor<boolean>;};+export function canReplyToSelectedMessageFromHotkey(input: {+ hasSelection: boolean;+ isEditing: boolean;+}) {+ return input.hasSelection && !input.isEditing;+}++export function canEditSelectedMessageFromHotkey(input: {+ hasSelection: boolean;+ isEditing: boolean;+ isOwnMessage: boolean;+}) {+ return canReplyToSelectedMessageFromHotkey(input) && input.isOwnMessage;+}+export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {const [attachMessageList, messageListScope] =useHotkeyDOMScope('channel-messages');@@ -31,6 +47,11 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {});const hasSelection = () => !!options.selection.selectedId();+ const canRunSelectionActionHotkeys = () =>+ canReplyToSelectedMessageFromHotkey({+ hasSelection: hasSelection(),+ isEditing: options.isEditing(),+ });const getSelectedMessage = () => {const id = options.selection.selectedId();@@ -86,7 +107,7 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {hotkey: 'enter',hotkeyToken: TOKENS.channel.replyToMessage,description: 'Reply to message',- condition: hasSelection,+ condition: canRunSelectionActionHotkeys,keyDownHandler: () => {const msg = getSelectedMessage();if (!msg) return false;@@ -102,9 +123,13 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {hotkeyToken: TOKENS.channel.editMessage,description: 'Edit message',condition: () => {- if (!hasSelection()) return false;+ if (!canRunSelectionActionHotkeys()) return false;const msg = getSelectedMessage();- return !!msg && msg.sender_id === options.userId();+ return canEditSelectedMessageFromHotkey({+ hasSelection: true,+ isEditing: options.isEditing(),+ isOwnMessage: !!msg && msg.sender_id === options.userId(),+ });},keyDownHandler: () => {const msg = getSelectedMessage();diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsxindex 1b64001f99..dbb4c0a8dc 100644--- a/js/app/packages/channel/Thread/ChannelThread.tsx+++ b/js/app/packages/channel/Thread/ChannelThread.tsx@@ -78,6 +78,7 @@ export function ChannelThread(props: ThreadProps) {messageListScopeId: props.messageListScopeId!,replySelection,isThreadFocused,+ isEditing: () => !!props.messageEditor?.state(),activeReplies,threadId: () => props.data().id,getMessageActions: (msg) => props.getMessageActions?.(msg),diff --git a/js/app/packages/channel/Thread/create-thread-hotkeys.ts b/js/app/packages/channel/Thread/create-thread-hotkeys.tsindex 0034badcd3..6b9b81370b 100644--- a/js/app/packages/channel/Thread/create-thread-hotkeys.ts+++ b/js/app/packages/channel/Thread/create-thread-hotkeys.ts@@ -14,6 +14,7 @@ type CreateThreadHotkeysOptions = {messageListScopeId: string;replySelection: MessageSelection;isThreadFocused: Accessor<boolean>;+ isEditing: Accessor<boolean>;activeReplies: Accessor<Array<ApiThreadReply>>;threadId: Accessor<string>;getMessageActions: (message: MessageData) => MessageActions | undefined;@@ -27,6 +28,26 @@ type CreateThreadHotkeysOptions = {setIsReplying: (replying: boolean) => void;};+export function canReplyToThreadFromHotkey(input: {+ isThreadFocused: boolean;+ isEditing: boolean;+}) {+ return input.isThreadFocused && !input.isEditing;+}++export function canEditThreadReplyFromHotkey(input: {+ isThreadFocused: boolean;+ isEditing: boolean;+ hasSelectedReply: boolean;+ isOwnReply: boolean;+}) {+ return (+ canReplyToThreadFromHotkey(input) &&+ input.hasSelectedReply &&+ input.isOwnReply+ );+}+function scrollReplyIntoView(replyId: string) {document.querySelector<HTMLElement>(`[data-message-id="${replyId}"]`)@@ -136,7 +157,11 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {description: 'Reply to thread',registrationType: 'add',handlerPriority: HOTKEY_PRIORITY_HIGH,- condition: options.isThreadFocused,+ condition: () =>+ canReplyToThreadFromHotkey({+ isThreadFocused: options.isThreadFocused(),+ isEditing: options.isEditing(),+ }),keyDownHandler: () => {const parentMsg = options.parentMessage();const actions = options.getMessageActions(parentMsg);@@ -153,11 +178,16 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {registrationType: 'add',handlerPriority: HOTKEY_PRIORITY_HIGH,condition: () => {- if (!options.isThreadFocused()) return false;+ if (options.isEditing()) return false;const replyId = options.replySelection.selectedId();if (!replyId) return false;const reply = getReplyById(replyId);- return !!reply && reply.sender_id === options.userId();+ return canEditThreadReplyFromHotkey({+ isThreadFocused: options.isThreadFocused(),+ isEditing: options.isEditing(),+ hasSelectedReply: !!replyId,+ isOwnReply: !!reply && reply.sender_id === options.userId(),+ });},keyDownHandler: () => {const replyId = options.replySelection.selectedId();