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.

feat(new-channels): add backspace hotkey for delete + fix full width edit message input (#2102)

teoe9dea0819e67
diff --git a/js/app/packages/channel/Channel/InlineMessageEditor.tsx b/js/app/packages/channel/Channel/InlineMessageEditor.tsx
index e35e73e5f2..16c3fbb443 100644
--- a/js/app/packages/channel/Channel/InlineMessageEditor.tsx
+++ b/js/app/packages/channel/Channel/InlineMessageEditor.tsx
@@ -3,10 +3,12 @@ import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
import type { MessageEditor } from './create-message-editor';
import { useMessage } from '../Message';
+import { cn } from '@ui/utils/classname';
type MessageEditorContentProps = {
channelId: string;
messageEditor: MessageEditor;
+ class?: string;
};
export function MessageEditorContent(props: MessageEditorContentProps) {
@@ -31,7 +33,7 @@ export function MessageEditorContent(props: MessageEditorContentProps) {
});
return (
- <div ref={attachHotkeys}>
+ <div ref={attachHotkeys} class={cn('w-full min-w-0', props.class)}>
<ChannelInput
input={{
mode: 'channel',
diff --git a/js/app/packages/channel/Channel/create-channel-hotkeys.ts b/js/app/packages/channel/Channel/create-channel-hotkeys.ts
index f8d2184e8c..1f4de95f33 100644
--- a/js/app/packages/channel/Channel/create-channel-hotkeys.ts
+++ b/js/app/packages/channel/Channel/create-channel-hotkeys.ts
@@ -24,7 +24,7 @@ export function canReplyToSelectedMessageFromHotkey(input: {
return input.hasSelection && !input.isEditing;
}
-export function canEditSelectedMessageFromHotkey(input: {
+export function canEditOrDeleteSelectedMessageFromHotkey(input: {
hasSelection: boolean;
isEditing: boolean;
isOwnMessage: boolean;
@@ -125,7 +125,7 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {
condition: () => {
if (!canRunSelectionActionHotkeys()) return false;
const msg = getSelectedMessage();
- return canEditSelectedMessageFromHotkey({
+ return canEditOrDeleteSelectedMessageFromHotkey({
hasSelection: true,
isEditing: options.isEditing(),
isOwnMessage: !!msg && msg.sender_id === options.userId(),
@@ -140,6 +140,29 @@ export function createChannelHotkeys(options: CreateChannelHotkeysOptions) {
},
});
+ registerHotkey({
+ scopeId: messageListScope,
+ hotkey: 'backspace',
+ hotkeyToken: TOKENS.channel.deleteMessage,
+ description: 'Delete message',
+ condition: () => {
+ if (!canRunSelectionActionHotkeys()) return false;
+ const msg = getSelectedMessage();
+ return canEditOrDeleteSelectedMessageFromHotkey({
+ hasSelection: true,
+ isEditing: options.isEditing(),
+ isOwnMessage: !!msg && msg.sender_id === options.userId(),
+ });
+ },
+ keyDownHandler: () => {
+ const msg = getSelectedMessage();
+ if (!msg) return false;
+ const actions = options.getMessageActions(msg);
+ actions?.onDelete?.({ message: msg });
+ return true;
+ },
+ });
+
registerHotkey({
scopeId: messageListScope,
hotkey: 'escape',
diff --git a/js/app/packages/channel/Message/ChannelMessage.tsx b/js/app/packages/channel/Message/ChannelMessage.tsx
index 5fc7f209d6..4ad0f75c8b 100644
--- a/js/app/packages/channel/Message/ChannelMessage.tsx
+++ b/js/app/packages/channel/Message/ChannelMessage.tsx
@@ -39,6 +39,7 @@ function MessageContentSlot(props: {
<MessageEditorContent
channelId={props.channelId}
messageEditor={messageEditor()}
+ class={props.class}
/>
)}
</Match>
diff --git a/js/app/packages/channel/Thread/create-thread-hotkeys.ts b/js/app/packages/channel/Thread/create-thread-hotkeys.ts
index 6b9b81370b..8f81b4d611 100644
--- a/js/app/packages/channel/Thread/create-thread-hotkeys.ts
+++ b/js/app/packages/channel/Thread/create-thread-hotkeys.ts
@@ -35,7 +35,7 @@ export function canReplyToThreadFromHotkey(input: {
return input.isThreadFocused && !input.isEditing;
}
-export function canEditThreadReplyFromHotkey(input: {
+export function canEditOrDeleteThreadReplyFromHotkey(input: {
isThreadFocused: boolean;
isEditing: boolean;
hasSelectedReply: boolean;
@@ -182,7 +182,7 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {
const replyId = options.replySelection.selectedId();
if (!replyId) return false;
const reply = getReplyById(replyId);
- return canEditThreadReplyFromHotkey({
+ return canEditOrDeleteThreadReplyFromHotkey({
isThreadFocused: options.isThreadFocused(),
isEditing: options.isEditing(),
hasSelectedReply: !!replyId,
@@ -200,6 +200,36 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {
},
}).withGroup(group);
+ registerHotkey({
+ scopeId: scope,
+ hotkey: 'backspace',
+ hotkeyToken: TOKENS.channel.threadDeleteReply,
+ description: 'Delete reply',
+ registrationType: 'add',
+ handlerPriority: HOTKEY_PRIORITY_HIGH,
+ condition: () => {
+ if (options.isEditing()) return false;
+ const replyId = options.replySelection.selectedId();
+ if (!replyId) return false;
+ const reply = getReplyById(replyId);
+ return canEditOrDeleteThreadReplyFromHotkey({
+ isThreadFocused: options.isThreadFocused(),
+ isEditing: options.isEditing(),
+ hasSelectedReply: !!replyId,
+ isOwnReply: !!reply && reply.sender_id === options.userId(),
+ });
+ },
+ keyDownHandler: () => {
+ const replyId = options.replySelection.selectedId();
+ if (!replyId) return false;
+ const reply = getReplyById(replyId);
+ if (!reply) return false;
+ const actions = options.getMessageActions(reply);
+ actions?.onDelete?.({ message: reply });
+ return true;
+ },
+ }).withGroup(group);
+
const [attachReplyInputRef, replyInputScope] = useHotkeyDOMScope(
'channel-reply-input'
);
diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.ts
index 12cec1da3b..d68cb4c1e4 100644
--- a/js/app/packages/core/hotkey/tokens.ts
+++ b/js/app/packages/core/hotkey/tokens.ts
@@ -206,6 +206,7 @@ export const TOKENS = {
moveUp: 'channel.moveUp',
moveDown: 'channel.moveDown',
editMessage: 'channel.editMessage',
+ deleteMessage: 'channel.deleteMessage',
replyToMessage: 'channel.replyToMessage',
expandThread: 'channel.expandThread',
collapseThread: 'channel.collapseThread',
@@ -221,6 +222,7 @@ export const TOKENS = {
threadCollapse: 'channel.threadCollapse',
threadReply: 'channel.threadReply',
threadEditReply: 'channel.threadEditReply',
+ threadDeleteReply: 'channel.threadDeleteReply',
},
// drawer