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(settings): fix hotkey nav and cmd k from settings (#4596)

Aidan Holloway-Bidwelled68820d60a2
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsx
index 2253d44330..c687fd6f16 100644
--- a/js/app/packages/app/component/Layout.tsx
+++ b/js/app/packages/app/component/Layout.tsx
@@ -1,5 +1,6 @@
import {
AppSidebar,
+ GoToHotkeys,
type SidebarState,
} from '@app/component/app-sidebar/sidebar';
import {
@@ -142,6 +143,7 @@ function LayoutInner(props: RouteSectionProps) {
</Show>
<GlobalShortcuts />
<Show when={!isMobile()}>
+ <GoToHotkeys />
<Suspense>
<FavoritesCommands />
<CommandMenu />
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index 4e6fba1aa5..68d63a7157 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -284,13 +284,8 @@ type AppSidebarProps = {
};
type SidebarHotkeyDeps = {
- links: () => SidebarItem[];
- hotkeyVisible: () => boolean;
- setHotkeyVisible: (visible: boolean) => void;
- resetHotkeysState: VoidFunction;
isSlim: () => boolean;
onOpenChange: (open: boolean) => void;
- openWithSplit: ReturnType<typeof useSplitLayout>['openWithSplit'];
};
type OpenWithSplitFn = ReturnType<typeof useSplitLayout>['openWithSplit'];
@@ -349,16 +344,74 @@ function navigateToSidebarView(args: {
}
const registerSidebarHotkeys = ({
- links,
isSlim,
onOpenChange,
- openWithSplit,
- hotkeyVisible,
- setHotkeyVisible,
- resetHotkeysState,
}: SidebarHotkeyDeps) => {
- const debounceResetHotkeysState = debounce(resetHotkeysState, 2000);
- const debounceSetHotkeyVisible = debounce(() => setHotkeyVisible(true), 200);
+ registerHotkey({
+ scopeId: 'global',
+ hotkeyToken: TOKENS.global.inviteTeam,
+ description: 'Send Invites',
+ keyDownHandler: (e) => {
+ e?.preventDefault();
+ setInviteModalOpen(true);
+ return true;
+ },
+ });
+
+ registerHotkey({
+ hotkey: 'cmd+.',
+ scopeId: 'global',
+ hotkeyToken: TOKENS.global.toggleSidebar,
+ description: 'Toggle sidebar and side panels',
+ runWithInputFocused: true,
+ keyDownHandler: (e) => {
+ e?.preventDefault();
+ const show = isSlim();
+ onOpenChange(show);
+ setAllSidePanelsOpen(show);
+ return true;
+ },
+ });
+};
+
+/**
+ * Whether the "g" leader key is currently awaiting a destination key. Lives
+ * at module scope so it can drive the hint overlay on `AppSidebar`'s nav
+ * icons even though the registration below is owned by `GoToHotkeys`, which
+ * stays mounted regardless of whether the sidebar itself is visible.
+ */
+const [goToHotkeyVisible, setGoToHotkeyVisible] = createSignal(false);
+
+const resetGoToHotkeysState = () => {
+ setGoToHotkeyVisible(false);
+ // To prevent the next key from triggering the hotkey handler,
+ // we reset the pressed keys state and exit the command scope
+ clearPressedKeys();
+ activateClosestDOMScope();
+};
+
+/**
+ * Registers the "g" leader key and the per-link "go to" nav hotkeys (e.g.
+ * "g i" for inbox). Rendered unconditionally from `Layout` — unlike
+ * `AppSidebar`, which unmounts on full-cover routes like settings — so these
+ * shortcuts keep working everywhere in the app.
+ */
+export const GoToHotkeys = () => {
+ const { openWithSplit } = useSplitLayout();
+
+ const homeViewEnabled = useFeatureFlag('enable-home-view', {
+ enabledOverride: ENABLE_HOME_OVERRIDE,
+ });
+
+ const links = createMemo((): SidebarItem[] =>
+ buildSidebarLinks(homeViewEnabled().enabled)
+ );
+
+ const debounceResetHotkeysState = debounce(resetGoToHotkeysState, 2000);
+ const debounceSetHotkeyVisible = debounce(
+ () => setGoToHotkeyVisible(true),
+ 200
+ );
// Register 'g' as a leader key that activates the global GO_TO command scope
registerHotkey({
@@ -389,7 +442,7 @@ const registerSidebarHotkeys = ({
// If a hotkey is going to be fired, but the hotkeys are not
// visible, then it's not a sidebar nav hotkey and we can
// ignore it and reset our visible state
- if (!hotkeyVisible()) {
+ if (!goToHotkeyVisible()) {
debounceSetHotkeyVisible.clear();
return false;
}
@@ -403,38 +456,12 @@ const registerSidebarHotkeys = ({
return false;
}
- resetHotkeysState();
+ resetGoToHotkeysState();
debounceResetHotkeysState.clear();
return true;
});
- registerHotkey({
- scopeId: 'global',
- hotkeyToken: TOKENS.global.inviteTeam,
- description: 'Send Invites',
- keyDownHandler: (e) => {
- e?.preventDefault();
- setInviteModalOpen(true);
- return true;
- },
- });
-
- registerHotkey({
- hotkey: 'cmd+.',
- scopeId: 'global',
- hotkeyToken: TOKENS.global.toggleSidebar,
- description: 'Toggle sidebar and side panels',
- runWithInputFocused: true,
- keyDownHandler: (e) => {
- e?.preventDefault();
- const show = isSlim();
- onOpenChange(show);
- setAllSidePanelsOpen(show);
- return true;
- },
- });
-
// Register navigation shortcuts in the global GO_TO command scope.
// This must be reactive because prod feature flags can add links after the
// initial render (e.g. Home), and Hotkey UI resolves tokens from the registry.
@@ -442,8 +469,8 @@ const registerSidebarHotkeys = ({
const disposers = links().map((link) => {
const openSidebarView = (e?: KeyboardEvent) => {
e?.preventDefault();
- if (hotkeyVisible()) {
- resetHotkeysState();
+ if (goToHotkeyVisible()) {
+ resetGoToHotkeysState();
debounceResetHotkeysState.clear();
}
@@ -489,6 +516,8 @@ const registerSidebarHotkeys = ({
}
});
});
+
+ return null;
};
/** Session-only signal so a hint shows after dismissal until the user acknowledges or the timer expires. */
@@ -695,6 +724,30 @@ const DASHBOARD_LINK: SidebarItem = {
hotkeyToken: TOKENS.sidebar.goTo.home,
};
+/**
+ * Assemble the ordered sidebar link list: the static links plus the flag-gated
+ * Home and Calls entries in their correct positions. Shared by the rendered
+ * sidebar (`AppSidebar.visibleLinks`) and the always-mounted `GoToHotkeys`
+ * registrar so their link sets can't drift. Call from a reactive context — it
+ * reads `ENABLE_CALLS()`; `homeEnabled` is passed in so the caller tracks the
+ * feature-flag read. `visibleLinks` additionally drops `hiddenFromSidebar`
+ * entries, which have hotkeys but no sidebar row.
+ */
+const buildSidebarLinks = (homeEnabled: boolean): SidebarItem[] => {
+ let links: SidebarItem[] = [...SIDEBAR_LINKS];
+
+ if (homeEnabled) {
+ links = [DASHBOARD_LINK, ...links];
+ }
+
+ if (ENABLE_CALLS()) {
+ const idx = links.findIndex((l) => l.id === 'channels');
+ links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
+ }
+
+ return links;
+};
+
/**
* Settings tabs surfaced as always-visible quick links above the settings
* widget. Label/icon come from the settings tab config (see
@@ -707,7 +760,6 @@ const PROMOTED_SETTINGS_TABS: SettingsTab[] = [
];
export const AppSidebar = (props: AppSidebarProps) => {
- const layout = useSplitLayout();
const { openSettings, selectTab, settingsOpen } = useSettingsState();
const isTabAvailable = useSettingsTabAvailable();
const callCtx = useCallContextOptional();
@@ -728,46 +780,11 @@ export const AppSidebar = (props: AppSidebarProps) => {
enabledOverride: ENABLE_NEW_PRICING_OVERRIDE,
});
- const [hotkeyVisible, setHotkeyVisible] = createSignal(false);
-
- const visibleLinks = createMemo((): SidebarItem[] => {
- let links: SidebarItem[] = [...SIDEBAR_LINKS];
-
- if (homeViewEnabled().enabled) {
- links = [DASHBOARD_LINK, ...links];
- }
-
- if (ENABLE_CALLS()) {
- const idx = links.findIndex((l) => l.id === 'channels');
- links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
- }
-
- return links.filter((link) => !link.hiddenFromSidebar);
- });
-
- const hotkeyLinks = createMemo((): SidebarItem[] => {
- let links: SidebarItem[] = [...SIDEBAR_LINKS];
-
- if (homeViewEnabled().enabled) {
- links = [DASHBOARD_LINK, ...links];
- }
-
- if (ENABLE_CALLS()) {
- const idx = links.findIndex((l) => l.id === 'channels');
- links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
- }
-
- return links;
- });
-
- 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 visibleLinks = createMemo((): SidebarItem[] =>
+ buildSidebarLinks(homeViewEnabled().enabled).filter(
+ (link) => !link.hiddenFromSidebar
+ )
+ );
const openSettingsTab = (tab: SettingsTab) => {
if (!isTabAvailable(tab)) return;
@@ -789,13 +806,8 @@ export const AppSidebar = (props: AppSidebarProps) => {
});
registerSidebarHotkeys({
- links: hotkeyLinks,
- hotkeyVisible,
- setHotkeyVisible,
- resetHotkeysState,
isSlim,
onOpenChange: handleSidebarOpenChange,
- openWithSplit: layout.openWithSplit,
});
return (
@@ -848,7 +860,7 @@ export const AppSidebar = (props: AppSidebarProps) => {
component={link.id === 'mail' ? SidebarMailLink : SidebarLink}
{...link}
sidebarState={props.sidebarState ?? 'expanded'}
- hotkeyVisible={hotkeyVisible()}
+ hotkeyVisible={goToHotkeyVisible()}
/>
</li>
)}
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index f326220754..30133e2e9c 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -1,6 +1,12 @@
+import { DEFAULT_ROUTE } from '@app/constants/defaultRoute';
+import { isSettingsPath } from '@core/constant/settingsPath';
import { isMobile } from '@core/mobile/isMobile';
+import { useLocation, useNavigate } from '@solidjs/router';
import { useContext } from 'solid-js';
-import { globalSplitManager } from '../../signal/splitLayout';
+import {
+ globalSplitManager,
+ whenSplitManagerReady,
+} from '../../signal/splitLayout';
import { SplitPanelContext } from './context';
import type {
OpenWithSplitOptions,
@@ -10,19 +16,33 @@ import type {
export function useSplitLayout() {
const splitPanelContext = useContext(SplitPanelContext);
+ const navigate = useNavigate();
+ const location = useLocation();
function openWithSplit(
content: SplitContent,
options?: OpenWithSplitOptions
) {
const splitManager = globalSplitManager();
+ const preferNewSplit = isMobile() ? false : options?.preferNewSplit;
+
if (!splitManager) {
- console.error('No split manager found');
+ if (!isSettingsPath(location.pathname)) {
+ console.error('No split manager found');
+ return;
+ }
+
+ // Settings is a full-cover route with no split layout mounted, so
+ // hotkey/command-menu navigation triggered from there has nowhere to
+ // open content. Leave settings for the default workspace route, then
+ // finish the open once its split manager mounts.
+ navigate(DEFAULT_ROUTE, { replace: true });
+ void whenSplitManagerReady().then((manager) =>
+ manager.openWithSplit(content, { ...options, preferNewSplit })
+ );
return;
}
- const preferNewSplit = isMobile() ? false : options?.preferNewSplit;
-
return splitManager.openWithSplit(content, {
...options,
preferNewSplit,
@@ -33,12 +53,6 @@ export function useSplitLayout() {
content: SplitContent,
referredFrom: ReferredFrom = null
) {
- const splitManager = globalSplitManager();
- if (!splitManager) {
- console.error('No split manager found');
- return;
- }
-
return openWithSplit(content, {
referredFrom,
handle: splitPanelContext?.handle,
diff --git a/js/app/packages/core/constant/SettingsState.tsx b/js/app/packages/core/constant/SettingsState.tsx
index 3699f56aff..973da3a635 100644
--- a/js/app/packages/core/constant/SettingsState.tsx
+++ b/js/app/packages/core/constant/SettingsState.tsx
@@ -1,14 +1,16 @@
import { useSplitLayout } from '@app/component/split-layout/layout';
import { DEFAULT_ROUTE } from '@app/constants/defaultRoute';
-import { ROUTER_BASE } from '@app/constants/routerBase';
import { globalSplitManager } from '@app/signal/splitLayout';
import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { activeTabId, setActiveTabId } from '@core/signal/settingsTab';
import { useLocation, useNavigate } from '@solidjs/router';
import { createMemo, createSignal } from 'solid-js';
+import { isSettingsPath, SETTINGS_PATH, toBaseRelative } from './settingsPath';
import { settingsSlugToTab, settingsTabToSlug } from './settingsTabsConfig';
+export { isSettingsPath };
+
export type SettingsTab =
| 'Account'
| 'Billing'
@@ -32,31 +34,9 @@ export type SettingsTab =
// which case we fall back to DEFAULT_ROUTE.
const [settingsReturnTo, setSettingsReturnTo] = createSignal<string>();
-const SETTINGS_PATH = '/settings';
-
const settingsPathFor = (tab: SettingsTab) =>
`${SETTINGS_PATH}/${settingsTabToSlug(tab)}`;
-/**
- * Strip the router base from a `location.pathname` (which includes it, e.g.
- * `/app/settings`) so it can be compared to — and reused with — the
- * base-relative paths that `navigate()` and route definitions use.
- */
-const toBaseRelative = (pathname: string) => {
- if (ROUTER_BASE === '/') return pathname;
- if (pathname === ROUTER_BASE) return '/';
- if (pathname.startsWith(`${ROUTER_BASE}/`)) {
- return pathname.slice(ROUTER_BASE.length);
- }
- return pathname;
-};
-
-/** Whether a `location.pathname` (base included) is the settings route. */
-export const isSettingsPath = (pathname: string) => {
- const path = toBaseRelative(pathname);
- return path === SETTINGS_PATH || path.startsWith(`${SETTINGS_PATH}/`);
-};
-
/**
* Drop a settings split from a split-layout path, if present. Handles both the
* URL encoding (`settings/<tab>`) and the legacy internal form
diff --git a/js/app/packages/core/constant/settingsPath.ts b/js/app/packages/core/constant/settingsPath.ts
new file mode 100644
index 0000000000..a2c962da8b
--- /dev/null
+++ b/js/app/packages/core/constant/settingsPath.ts
@@ -0,0 +1,23 @@
+import { ROUTER_BASE } from '@app/constants/routerBase';
+
+export const SETTINGS_PATH = '/settings';
+
+/**
+ * Strip the router base from a `location.pathname` (which includes it, e.g.
+ * `/app/settings`) so it can be compared to — and reused with — the
+ * base-relative paths that `navigate()` and route definitions use.
+ */
+export const toBaseRelative = (pathname: string) => {
+ if (ROUTER_BASE === '/') return pathname;
+ if (pathname === ROUTER_BASE) return '/';
+ if (pathname.startsWith(`${ROUTER_BASE}/`)) {
+ return pathname.slice(ROUTER_BASE.length);
+ }
+ return pathname;
+};
+
+/** Whether a `location.pathname` (base included) is the settings route. */
+export const isSettingsPath = (pathname: string) => {
+ const path = toBaseRelative(pathname);
+ return path === SETTINGS_PATH || path.startsWith(`${SETTINGS_PATH}/`);
+};