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.

fix(ui): a couple scuffed hotkeys (#3211)

Fake-User8b649be55213
diff --git a/js/app/packages/app/component/EntitySelectionToolbarModal.tsx b/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
index b77c4992b7..8c8de72f6c 100644
--- a/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
+++ b/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
@@ -44,11 +44,7 @@ export const EntitySelectionToolbarModal = (
class="p-1 px-2 flex gap-1 border-edge-muted rounded-xs border items-center size-full hover:bg-hover hover-transition-bg"
>
<div class="flex border border-edge-muted text-xxs rounded-xs items-center px-1.5 py-px font-normal">
- <Hotkey
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- />
+ <Hotkey shortcut="escape" />
</div>
<span>Clear</span>
</button>
diff --git a/js/app/packages/app/component/SoupChatInput.tsx b/js/app/packages/app/component/SoupChatInput.tsx
index feb4096edb..5902199bde 100644
--- a/js/app/packages/app/component/SoupChatInput.tsx
+++ b/js/app/packages/app/component/SoupChatInput.tsx
@@ -13,6 +13,7 @@ import { deriveChatName } from '@core/component/AI/util/deriveName';
import { PaywallKey, usePaywallState } from '@core/constant/PaywallState';
import { pressedKeys } from '@core/hotkey/state';
import { TOKENS } from '@core/hotkey/tokens';
+import type { ValidHotkey } from '@core/hotkey/types';
import { isPaymentError } from '@core/util/handlePaymentError';
import { isErr } from '@core/util/maybeResult';
import { createRenameDssEntityMutation } from '@macro-entity';
@@ -166,12 +167,7 @@ function SoupChatInputInner() {
'border-edge-muted': !metaHeld(),
}}
>
- <Hotkey
- token={
- TOKENS.global
- .commandMenu /* scuffed, should use TOKENS.ts */
- }
- />
+ <Hotkey shortcut={'cmd+enter' satisfies ValidHotkey} />
</div>
<span>Background</span>
</div>
diff --git a/js/app/packages/app/component/command/CommandMenu.tsx b/js/app/packages/app/component/command/CommandMenu.tsx
index 08af5d8dd6..b4c23c1660 100644
--- a/js/app/packages/app/component/command/CommandMenu.tsx
+++ b/js/app/packages/app/component/command/CommandMenu.tsx
@@ -5,7 +5,7 @@ import { globalSplitManager } from '@app/signal/splitLayout';
import { Tabs } from '@core/component/Tabs';
import { itemToBlockName } from '@core/constant/allBlocks';
import { getActiveCommandsFromScope } from '@core/hotkey/getCommands';
-import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';
+import type { RegisterHotkeyReturn } from '@core/hotkey/types';
import { runCommand } from '@core/hotkey/utils';
import { debouncedDependent } from '@core/util/debounce';
import { type EntityData, InlineEntity } from '@entity';
@@ -261,7 +261,7 @@ export function CommandMenuInner(props: {
CommandState.setQuery('');
}
- registerHotkey({
+ const navDownHotkey = registerHotkey({
hotkey: ['arrowdown', 'ctrl+j'],
scopeId: hotkeyScope,
description: 'Move selection down',
@@ -275,7 +275,7 @@ export function CommandMenuInner(props: {
hide: true,
});
- registerHotkey({
+ const navUpHotkey = registerHotkey({
hotkey: ['arrowup', 'ctrl+k'],
scopeId: hotkeyScope,
description: 'Move selection up',
@@ -291,7 +291,7 @@ export function CommandMenuInner(props: {
hide: true,
});
- registerHotkey({
+ const confirmHotkey = registerHotkey({
hotkey: 'enter',
scopeId: hotkeyScope,
description: 'Select item',
@@ -306,7 +306,7 @@ export function CommandMenuInner(props: {
runWithInputFocused: true,
});
- registerHotkey({
+ const confirmSplitHotkey = registerHotkey({
hotkey: 'shift+enter',
scopeId: hotkeyScope,
description: 'Open in new split',
@@ -321,7 +321,7 @@ export function CommandMenuInner(props: {
runWithInputFocused: true,
});
- registerHotkey({
+ const escapeHotkey = registerHotkey({
hotkey: 'escape',
scopeId: hotkeyScope,
description: 'Close command menu',
@@ -341,7 +341,7 @@ export function CommandMenuInner(props: {
});
// Backspace when query is empty goes back from command scope
- registerHotkey({
+ const backspaceHotkey = registerHotkey({
hotkey: 'backspace',
scopeId: hotkeyScope,
description: 'Go back',
@@ -363,7 +363,7 @@ export function CommandMenuInner(props: {
hide: true,
});
- registerHotkey({
+ const tabHotkey = registerHotkey({
hotkey: 'tab',
scopeId: hotkeyScope,
description: 'Next category',
@@ -536,20 +536,10 @@ export function CommandMenuInner(props: {
<span class="flex items-center gap-1">
<div class="flex gap-1">
<div class="flex border border-edge-muted text-xxs rounded-xs items-center px-1.5 py-px font-normal">
- <Hotkey
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- class="space-x-1"
- />
+ <Hotkey shortcut={navUpHotkey.hotkey()} class="space-x-1" />
</div>
<div class="flex border border-edge-muted text-xxs rounded-xs items-center px-1.5 py-px font-normal">
- <Hotkey
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- class="space-x-1"
- />
+ <Hotkey shortcut={navDownHotkey.hotkey()} class="space-x-1" />
</div>
</div>
Navigate
@@ -557,55 +547,26 @@ export function CommandMenuInner(props: {
<Switch>
<Match when={isInCommandScope()}>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Run action"
- />
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Back"
- />
+ <HotkeyHint command={confirmHotkey} label="Run action" />
+ <HotkeyHint command={backspaceHotkey} label="Back" />
</Match>
<Match when={selectedIsCommand() || isEntityActionMode()}>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Run action"
- />
+ <HotkeyHint command={confirmHotkey} label="Run action" />
</Match>
<Match when={selectedIsSearch()}>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Search"
- />
+ <HotkeyHint command={confirmHotkey} label="Search" />
<Show when={canOpenInNewSplit()}>
<HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
+ command={confirmSplitHotkey}
label="Search in new split"
/>
</Show>
</Match>
<Match when={selectedIsEntity()}>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Open"
- />
+ <HotkeyHint command={confirmHotkey} label="Open" />
<Show when={canOpenInNewSplit()}>
<HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
+ command={confirmSplitHotkey}
label="Open in new split"
/>
</Show>
@@ -613,30 +574,13 @@ export function CommandMenuInner(props: {
</Switch>
<Show when={!isInCommandScope() && !isEntityActionMode()}>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Category"
- />
+ <HotkeyHint command={tabHotkey} label="Category" />
</Show>
<Show
when={isInCommandScope()}
- fallback={
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Close"
- />
- }
+ fallback={<HotkeyHint command={escapeHotkey} label="Close" />}
>
- <HotkeyHint
- token={
- TOKENS.global.commandMenu /* scuffed, should use TOKENS.ts */
- }
- label="Back"
- />
+ <HotkeyHint command={escapeHotkey} label="Back" />
</Show>
</Panel.Footer>
</Panel>
@@ -726,11 +670,11 @@ function VirtualizedCommandList(props: {
);
}
-function HotkeyHint(props: { token: HotkeyToken; label: string }) {
+function HotkeyHint(props: { command: RegisterHotkeyReturn; label: string }) {
return (
<span class="flex items-center gap-1">
<div class="flex border border-edge-muted text-xxs rounded-xs items-center px-1.5 py-px font-normal">
- <Hotkey token={props.token} class="space-x-1" />
+ <Hotkey shortcut={props.command.hotkey()} class="space-x-1" />
</div>
{props.label}
</span>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
index 4e3b80e92f..dd709dd646 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
@@ -5,7 +5,6 @@ import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';
import { registerHotkey } from '@core/hotkey/hotkeys';
-import { TOKENS } from '@core/hotkey/tokens';
import XIcon from '@icon/regular/x.svg?component-solid';
import { markdownToPlainText } from '@lexical-core/utils/parsers';
import SearchIcon from '@macro-icons/macro-magnifying-glass.svg';
@@ -166,9 +165,11 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
class="min-h-0! overflow-visible!"
/>
</div>
- <Show when={!hasContent() && !props.onDismiss}>
+ <Show
+ when={!hasContent() && !props.onDismiss && !!searchHotkey.hotkey()}
+ >
<div class="shrink-0 text-xxs text-ink-extra-muted/50 rounded-sm border border-ink/5 px-1.5 py-px group-focus-within:hidden">
- <Hotkey token={TOKENS.soup.openSearch} class="flex gap-1" />
+ <Hotkey shortcut={searchHotkey.hotkey()} class="flex gap-1" />
</div>
</Show>
<Show when={hasContent() || props.onDismiss}>
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index dc5270ba5d..6bba35157d 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -239,6 +239,7 @@ export const SoupView = (props: SoupViewProps) => {
registerHotkey({
hotkey: 'cmd+f',
+ hotkeyToken: TOKENS.soup.openSearch,
scopeId: panel.splitHotkeyScope,
registrationType: 'add',
description: 'Search',
diff --git a/js/app/packages/core/hotkey/hotkeys.test.ts b/js/app/packages/core/hotkey/hotkeys.test.ts
index 13e17a71ac..e3b37902a9 100644
--- a/js/app/packages/core/hotkey/hotkeys.test.ts
+++ b/js/app/packages/core/hotkey/hotkeys.test.ts
@@ -5,6 +5,7 @@ import type { RegisterHotkeyReturn } from './types';
const makeRegistration = (): RegisterHotkeyReturn => {
const reg: RegisterHotkeyReturn = {
dispose: vi.fn(),
+ hotkey: () => undefined,
withGroup: (group) => {
group.add(reg);
return reg;
diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.ts
index afec7551d6..046de1b86d 100644
--- a/js/app/packages/core/hotkey/hotkeys.ts
+++ b/js/app/packages/core/hotkey/hotkeys.ts
@@ -39,6 +39,7 @@ import {
getKeyString,
getScopeId,
normalizeEventKeyPress,
+ prettyPrintHotkeyString,
registerScope,
removeCommandsFromTokenMap,
removeScope,
@@ -131,6 +132,7 @@ export function registerHotkey(
const noopDisposer: RegisterHotkeyReturn = {
dispose: () => {},
+ hotkey: () => undefined,
withGroup: (group) => {
group.add(noopDisposer);
return noopDisposer;
@@ -275,8 +277,14 @@ export function registerHotkey(
}
}
+ const primaryHotkey = hotkeys?.[0];
+ const prettyHotkey = primaryHotkey
+ ? prettyPrintHotkeyString(primaryHotkey)
+ : undefined;
+
// Create disposer object
const disposer: RegisterHotkeyReturn = {
+ hotkey: () => prettyHotkey,
dispose: () => {
// Remove from hotkey token map if it exists
if (hotkeyToken) {
diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.ts
index bd52eec02c..340e493b3b 100644
--- a/js/app/packages/core/hotkey/types.ts
+++ b/js/app/packages/core/hotkey/types.ts
@@ -198,6 +198,7 @@ export type HotkeyGroup = {
export type RegisterHotkeyReturn = {
dispose: () => void;
commandScopeId?: string;
+ hotkey: () => string | undefined;
/** Add this registration to a group for grouped disposal */
withGroup: (group: HotkeyGroup) => RegisterHotkeyReturn;
};