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(cmd-k): add sidebar go to commands (#2268)
teo9aca730e1601
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsxindex 9033d8bf79..3b1c2cd07f 100644--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx@@ -204,29 +204,32 @@ export const registerSidebarHotkeys = ({// Register navigation shortcuts in the global GO_TO command scopefor (const link of SIDEBAR_LINKS) {+ const openSidebarView = (e?: KeyboardEvent) => {+ e?.preventDefault();+ if (hotkeyVisible()) {+ resetHotkeysState();+ debounceResetHotkeysState.clear();+ }+ openWithSplit(+ {+ type: 'component',+ id: link.id,+ },+ {+ preferNewSplit: e?.shiftKey,+ mergeHistory: false,+ allowDuplicate: true,+ }+ );+ return true;+ };+registerHotkey({hotkey: link.hotkey,scopeId: link.standaloneHotkey ? 'global' : GO_TO_COMMAND_SCOPE,description: `Go to ${link.label}`,- keyDownHandler: (e) => {- e?.preventDefault();- if (hotkeyVisible()) {- resetHotkeysState();- debounceResetHotkeysState.clear();- }- openWithSplit(- {- type: 'component',- id: link.id,- },- {- preferNewSplit: e?.shiftKey,- mergeHistory: false,- allowDuplicate: true,- }- );- return true;- },+ keyDownHandler: openSidebarView,+ icon: link.icon,});}};diff --git a/js/app/packages/app/component/command/CommandItem.tsx b/js/app/packages/app/component/command/CommandItem.tsxindex d9198e343b..d83cf70e48 100644--- a/js/app/packages/app/component/command/CommandItem.tsx+++ b/js/app/packages/app/component/command/CommandItem.tsx@@ -1,6 +1,7 @@import { Hotkey } from '@core/component/Hotkey';import { hasValidHotkey } from '@core/hotkey/utils';-import { Match, Show, Switch } from 'solid-js';+import type { HotkeySequenceStep } from '@core/component/Tooltip';+import { For, Match, Show, Switch } from 'solid-js';import {isCommandItem,isEntityItem,@@ -20,28 +21,62 @@ export interface CommandItemProps {}function CommandItemHotkey(props: { item: CommandMenuItem }) {- const command = () => (isCommandItem(props.item) ? props.item.data : null);+ const commandItem = () => (isCommandItem(props.item) ? props.item : null);+ const command = () => commandItem()?.data ?? null;const token = () => command()?.hotkeyToken;+ const sequence = () => commandItem()?.displayHotkeySequence;const shortcut = () => {- const cmd = command();+ const item = commandItem();+ const cmd = item?.data;if (!cmd) return undefined;if (hasValidHotkey(token())) return undefined;- return cmd.hotkeys?.[0];+ return item?.displayHotkey ?? cmd.hotkeys?.[0];};- const hasHotkey = () => hasValidHotkey(token()) || Boolean(shortcut());+ const hasHotkey = () =>+ hasValidHotkey(token()) ||+ Boolean(shortcut()) ||+ Boolean(sequence()?.length);++ const StepHotkey = (step: HotkeySequenceStep) => (+ <div class="p-2 py-0.5 border border-edge-muted/50 rounded-xs">+ <Hotkey+ token={step.token}+ shortcut={step.shortcut}+ class="flex gap-1 items-center"+ />+ </div>+ );return (<Show when={hasHotkey()}><div class="pr-2 flex items-center justify-center text-[0.75rem] font-medium text-ink-extra-muted">- <div class="p-2 py-0.5 border border-edge-muted/50 rounded-xs">- <Hotkey- token={token()}- shortcut={shortcut()}- class="flex gap-1 items-center"- />- </div>+ <Show+ when={sequence()?.length}+ fallback={+ <div class="p-2 py-0.5 border border-edge-muted/50 rounded-xs">+ <Hotkey+ token={token()}+ shortcut={shortcut()}+ class="flex gap-1 items-center"+ />+ </div>+ }+ >+ <div class="flex items-center gap-1">+ <For each={sequence()}>+ {(step, index) => (+ <>+ {StepHotkey(step)}+ <Show when={index() < (sequence()?.length ?? 0) - 1}>+ <span class="text-ink-extra-muted">then</span>+ </Show>+ </>+ )}+ </For>+ </div>+ </Show></div></Show>);diff --git a/js/app/packages/app/component/command/useCommandItems.ts b/js/app/packages/app/component/command/useCommandItems.tsindex 8627c11d15..2df7516615 100644--- a/js/app/packages/app/component/command/useCommandItems.ts+++ b/js/app/packages/app/component/command/useCommandItems.ts@@ -17,6 +17,8 @@ import {import { activeScope } from '@core/hotkey/state';import { CommandState } from './state';import { HotkeyTags } from '@core/hotkey/constants';+import { GO_TO_COMMAND_SCOPE, GO_TO_LEADER_KEY } from '@app/constants/hotkeys';+import type { HotkeySequenceStep } from '@core/component/Tooltip';/** Command item type - local to command menu, not part of quickAccess */type CommandItem = {@@ -27,6 +29,8 @@ type CommandItem = {sortTimestamp: number;timestamps: Record<string, never>;data: HotkeyCommand;+ displayHotkey?: string;+ displayHotkeySequence?: HotkeySequenceStep[];};/** Combined item type for command menu (quickAccess items + commands) */@@ -60,7 +64,15 @@ function createSearchConfig(hasQuery: boolean) {* Deduplicates commands by description since commands with multiple hotkeys* (e.g., ['delete', 'backspace']) appear multiple times in the command list.*/-function commandsToItems(commands: CommandWithInfo[]): CommandItem[] {+function commandsToItems(+ commands: CommandWithInfo[],+ options?: {+ displayHotkey?: (command: CommandWithInfo) => string | undefined;+ displayHotkeySequence?: (+ command: CommandWithInfo+ ) => HotkeySequenceStep[] | undefined;+ }+): CommandItem[] {const seen = new Set<string>();const dedupedCommands = commands.filter((command) => {const description =@@ -89,6 +101,8 @@ function commandsToItems(commands: CommandWithInfo[]): CommandItem[] {sortTimestamp: 0,timestamps: {},data: command,+ displayHotkey: options?.displayHotkey?.(command),+ displayHotkeySequence: options?.displayHotkeySequence?.(command),};});}@@ -110,6 +124,13 @@ function useCommandsList(): () => CommandItem[] {hideCommandsWithoutHotkeys: false,ignoreInputFocused: true,});+ const goToCommands = getActiveCommandsFromScope(GO_TO_COMMAND_SCOPE, {+ sortByScopeLevel: false,+ hideShadowedCommands: false,+ hideCommandsWithoutHotkeys: false,+ limitToCurrentScope: true,+ ignoreInputFocused: true,+ });return createMemo(() => {// If we're in a command scope (multi-stage command), show those commands instead@@ -126,8 +147,19 @@ function useCommandsList(): () => CommandItem[] {return commandsToItems(selectionCommands);}- // Use the commands captured at mount time- return commandsToItems(capturedCommands);+ // Include sidebar go-to commands in the main command menu with their+ // leader-key sequence rendered as a display-only shortcut.+ return [+ ...commandsToItems(capturedCommands),+ ...commandsToItems(goToCommands, {+ displayHotkeySequence: (command) => {+ const hotkey = command.hotkeys?.[0];+ return hotkey+ ? [{ shortcut: GO_TO_LEADER_KEY }, { shortcut: hotkey }]+ : undefined;+ },+ }),+ ];});}