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(soup): hotkeys registered to split aren't disposed when closing soup (#1681)

dev-rbac6a8c48c155
diff --git a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
index bf94997daa..6a41d480fa 100644
--- a/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
+++ b/js/app/packages/app/component/next-soup/actions/use-entity-action-hotkeys.ts
@@ -14,9 +14,10 @@ import {
} from './index';
import { isShareableEntityType } from '@app/component/global-share-modal/GlobalShareModal';
import { useUserId } from '@core/context/user';
-import { registerHotkey } from '@core/hotkey/hotkeys';
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
import type { SplitHandle } from '@app/component/split-layout/layoutManager';
import { openEntityInSplitFromUnifiedList } from '@app/component/next-soup/utils';
+import { onCleanup } from 'solid-js';
type UseEntityActionHotkeysOptions = {
scopeId: string;
@@ -69,6 +70,8 @@ export const useEntityActionHotkeys = (
openEntityInSplitFromUnifiedList(entity, { splitHandle });
};
+ const group = createHotkeyGroup();
+
// Mark Done - 'e'
registerHotkey({
hotkey: ['e'],
@@ -90,7 +93,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
// Delete - 'delete', 'backspace'
registerHotkey({
@@ -116,7 +119,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
// Rename - 'r'
registerHotkey({
@@ -142,7 +145,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
// Copy - 'cmd+d'
registerHotkey({
@@ -168,7 +171,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
// Move to folder - 'm'
registerHotkey({
@@ -194,7 +197,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
// Copy link - 'shift+cmd+c'
registerHotkey({
@@ -216,8 +219,9 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
+ // Share
registerHotkey({
hotkeyToken: TOKENS.entity.action.share,
scopeId,
@@ -236,5 +240,7 @@ export const useEntityActionHotkeys = (
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
- });
+ }).withGroup(group);
+
+ onCleanup(() => group.dispose());
};
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 dddc79711b..b12edb6796 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
@@ -269,11 +269,15 @@ export const SoupViewList = (props: SoupViewListProps) => {
});
// Property editor
- usePropertyEditorHotkeys({
+ const propertyHotkeys = usePropertyEditorHotkeys({
scopeId: scopeId(),
soup,
});
+ onCleanup(() => {
+ propertyHotkeys.disposeHotkeys();
+ });
+
// Register soup view hotkeys (jump navigation, enter, escape, cmd+k, etc.)
useSoupViewHotkeys({
splitId: panel.handle.id,
diff --git a/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts b/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts
index c995f7444b..3c81bc46b8 100644
--- a/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/use-soup-navigation-hotkeys.ts
@@ -1,9 +1,9 @@
import { TOKENS } from '@core/hotkey/tokens';
import type { VirtualizerHandle } from 'virtua/solid';
-import type { Accessor } from 'solid-js';
+import { onCleanup, type Accessor } from 'solid-js';
import type { SoupState } from '../create-soup-state';
import { useMaybePreviewPanel } from '@app/component/PreviewPanel';
-import { registerHotkey } from '@core/hotkey/hotkeys';
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
import type { SplitHandle } from '@app/component/split-layout/layoutManager';
import { openEntityInSplitFromUnifiedList } from '@app/component/next-soup/utils';
import type { EntityData } from '@entity';
@@ -107,44 +107,66 @@ export const useSoupNavigationHotkeys = (
return true;
};
- // Navigate down - 'j', 'arrowdown'
+ const group = createHotkeyGroup();
+
+ const navigateDown = () => {
+ const next = soup.navigate.down();
+
+ if (!next) return true;
+
+ scrollTo(next.index);
+ openEntity(next.item);
+
+ return true;
+ };
+
+ const navigateUp = () => {
+ const next = soup.navigate.up();
+
+ if (!next) return true;
+
+ scrollTo(next.index);
+ openEntity(next.item);
+
+ return true;
+ };
+
+ // Used outside soup view, does not need to be disposed
registerHotkey({
- hotkey: ['j', 'arrowdown'],
+ hotkey: ['j'],
scopeId,
description: 'Down',
hotkeyToken: TOKENS.entity.step.end,
- keyDownHandler: () => {
- const next = soup.navigate.down();
-
- if (!next) return true;
-
- scrollTo(next.index);
- openEntity(next.item);
-
- return true;
- },
+ keyDownHandler: navigateDown,
hide: true,
});
- // Navigate up - 'k', 'arrowup'
registerHotkey({
- hotkey: ['k', 'arrowup'],
+ hotkey: ['arrowdown'],
+ scopeId,
+ description: 'Down',
+ keyDownHandler: navigateDown,
+ hide: true,
+ }).withGroup(group);
+
+ // Used outside soup view, does not need to be disposed
+ registerHotkey({
+ hotkey: ['k'],
scopeId,
hotkeyToken: TOKENS.entity.step.start,
description: 'Up',
- keyDownHandler: () => {
- const next = soup.navigate.up();
-
- if (!next) return true;
-
- scrollTo(next.index);
- openEntity(next.item);
-
- return true;
- },
+ keyDownHandler: navigateUp,
hide: true,
});
+ registerHotkey({
+ hotkey: ['arrowup'],
+ scopeId,
+ description: 'Up',
+ keyDownHandler: navigateUp,
+ hide: true,
+ }).withGroup(group);
+
// Select up - 'shift+arrowup', 'shift+k'
registerHotkey({
hotkey: ['shift+arrowup', 'shift+k'],
@@ -155,7 +177,7 @@ export const useSoupNavigationHotkeys = (
return handleNavigationSelection(-1);
},
hide: true,
- });
+ }).withGroup(group);
// Select down - 'shift+arrowdown', 'shift+j'
registerHotkey({
@@ -167,7 +189,7 @@ export const useSoupNavigationHotkeys = (
return handleNavigationSelection(1);
},
hide: true,
- });
+ }).withGroup(group);
const previewPanel = useMaybePreviewPanel();
@@ -202,7 +224,7 @@ export const useSoupNavigationHotkeys = (
registrationType: 'add',
handlerPriority: 4,
hide: true,
- });
+ }).withGroup(group);
registerHotkey({
hotkey: ['l', 'arrowright'],
@@ -238,5 +260,7 @@ export const useSoupNavigationHotkeys = (
registrationType: 'add',
handlerPriority: 4,
hide: true,
- });
+ }).withGroup(group);
+
+ onCleanup(() => group.dispose());
};
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.ts
index c039a3a810..a4f504c055 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
@@ -1,7 +1,7 @@
import { CommandState } from '@app/component/command/state';
import type { SplitHandle } from '@app/component/split-layout/layoutManager';
import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';
-import { registerHotkey } from '@core/hotkey/hotkeys';
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
import {
getHotkeyCommand,
@@ -9,7 +9,7 @@ import {
runCommand,
} from '@core/hotkey/utils';
import { isSearchEntity } from '@entity';
-import type { Accessor } from 'solid-js';
+import { onCleanup, type Accessor } from 'solid-js';
import type { VirtualizerHandle } from 'virtua/solid';
import type { SoupState } from '../create-soup-state';
import { openEntityInSplitFromUnifiedList } from '@app/component/next-soup/utils';
@@ -36,6 +36,31 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
const splitIsUnifiedList = () => splitHandle.content().id === 'unified-list';
+ // escape - Multi-purpose: Clear selection / Close spotlight / Close split / Go home
+ const clearMultiCondition = () =>
+ soup.selection.count() > 0 && splitIsUnifiedList();
+ const closeSpotlightCondition = () => splitHandle.isSpotLight();
+ const goHomeCondition = () => !splitIsUnifiedList();
+ const closeSplitCondition = () => splitIsUnifiedList() && getSplitCount() > 1;
+
+ const escapeDescription = () => {
+ if (clearMultiCondition()) {
+ return 'Clear multi selection';
+ }
+ if (closeSpotlightCondition()) {
+ return 'Close spotlight';
+ }
+ if (closeSplitCondition()) {
+ return 'Close split';
+ }
+ if (goHomeCondition()) {
+ return 'Go home';
+ }
+ return '';
+ };
+
+ const group = createHotkeyGroup();
+
// home - Jump to top of list
registerHotkey({
hotkey: ['home'],
@@ -50,7 +75,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
hide: true,
- });
+ }).withGroup(group);
// g g - Jump to top of list (vim-style command scope)
const { commandScopeId } = registerHotkey({
@@ -60,11 +85,11 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
keyDownHandler: () => true,
activateCommandScope: true,
hide: true,
- });
+ }).withGroup(group);
registerHotkey({
hotkey: ['g'],
- scopeId: commandScopeId,
+ scopeId: commandScopeId!,
description: 'Go to top of list',
keyDownHandler: () => {
const next = soup.navigate.toFirst();
@@ -73,7 +98,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
}
return true;
},
- });
+ }).withGroup(group);
// shift+g, end - Jump to bottom of list
registerHotkey({
@@ -89,7 +114,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
hide: true,
- });
+ }).withGroup(group);
// enter - Open entity in split
registerHotkey({
@@ -116,7 +141,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
displayPriority: 4,
- });
+ }).withGroup(group);
// cmd+enter - Focus preview block
registerHotkey({
@@ -169,7 +194,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
displayPriority: 4,
- });
+ }).withGroup(group);
// x - Toggle select item
registerHotkey({
@@ -183,7 +208,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
displayPriority: 10,
- });
+ }).withGroup(group);
// cmd+k - Open command menu with selection context
// When there's a selection, opens in entity action mode showing only
@@ -211,30 +236,9 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
displayPriority: 10,
hide: CommandState.isOpen,
runWithInputFocused: true,
- });
+ }).withGroup(group);
// escape - Multi-purpose: Clear selection / Close spotlight / Close split / Go home
- const clearMultiCondition = () => soup.selection.count() > 0;
- const closeSpotlightCondition = () => splitHandle.isSpotLight();
- const goHomeCondition = () => !splitIsUnifiedList();
- const closeSplitCondition = () => splitIsUnifiedList() && getSplitCount() > 1;
-
- const escapeDescription = () => {
- if (clearMultiCondition()) {
- return 'Clear multi selection';
- }
- if (closeSpotlightCondition()) {
- return 'Close spotlight';
- }
- if (closeSplitCondition()) {
- return 'Close split';
- }
- if (goHomeCondition()) {
- return 'Go home';
- }
- return '';
- };
-
registerHotkey({
hotkey: ['escape'],
scopeId,
@@ -269,6 +273,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
},
});
+ // shift+enter - Open in new split
registerHotkey({
hotkey: ['shift+enter'],
scopeId,
@@ -284,5 +289,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
return true;
},
hide: true,
- });
+ }).withGroup(group);
+
+ onCleanup(() => group.dispose());
};
diff --git a/js/app/packages/app/component/property-edit-modal/hooks/usePropertyEditorHotkeys.ts b/js/app/packages/app/component/property-edit-modal/hooks/usePropertyEditorHotkeys.ts
index ab5e6cc050..5932bc68db 100644
--- a/js/app/packages/app/component/property-edit-modal/hooks/usePropertyEditorHotkeys.ts
+++ b/js/app/packages/app/component/property-edit-modal/hooks/usePropertyEditorHotkeys.ts
@@ -1,4 +1,4 @@
-import { registerHotkey } from 'core/hotkey/hotkeys';
+import { createHotkeyGroup, registerHotkey } from 'core/hotkey/hotkeys';
import { openPropertyEditor } from '../state/propertyEditor';
import type {
Property,
@@ -56,6 +56,8 @@ export function usePropertyEditorHotkeys(options: PropertyEditorHotkeyOptions) {
}
};
+ const group = createHotkeyGroup();
+
// Open property selector - shift+cmd+o
registerHotkey({
hotkey: ['shift+cmd+o'],
@@ -72,7 +74,7 @@ export function usePropertyEditorHotkeys(options: PropertyEditorHotkeyOptions) {
return entities.length > 0 && entities.every(isTaskEntity);
},
scopeId,
- });
+ }).withGroup(group);
// Set priority - shift+cmd+p
registerHotkey({
@@ -94,7 +96,7 @@ export function usePropertyEditorHotkeys(options: PropertyEditorHotkeyOptions) {
);
},
scopeId,
- });
+ }).withGroup(group);
// Set assignee - shift+cmd+a
registerHotkey({
@@ -116,7 +118,7 @@ export function usePropertyEditorHotkeys(options: PropertyEditorHotkeyOptions) {
);
},
scopeId,
- });
+ }).withGroup(group);
// Set status - shift+cmd+s
registerHotkey({
@@ -136,9 +138,10 @@ export function usePropertyEditorHotkeys(options: PropertyEditorHotkeyOptions) {
);
},
scopeId,
- });
+ }).withGroup(group);
return {
openPropertyEditor: openIfSelected,
+ disposeHotkeys: group.dispose,
};
}
diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.ts
index 645f9fde5d..e188b66ae4 100644
--- a/js/app/packages/core/hotkey/hotkeys.ts
+++ b/js/app/packages/core/hotkey/hotkeys.ts
@@ -24,6 +24,7 @@ import {
import {
HOTKEY_PRIORITY_DEFAULT,
type HotkeyCommand,
+ type HotkeyGroup,
type HotkeyRegistrationOptions,
isBaseKeyboardValue,
type KeypressContext,
@@ -124,13 +125,20 @@ export function registerHotkey(
shouldReturnFocusOnClose,
} = args;
+ const noopDisposer: RegisterHotkeyReturn = {
+ dispose: () => {},
+ withGroup: (group) => {
+ group.add(noopDisposer);
+ return noopDisposer;
+ },
+ };
+
if (!scopeId) {
logger.error('Scope ID is required for hotkey registration.', {
error: new Error('No scope ID provided'),
scopeId,
});
- // Return a no-op disposer
- return { dispose: () => {} };
+ return noopDisposer;
}
const scopeNode = hotkeyScopeTree.get(scopeId);
if (!scopeNode) {
@@ -138,7 +146,7 @@ export function registerHotkey(
error: new Error('Scope ID not found'),
scopeId,
});
- return { dispose: () => {} };
+ return noopDisposer;
}
// Convert single hotkey to array for consistent handling
@@ -275,11 +283,76 @@ export function registerHotkey(
}
},
commandScopeId,
+ withGroup: (group) => {
+ group.add(disposer);
+ return disposer;
+ },
};
return disposer;
}
+/**
+ * Creates a group for collecting hotkey registrations and disposing them all at once.
+ *
+ * @returns A group object with `add` and `dispose` methods
+ *
+ * @example
+ * ```tsx
+ * const group = createHotkeyGroup();
+ *
+ * // Add registrations using group.add()
+ * group.add(registerHotkey({
+ * scopeId: 'my-scope',
+ * description: 'Delete item',
+ * hotkey: 'delete',
+ * keyDownHandler: () => true,
+ * }));
+ *
+ * // Or use .withGroup() on the registration
+ * registerHotkey({
+ * scopeId: 'my-scope',
+ * description: 'Copy item',
+ * hotkey: 'cmd+c',
+ * keyDownHandler: () => true,
+ * }).withGroup(group);
+ *
+ * // Access commandScopeId naturally
+ * const { commandScopeId } = group.add(registerHotkey({
+ * scopeId: 'my-scope',
+ * description: 'Open menu',
+ * hotkey: 'cmd+k',
+ * activateCommandScope: true,
+ * keyDownHandler: () => true,
+ * }));
+ *
+ * group.add(registerHotkey({
+ * scopeId: commandScopeId,
+ * description: 'Menu option',
+ * hotkey: '1',
+ * keyDownHandler: () => true,
+ * }));
+ *
+ * // Dispose all at once
+ * onCleanup(() => group.dispose());
+ * ```
+ */
+export function createHotkeyGroup(): HotkeyGroup {
+ const registrations: RegisterHotkeyReturn[] = [];
+
+ return {
+ add: <T extends RegisterHotkeyReturn>(registration: T): T => {
+ registrations.push(registration);
+ return registration;
+ },
+ dispose: () => {
+ for (const registration of registrations) {
+ registration.dispose();
+ }
+ },
+ };
+}
+
// Variables for tracking event propagation
let scopeActivatedByFocusIn = false;
diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.ts
index afcd41d609..da1f793e86 100644
--- a/js/app/packages/core/hotkey/types.ts
+++ b/js/app/packages/core/hotkey/types.ts
@@ -154,9 +154,18 @@ export interface HotkeyRegistrationOptions {
shouldReturnFocusOnClose?: boolean;
}
+export type HotkeyGroup = {
+ /** Add a hotkey registration to this group */
+ add: <T extends RegisterHotkeyReturn>(registration: T) => T;
+ /** Dispose all hotkeys in this group */
+ dispose: () => void;
+};
+
export type RegisterHotkeyReturn = {
dispose: () => void;
commandScopeId?: string;
+ /** Add this registration to a group for grouped disposal */
+ withGroup: (group: HotkeyGroup) => RegisterHotkeyReturn;
};
export type ScopeNodeBase = {