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
feat(sidebar): shortcut labels (#1880)
dev-rb4ca10c9a5fd3
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.test.ts b/js/app/packages/app/component/app-sidebar/sidebar.test.tsdeleted file mode 100644index 3a9b555ac3..0000000000--- a/js/app/packages/app/component/app-sidebar/sidebar.test.ts+++ /dev/null@@ -1,53 +0,0 @@-import { describe, expect, test, vi, beforeEach } from 'vitest';-import { registerSidebarHotkeys } from './sidebar';-import { registerHotkey } from '@core/hotkey/hotkeys';--vi.mock('@core/hotkey/hotkeys', () => ({- registerHotkey: vi.fn(),-}));--describe('registerSidebarHotkeys', () => {- beforeEach(() => {- vi.clearAllMocks();- });-- test('registers sidebar toggle hotkey to run with focused input', () => {- registerSidebarHotkeys({- isSlim: () => false,- onOpenChange: vi.fn(),- openWithSplit: vi.fn(),- });-- expect(registerHotkey).toHaveBeenCalledWith(- expect.objectContaining({- hotkey: 'cmd+.',- runWithInputFocused: true,- })- );- });-- test('sidebar toggle handler uses current slim state', () => {- const onOpenChange = vi.fn();- let slim = true;-- registerSidebarHotkeys({- isSlim: () => slim,- onOpenChange,- openWithSplit: vi.fn(),- });-- const toggleRegistration = vi- .mocked(registerHotkey)- .mock.calls.map(([args]) => args)- .find((args) => args.hotkey === 'cmd+.');-- expect(toggleRegistration).toBeDefined();-- toggleRegistration?.keyDownHandler();- expect(onOpenChange).toHaveBeenLastCalledWith(true);-- slim = false;- toggleRegistration?.keyDownHandler();- expect(onOpenChange).toHaveBeenLastCalledWith(false);- });-});diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsxindex 37944f194f..32be74797c 100644--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx@@ -32,13 +32,15 @@ import { useSettingsState } from '@core/constant/SettingsState';import type { ValidHotkey } from '@core/hotkey/types';import { registerHotkey } from '@core/hotkey/hotkeys';import { GO_TO_COMMAND_SCOPE, GO_TO_LEADER_KEY } from '@app/constants/hotkeys';+import { debounce, type Scheduled } from '@solid-primitives/scheduled';+import { Hotkey } from '@core/component/Hotkey';+import { clearPressedKeys } from '@core/hotkey/state';+import { activateClosestDOMScope } from '@core/hotkey/utils';+import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';import { ContextMenuContent, MenuItem } from '@core/component/Menu';import { ContextMenu } from '@kobalte/core/context-menu';--import { TOKENS } from '@core/hotkey/tokens';-import { Hotkey } from '@core/component/Hotkey';import { useAnalytics } from '@app/component/analytics-context';-import type { HotkeyToken } from '@core/hotkey/tokens';+import { useHotkeyInterceptor } from '@app/signal/hotkeyRoot';interface SidebarItem {id: ListView;@@ -119,6 +121,10 @@ type AppSidebarProps = {};type SidebarHotkeyDeps = {+ hotkeyVisible: () => boolean;+ setHotkeyVisible: (visible: boolean) => void;+ resetHotkeysState: VoidFunction;+ debounceResetHotkeysState: Scheduled<[]>;isSlim: () => boolean;onOpenChange: (open: boolean) => void;openWithSplit: ReturnType<typeof useSplitLayout>['openWithSplit'];@@ -128,18 +134,50 @@ export const registerSidebarHotkeys = ({isSlim,onOpenChange,openWithSplit,+ hotkeyVisible,+ setHotkeyVisible,+ resetHotkeysState,+ debounceResetHotkeysState,}: SidebarHotkeyDeps) => {// Register 'g' as a leader key that activates the global GO_TO command scoperegisterHotkey({hotkey: GO_TO_LEADER_KEY,scopeId: 'global',description: 'Go to page',- keyDownHandler: () => false,+ keyDownHandler: () => {+ setHotkeyVisible(true);+ debounceResetHotkeysState();+ return true;+ },activateCommandScopeId: GO_TO_COMMAND_SCOPE,hide: true,registrationType: 'add',});+ const registeredGoToKeys = new Set<ValidHotkey>([+ ...SIDEBAR_LINKS.map((link) => link.hotkey),+ ]);++ // When the go to command scope is active, we want to prevent+ // other default hotkeys from running. So doing "g" + some key+ // not part of the sidebar hotkeys, won't fire the command+ // for the key+ useHotkeyInterceptor((context) => {+ if (context.eventType !== 'keydown' || !hotkeyVisible()) return false;++ if (+ context.activeScopeId !== GO_TO_COMMAND_SCOPE ||+ registeredGoToKeys.has(context.pressedKeysString)+ ) {+ return false;+ }++ resetHotkeysState();+ debounceResetHotkeysState.clear();++ return true;+ });+registerHotkey({hotkey: 'cmd+.',scopeId: 'global',@@ -161,6 +199,10 @@ export const registerSidebarHotkeys = ({description: `Go to ${link.label}`,keyDownHandler: (e) => {e?.preventDefault();+ if (hotkeyVisible()) {+ resetHotkeysState();+ debounceResetHotkeysState.clear();+ }openWithSplit({type: 'component',@@ -243,6 +285,19 @@ export const AppSidebar = (props: AppSidebarProps) => {const layout = useSplitLayout();const { toggleSettings } = useSettingsState();+ const [hotkeyVisible, setHotkeyVisible] = createSignal(false);++ const resetHotkeysState = () => {+ setHotkeyVisible(false);++ // To prevent the next key from triggering the hotkey handler,+ // we reset the pressed keys state and exit the command scope+ clearPressedKeys();+ activateClosestDOMScope();+ };++ const debounceResetHotkeysState = debounce(resetHotkeysState, 2000);+const handleCommandPaletteClick = () => {if (!CommandState.isOpen()) {analytics.track('command_menu_open', { from: 'sidebar' });@@ -277,18 +332,20 @@ export const AppSidebar = (props: AppSidebarProps) => {});};- const registerHotkeys = () =>- registerSidebarHotkeys({- isSlim,- onOpenChange: props.onOpenChange,- openWithSplit: layout.openWithSplit,- });-const isExpanded = () => props.sidebarState === 'expanded';const isSlim = () => props.sidebarState === 'slim';- registerHotkeys();const [sidebarBtnHovering, setSidebarBtnHovering] = createSignal(false);+ registerSidebarHotkeys({+ hotkeyVisible,+ setHotkeyVisible,+ resetHotkeysState,+ debounceResetHotkeysState,+ isSlim,+ onOpenChange: props.onOpenChange,+ openWithSplit: layout.openWithSplit,+ });+return (<divclass={cn(@@ -353,6 +410,7 @@ export const AppSidebar = (props: AppSidebarProps) => {<SidebarLink{...link}sidebarState={props.sidebarState ?? 'expanded'}+ hotkeyVisible={hotkeyVisible()}/></li>)}@@ -406,6 +464,7 @@ export const AppSidebar = (props: AppSidebarProps) => {interface SidebarLinkProps extends SidebarItem {sidebarState: SidebarState;+ hotkeyVisible: boolean;}const SidebarLink = (props: SidebarLinkProps) => {@@ -519,7 +578,7 @@ const SidebarLink = (props: SidebarLinkProps) => {{props.label}</span>- <Show when={isHovering()}>+ <Show when={isHovering() && !props.hotkeyVisible}><div class="group-data-[slim=true]/sidebar:invisible ml-auto"><div class="flex gap-1 items-center text-ink-extra-muted font-normal text-[0.625rem]"><Show when={!props.standaloneHotkey}>@@ -539,6 +598,18 @@ const SidebarLink = (props: SidebarLinkProps) => {</div></div></Show>+ <Show when={props.hotkeyVisible}>+ <div+ class={cn(+ 'text-xs size-4 outline outline-1 outline-accent/50 rounded-xs bg-page text-ink flex items-center justify-center overflow-hidden',+ props.sidebarState === 'slim' && 'absolute -bottom-1 -right-1',+ props.sidebarState !== 'slim' && 'relative p-1 ml-auto'+ )}+ >+ <div class="absolute inset-0 size-full bg-accent/20" />+ <Hotkey shortcut={props.hotkey} />+ </div>+ </Show></Button></ContextMenu.Trigger>diff --git a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.tsindex c29ef2c0b3..ae7b02d18d 100644--- a/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts+++ b/js/app/packages/app/component/next-soup/soup-view/use-soup-view-hotkeys.ts@@ -90,16 +90,6 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {hide: true,}).withGroup(group);- // g g - Jump to top of list (vim-style, uses global GO_TO command scope)- registerHotkey({- hotkey: GO_TO_LEADER_KEY,- scopeId,- description: 'Go to top of list',- keyDownHandler: () => false,- activateCommandScopeId: GO_TO_COMMAND_SCOPE,- hide: true,- }).withGroup(group);-// Register 'g' in the global GO_TO command scope for g+g (jump to top)// Uses condition to only run for the soup-view that was focused when 'g' was pressedregisterHotkey({diff --git a/js/app/packages/app/signal/hotkeyRoot.ts b/js/app/packages/app/signal/hotkeyRoot.tsindex a20a47ac75..6389f9221a 100644--- a/js/app/packages/app/signal/hotkeyRoot.ts+++ b/js/app/packages/app/signal/hotkeyRoot.ts@@ -1,5 +1,8 @@import type { useHotKeyRoot } from '@core/hotkey/hotkeys';-import type { KeypressContext } from '@core/hotkey/types';+import type {+ HotkeyInterceptorContext,+ KeypressContext,+} from '@core/hotkey/types';import { createSignal, onCleanup, onMount } from 'solid-js';export const [hotkeyRoot, setHotkeyRoot] =@@ -19,3 +22,21 @@ export function useSubscribeToKeypress(onCleanup(cleanup);});}++/**+ * Subscribe to hotkey interceptor events BEFORE command lookup.+ * Return true from the callback to capture the event and prevent+ * normal hotkey command lookup and propagation.+ * Automatically cleans up on unmount.+ */+export function useHotkeyInterceptor(+ callback: (context: HotkeyInterceptorContext) => boolean+) {+ onMount(() => {+ const root = hotkeyRoot();+ if (!root) return;++ const cleanup = root.addHotkeyInterceptor(callback);+ onCleanup(cleanup);+ });+}diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.tsindex ff96301fae..2d5abcc614 100644--- a/js/app/packages/core/hotkey/hotkeys.ts+++ b/js/app/packages/core/hotkey/hotkeys.ts@@ -25,6 +25,7 @@ import {HOTKEY_PRIORITY_DEFAULT,type HotkeyCommand,type HotkeyGroup,+ type HotkeyInterceptorContext,type HotkeyRegistrationOptions,isBaseKeyboardValue,type KeypressContext,@@ -531,6 +532,8 @@ export function useHotKeyRoot() {}let onKeypress: ((context: KeypressContext) => void)[] = [];+ let onHotkeyInterceptor: ((context: HotkeyInterceptorContext) => boolean)[] =+ [];const handleKeyDown = (e: KeyboardEvent) => {document.documentElement.dataset.modality = 'keyboard';@@ -623,6 +626,25 @@ export function useHotKeyRoot() {const pressedKeysString = getKeyString(currentPressedKeys);+ // Call hotkey interceptor handlers before command lookup+ // If any handler returns true, capture the event and skip normal processing+ const hotkeyInterceptorContext: HotkeyInterceptorContext = {+ pressedKeysString,+ pressedKeys: currentPressedKeys,+ event: e,+ activeScopeId: currentScopeId,+ isEditableFocused: isEditableFocused ?? false,+ eventType: e.type as 'keydown' | 'keyup',+ };++ for (const callback of onHotkeyInterceptor) {+ if (callback(hotkeyInterceptorContext)) {+ e.preventDefault();+ e.stopPropagation();+ return;+ }+ }+let scopeNode = scopeTree.get(currentScopeId);let commandCaptured: HotkeyCommand | undefined;let commandScopeActivated = false;@@ -742,6 +764,35 @@ export function useHotKeyRoot() {onKeypress = onKeypress.filter((c) => c !== callback);};},++ /**+ * Subscribe to hotkey interceptor events BEFORE command lookup.+ * Return true from the callback to capture the event and prevent+ * normal hotkey command lookup and propagation.+ *+ * @param callback - Function called before hotkey command lookup.+ * Return true to capture the event and skip normal processing.+ * @returns A cleanup function to unsubscribe.+ *+ * @example+ * ```ts+ * addHotkeyInterceptor((context) => {+ * // Capture unregistered keys in a specific scope+ * if (context.activeScopeId === 'my-command-scope') {+ * return true; // Capture and prevent propagation+ * }+ * return false; // Let normal processing continue+ * });+ * ```+ */+ addHotkeyInterceptor: (+ callback: (context: HotkeyInterceptorContext) => boolean+ ) => {+ onHotkeyInterceptor.push(callback);+ return () => {+ onHotkeyInterceptor = onHotkeyInterceptor.filter((c) => c !== callback);+ };+ },};}diff --git a/js/app/packages/core/hotkey/state.ts b/js/app/packages/core/hotkey/state.tsindex 8ee3b9356f..3ee2f9f55c 100644--- a/js/app/packages/core/hotkey/state.ts+++ b/js/app/packages/core/hotkey/state.ts@@ -34,6 +34,10 @@ export const [pressedKeys, setPressedKeys] = createSignal<Set<string>>(new Set());+export const clearPressedKeys = () => {+ setPressedKeys(new Set<string>());+};+export const [executedTokens, setExecutedTokens] = makePersisted(createSignal<string[]>([]),{diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.tsindex 5d116d83f6..3a19fa1309 100644--- a/js/app/packages/core/hotkey/types.ts+++ b/js/app/packages/core/hotkey/types.ts@@ -346,6 +346,27 @@ export type ValidHotkey =| `ctrl+opt+shift+${BaseKeyboardValue}`| `opt+shift+cmd+${BaseKeyboardValue}`;+/**+ * Context object passed to hotkey interceptor subscribers before hotkey command+ * lookup. Runs before normal hotkey processing. Return true from the+ * callback to capture the event and prevent normal hotkey command lookup+ * and propagation.+ */+export interface HotkeyInterceptorContext {+ /** The normalized hotkey string (e.g., 'cmd+j', 'j') */+ pressedKeysString: ValidHotkey;+ /** Set of currently pressed keys */+ pressedKeys: Set<string>;+ /** The raw keyboard event */+ event: KeyboardEvent;+ /** The currently active scope ID */+ activeScopeId: string;+ /** Whether an editable input element is currently focused */+ isEditableFocused: boolean;+ /** The event type ('keydown' or 'keyup') */+ eventType: 'keydown' | 'keyup';+}+/*** Context object passed to keypress subscribers containing all relevant* information about the current keypress event. Subscribers can use this