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(email): Email compose shortcuts (#732)

dev-rb5c65dad4f269
diff --git a/js/app/packages/app/component/command/KonsoleItem.tsx b/js/app/packages/app/component/command/KonsoleItem.tsx
index be01fbe446..5a02df2e22 100644
--- a/js/app/packages/app/component/command/KonsoleItem.tsx
+++ b/js/app/packages/app/component/command/KonsoleItem.tsx
@@ -403,7 +403,7 @@ export function useCommandItemAction(args: {
setCommandScopeCommands(commandScopeCommands);
break;
} else {
- setKonsoleOpen(false);
+ setKonsoleOpen(false, item.data.command.shouldReturnFocusOnClose);
resetQuery();
resetKonsoleMode();
runCommand(item.data.command);
diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsx
index e9d9c21cb7..6ac0b9f65c 100644
--- a/js/app/packages/block-email/component/Compose.tsx
+++ b/js/app/packages/block-email/component/Compose.tsx
@@ -12,6 +12,8 @@ import { TextButton } from '@core/component/TextButton';
import { toast } from '@core/component/Toast/Toast';
import { usePaywallState } from '@core/constant/PaywallState';
import { useEmailLinks } from '@core/email-link';
+import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
import {
type ContactInfo,
@@ -25,6 +27,7 @@ import {
createMemo,
createSignal,
Match,
+ onMount,
Show,
Suspense,
Switch,
@@ -45,6 +48,15 @@ class EmailComposeError {
) {}
}
+type EmailComposeElementRefs = {
+ directRecipientsSelector: HTMLElement | undefined;
+ ccRecipientsSelector: HTMLElement | undefined;
+ bccRecipientsSelector: HTMLElement | undefined;
+ containerRef: HTMLElement | undefined;
+ subjectInput: HTMLElement | undefined;
+ messageInput: HTMLElement | undefined;
+};
+
export function EmailCompose() {
const hasPaidAccess = useHasPaidAccess();
const { showPaywall } = usePaywallState();
@@ -53,6 +65,24 @@ export function EmailCompose() {
const emailLinksQuery = useEmailLinksQuery();
+ const [refs, setRefs] = createSignal<EmailComposeElementRefs>({
+ directRecipientsSelector: undefined,
+ ccRecipientsSelector: undefined,
+ bccRecipientsSelector: undefined,
+ containerRef: undefined,
+ subjectInput: undefined,
+ messageInput: undefined,
+ });
+
+ const registerRef = (name: keyof EmailComposeElementRefs) => {
+ return (el: HTMLElement) => {
+ setRefs((p) => ({ ...p, [name]: el }));
+ };
+ };
+
+ const [attachComposeHotkeys, composeHotkeyScope] =
+ useHotkeyDOMScope('compose-email');
+
const link = createMemo(() => {
const data = emailLinksQuery.data;
if (data && data.links.length > 0) {
@@ -83,6 +113,93 @@ export function EmailCompose() {
const [showCc, setShowCc] = createSignal(false);
const [showBcc, setShowBcc] = createSignal(false);
+ onMount(() => {
+ const container = refs().containerRef;
+ if (!container) return;
+ attachComposeHotkeys(container);
+ });
+
+ registerHotkey({
+ hotkey: 'shift+cmd+o',
+ scopeId: composeHotkeyScope,
+ description: 'Edit "To" recipients',
+ keyDownHandler: () => {
+ refs()?.directRecipientsSelector?.focus();
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.recipients,
+ shouldReturnFocusOnClose: false,
+ });
+
+ registerHotkey({
+ hotkey: 'shift+cmd+c',
+ scopeId: composeHotkeyScope,
+ description: 'Edit "Cc" recipients',
+ keyDownHandler: () => {
+ const visible = showCc();
+ if (!visible) {
+ setShowCc(true);
+ queueMicrotask(() => refs()?.ccRecipientsSelector?.focus());
+ return true;
+ }
+
+ refs()?.ccRecipientsSelector?.focus();
+
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.ccRecipients,
+ shouldReturnFocusOnClose: false,
+ });
+
+ registerHotkey({
+ hotkey: 'shift+cmd+b',
+ scopeId: composeHotkeyScope,
+ description: 'Edit "Bcc" recipients',
+ keyDownHandler: () => {
+ const visible = showBcc();
+ if (!visible) {
+ setShowBcc(true);
+ queueMicrotask(() => refs()?.bccRecipientsSelector?.focus());
+ return true;
+ }
+
+ refs()?.bccRecipientsSelector?.focus();
+
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.bccRecipients,
+ shouldReturnFocusOnClose: false,
+ });
+
+ registerHotkey({
+ hotkey: 'shift+cmd+s',
+ scopeId: composeHotkeyScope,
+ description: 'Edit subject',
+ keyDownHandler: () => {
+ refs()?.subjectInput?.focus();
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.subject,
+ shouldReturnFocusOnClose: false,
+ });
+
+ registerHotkey({
+ hotkey: 'shift+cmd+m',
+ scopeId: composeHotkeyScope,
+ description: 'Edit message',
+ keyDownHandler: () => {
+ refs()?.messageInput?.focus();
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.message,
+ shouldReturnFocusOnClose: false,
+ });
+
const [triedToSubmit, _setTriedToSubmit] = createSignal(false);
const { connect: connectEmail } = useEmailLinks();
@@ -207,7 +324,10 @@ export function EmailCompose() {
]}
/>
</SplitHeaderLeft>
- <div class="relative flex flex-col w-full h-full panel min-h-0 overflow-hidden">
+ <div
+ ref={registerRef('containerRef')}
+ class="relative flex flex-col w-full h-full panel min-h-0 overflow-hidden"
+ >
<Switch>
<Match when={hasLinkError()}>
<div class="w-full bg-alert-bg border-b border-t border-alert/20 text-alert-ink p-2">
@@ -307,6 +427,7 @@ export function EmailCompose() {
</div>
<div class="flex-1">
<RecipientSelector<'user' | 'contact'>
+ inputRef={registerRef('directRecipientsSelector')}
options={destinationOptions}
selectedOptions={selectedRecipients}
setSelectedOptions={setSelectedRecipients}
@@ -334,6 +455,7 @@ export function EmailCompose() {
</div>
<div class="flex-1">
<RecipientSelector<'user' | 'contact'>
+ inputRef={registerRef('ccRecipientsSelector')}
options={destinationOptions}
selectedOptions={ccRecipients}
setSelectedOptions={setCcRecipients}
@@ -354,6 +476,7 @@ export function EmailCompose() {
</div>
<div class="flex-1">
<RecipientSelector<'user' | 'contact'>
+ inputRef={registerRef('bccRecipientsSelector')}
options={destinationOptions}
selectedOptions={bccRecipients}
setSelectedOptions={setBccRecipients}
@@ -374,6 +497,7 @@ export function EmailCompose() {
<div class="flex-1">
<input
+ ref={registerRef('subjectInput')}
type="text"
value={subject()}
placeholder="Subject"
@@ -403,6 +527,7 @@ export function EmailCompose() {
}}
>
<ComposeEmailInput
+ inputRef={registerRef('messageInput')}
onSubmit={onSubmit}
isSubmitting={sendMutation.isPending}
disabled={hasLinkError()}
diff --git a/js/app/packages/block-email/component/ComposeEmailInput.tsx b/js/app/packages/block-email/component/ComposeEmailInput.tsx
index 18cde8d997..6bb847dca2 100644
--- a/js/app/packages/block-email/component/ComposeEmailInput.tsx
+++ b/js/app/packages/block-email/component/ComposeEmailInput.tsx
@@ -50,6 +50,7 @@ export type ComposeInputData = {
};
type ComposeEmailInputProps = {
+ inputRef?: (el: HTMLDivElement) => void;
onSubmit: (data: ComposeInputData) => void;
disabled?: boolean;
isSubmitting?: boolean;
@@ -120,7 +121,9 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {
// Set up hotkey scope for the compose message component
const [attachComposeHotkeys, composeHotkeyScope] =
useHotkeyDOMScope('compose-message');
- let composeContainerRef: HTMLDivElement | undefined;
+ const [composeContainerRef, setComposeContainerRef] = createSignal<
+ HTMLElement | undefined
+ >();
async function handleSend() {
const currentEditor = editor();
@@ -150,29 +153,27 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {
}
onMount(() => {
- if (composeContainerRef) {
- attachComposeHotkeys(composeContainerRef);
+ const container = composeContainerRef();
+ if (!container) return;
+ attachComposeHotkeys(container);
+ });
- registerHotkey({
- hotkey: 'cmd+enter',
- scopeId: composeHotkeyScope,
- description: 'Send email',
- keyDownHandler: () => {
- handleSend();
- return true;
- },
- runWithInputFocused: true,
- hotkeyToken: 'email.send',
- displayPriority: 10,
- });
- }
+ registerHotkey({
+ hotkey: 'cmd+enter',
+ scopeId: composeHotkeyScope,
+ description: 'Send email',
+ keyDownHandler: () => {
+ handleSend();
+ return true;
+ },
+ runWithInputFocused: true,
+ hotkeyToken: 'email.send',
+ displayPriority: 10,
});
return (
<div
- ref={(el) => {
- composeContainerRef = el;
- }}
+ ref={setComposeContainerRef}
class="relative flex flex-col flex-1 items-center justify-between min-h-0"
>
<div class="w-full h-full flex flex-col min-h-0">
@@ -213,6 +214,7 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {
<FileDropOverlay>Drop file(s) to attach</FileDropOverlay>
</div>
<MarkdownTextarea
+ domRef={props.inputRef}
captureEditor={setEditor}
class="text-sm break-words text-ink"
editable={() => !props.disabled}
diff --git a/js/app/packages/core/component/RecipientSelector.tsx b/js/app/packages/core/component/RecipientSelector.tsx
index 1a0e1cb739..6a4b7c213f 100644
--- a/js/app/packages/core/component/RecipientSelector.tsx
+++ b/js/app/packages/core/component/RecipientSelector.tsx
@@ -214,7 +214,7 @@ type RecipientSelectorProps<K extends CombinedRecipientKind> = {
// If you provide triedToSubmit, the component will show an error message if no options are selected and triedToSubmit is true
triedToSubmit?: Accessor<boolean>;
placeholder?: string | JSX.Element;
- inputRef?: Setter<HTMLInputElement | undefined>;
+ inputRef?: (ref: HTMLInputElement) => void;
focusOnMount?: boolean;
triggerMode?: ComboboxTriggerMode;
hideBorder?: boolean;
@@ -260,15 +260,6 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
});
}
- if (props.inputRef) {
- createEffect(() => {
- const ref = inputRef();
- if (props.inputRef && ref) {
- props.inputRef(ref);
- }
- });
- }
-
function getOptionDisabled(option: CombinedRecipientItem): boolean {
if (option.kind === 'custom') {
return option.data.invalid;
@@ -525,8 +516,11 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
</For>
<Combobox.Input
disabled={disabled()}
- ref={setInputRef}
- class="flex-1 min-h-7 p-1 min-w-[200px] outline-none placeholder:text-ink-placeholder"
+ ref={(el) => {
+ setInputRef(el);
+ props.inputRef?.(el);
+ }}
+ class="flex-1 min-h-7 p-1 min-w-[200px] outline-none placeholder:text-ink-placeholder/50"
classList={{
'ml-1': selectedLen() === 0,
}}
diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.ts
index 5ced8fea96..d5286e8553 100644
--- a/js/app/packages/core/hotkey/hotkeys.ts
+++ b/js/app/packages/core/hotkey/hotkeys.ts
@@ -119,6 +119,7 @@ export function registerHotkey(
hide,
icon,
tags,
+ shouldReturnFocusOnClose,
} = args;
if (!scopeId) {
@@ -193,6 +194,7 @@ export function registerHotkey(
hide,
icon,
tags,
+ shouldReturnFocusOnClose,
};
// Check for existing hotkeys in the scope
diff --git a/js/app/packages/core/hotkey/tokens.ts b/js/app/packages/core/hotkey/tokens.ts
index 5eeaac6c49..93cf37546e 100644
--- a/js/app/packages/core/hotkey/tokens.ts
+++ b/js/app/packages/core/hotkey/tokens.ts
@@ -83,6 +83,15 @@ export const TOKENS = {
previousMessage: 'email.previousMessage',
nextMessage: 'email.nextMessage',
cancelReply: 'email.cancelReply',
+ compose: {
+ edit: {
+ recipients: 'email.compose.edit.recipients',
+ ccRecipients: 'email.compose.edit.ccRecipients',
+ bccRecipients: 'email.compose.edit.bccRecipients',
+ subject: 'email.compose.edit.subject',
+ message: 'email.compose.edit.message',
+ },
+ },
},
// split
diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.ts
index e8ab8f28e1..d73f7ff183 100644
--- a/js/app/packages/core/hotkey/types.ts
+++ b/js/app/packages/core/hotkey/types.ts
@@ -28,6 +28,11 @@ export interface HotkeyCommand {
icon?: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;
// Optional tags for categorizing in the command palette.
tags?: string[];
+ /**
+ * @description Should the focus be returned to the previously active element when this command is selected in the Konsole
+ * @default true
+ */
+ shouldReturnFocusOnClose?: boolean;
}
export interface HotkeyRegistrationOptions {
@@ -108,6 +113,12 @@ export interface HotkeyRegistrationOptions {
* Optional tags for categorizing in the command palette.
*/
tags?: string[];
+
+ /**
+ * @description Should the focus be returned to the previously active element when this command is selected in the Konsole
+ * @default true
+ */
+ shouldReturnFocusOnClose?: boolean;
}
export type RegisterHotkeyReturn = {