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
Fix sidebar toggle hotkey when editor input is focused (#1944)
Jacob Beckerman867513865944
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.test.ts b/js/app/packages/app/component/app-sidebar/sidebar.test.tsnew file mode 100644index 0000000000..3a9b555ac3--- /dev/null+++ b/js/app/packages/app/component/app-sidebar/sidebar.test.ts@@ -0,0 +1,53 @@+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 4b499c732a..e886d5fdcc 100644--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx@@ -109,6 +109,66 @@ type AppSidebarProps = {onOpenChange: (open: boolean) => void;};+type SidebarHotkeyDeps = {+ isSlim: () => boolean;+ onOpenChange: (open: boolean) => void;+ openWithSplit: ReturnType<typeof useSplitLayout>['openWithSplit'];+};++export const registerSidebarHotkeys = ({+ isSlim,+ onOpenChange,+ openWithSplit,+}: SidebarHotkeyDeps) => {+ // Register 'g' as a leader key that activates the global GO_TO command scope+ registerHotkey({+ hotkey: GO_TO_LEADER_KEY,+ scopeId: 'global',+ description: 'Go to page',+ keyDownHandler: () => false,+ activateCommandScopeId: GO_TO_COMMAND_SCOPE,+ hide: true,+ registrationType: 'add',+ });++ registerHotkey({+ hotkey: 'cmd+.',+ scopeId: 'global',+ hotkeyToken: TOKENS.global.toggleSidebar,+ description: 'Toggle sidebar',+ runWithInputFocused: true,+ keyDownHandler: (e) => {+ e?.preventDefault();+ onOpenChange(isSlim());+ return true;+ },+ });++ // Register navigation shortcuts in the global GO_TO command scope+ for (const link of SIDEBAR_LINKS) {+ registerHotkey({+ hotkey: link.hotkey,+ scopeId: link.standaloneHotkey ? 'global' : GO_TO_COMMAND_SCOPE,+ description: `Go to ${link.label}`,+ keyDownHandler: (e) => {+ e?.preventDefault();+ openWithSplit(+ {+ type: 'component',+ id: link.id,+ },+ {+ preferNewSplit: e?.shiftKey,+ mergeHistory: false,+ allowDuplicate: true,+ }+ );+ return true;+ },+ });+ }+};+export const AppSidebar = (props: AppSidebarProps) => {const layout = useSplitLayout();const { toggleSettings } = useSettingsState();@@ -121,59 +181,16 @@ export const AppSidebar = (props: AppSidebarProps) => {setCreateMenuOpen((p) => !p);};- const registerHotkeys = () => {- // Register 'g' as a leader key that activates the global GO_TO command scope- registerHotkey({- hotkey: GO_TO_LEADER_KEY,- scopeId: 'global',- description: 'Go to page',- keyDownHandler: () => false,- activateCommandScopeId: GO_TO_COMMAND_SCOPE,- hide: true,- registrationType: 'add',+ const registerHotkeys = () =>+ registerSidebarHotkeys({+ isSlim,+ onOpenChange: props.onOpenChange,+ openWithSplit: layout.openWithSplit,});- registerHotkey({- hotkey: 'cmd+.',- scopeId: 'global',- hotkeyToken: TOKENS.global.toggleSidebar,- description: 'Toggle sidebar',- keyDownHandler: (e) => {- e?.preventDefault();- props.onOpenChange(isSlim());- return true;- },- });-- // Register navigation shortcuts in the global GO_TO command scope- for (const link of SIDEBAR_LINKS) {- registerHotkey({- hotkey: link.hotkey,- scopeId: link.standaloneHotkey ? 'global' : GO_TO_COMMAND_SCOPE,- description: `Go to ${link.label}`,- keyDownHandler: (e) => {- e?.preventDefault();- layout.openWithSplit(- {- type: 'component',- id: link.id,- },- {- preferNewSplit: e?.shiftKey,- mergeHistory: false,- allowDuplicate: true,- }- );- return true;- },- });- }- };-- registerHotkeys();-const isExpanded = () => props.sidebarState === 'expanded';const isSlim = () => props.sidebarState === 'slim';+ registerHotkeys();const [sidebarBtnHovering, setSidebarBtnHovering] = createSignal(false);return (