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(multi-select): return focus after delete modal close, better conditional checking (#228)

Seamus576a4d8d3232
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 29df46e91e..42ee6c8c00 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -1,4 +1,5 @@
import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import { HotkeyTags } from '@core/hotkey/constants';
import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';
import { TOKENS } from '@core/hotkey/tokens';
import type { ValidHotkey } from '@core/hotkey/types';
@@ -11,6 +12,7 @@ import {
import { filterMap } from '@core/util/list';
import { isErr } from '@core/util/maybeResult';
import { getScrollParent } from '@core/util/scrollParent';
+import { waitForFrames } from '@core/util/sleep';
import type { EntityData } from '@macro-entity';
import { useTutorialCompleted } from '@service-gql/client';
import { storageServiceClient } from '@service-storage/client';
@@ -272,6 +274,28 @@ export function createNavigationEntityListShortcut({
if (next !== null) {
setViewDataStore(selectedView(), 'selectedEntity', next);
setViewDataStore(selectedView(), 'highlightedId', next.id);
+ const nextIndex = entities()?.findIndex(
+ ({ id }) => id === next.id
+ );
+ if (nextIndex !== undefined && nextIndex > -1) {
+ virtualizerHandle()?.scrollToIndex(nextIndex, {
+ align: 'nearest',
+ });
+ waitForFrames(2).then(() => {
+ const elem = getEntityElAtIndex(nextIndex);
+ if (elem instanceof HTMLElement) {
+ elem.focus();
+ return;
+ // cooked state (no focus returned)
+ }
+ });
+ } else {
+ const firstIndex = virtualizerHandle()?.findStartIndex();
+ if (!firstIndex) return;
+ const elem = getEntityElAtIndex(firstIndex);
+ if (elem instanceof HTMLElement) elem.focus();
+ // cooked state (no focus returned)
+ }
}
},
});
@@ -400,6 +424,12 @@ export function createNavigationEntityListShortcut({
};
});
+ // the full info with indices and neighbors is great but we also need to
+ // flatten back to the plain entities a lot - so just memoize.
+ const plainSelectedEntities = createLazyMemo(() => {
+ return getEntitiesForAction().entities.map(({ entity }) => entity);
+ });
+
const isEntityLastItem = createLazyMemo(() => {
const entityList = entities();
if (!entityList) return false;
@@ -809,7 +839,6 @@ export function createNavigationEntityListShortcut({
description: 'Top',
keyDownHandler: () => {
navigateThroughList({ axis: 'start', mode: 'jump' });
-
return true;
},
});
@@ -944,7 +973,9 @@ export function createNavigationEntityListShortcut({
hotkey: ['e'],
scopeId: entityHotkeyScope,
description: 'Mark done',
- condition: isViewingList,
+ condition: () =>
+ isViewingList() &&
+ !actionRegistry.isActionDisabled('mark_as_done', plainSelectedEntities()),
keyDownHandler: () => {
const entitiesForAction = getEntitiesForAction();
if (entitiesForAction.entities.length === 0) {
@@ -966,7 +997,7 @@ export function createNavigationEntityListShortcut({
return true;
},
displayPriority: 10,
- tags: ['selection-modification'],
+ tags: [HotkeyTags.SelectionModification],
});
registerHotkey({
hotkey: ['x'],
@@ -997,7 +1028,9 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
description: () =>
viewData().selectedEntities.length > 1 ? 'Delete items' : 'Delete item',
- condition: isViewingList,
+ condition: () =>
+ isViewingList() &&
+ !actionRegistry.isActionDisabled('delete', plainSelectedEntities()),
keyDownHandler: () => {
const entitiesForAction = getEntitiesForAction();
if (entitiesForAction.entities.length === 0) {
@@ -1009,7 +1042,8 @@ export function createNavigationEntityListShortcut({
);
return true;
},
- tags: ['selection-modification'],
+ tags: [HotkeyTags.SelectionModification],
+ displayPriority: 10,
});
createEffect(() => {
diff --git a/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx b/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx
index 6b5c4da1c0..e2cb15c45d 100644
--- a/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx
+++ b/js/app/packages/app/component/bulk-edit-entity/BulkEditEntityModal.tsx
@@ -12,7 +12,7 @@ import { BulkDeleteView } from './BulkDeleteView';
import { BulkRenameEntitiesView } from './BulkRenameEntitiesView';
export const BulkEditEntityModalTitle = (props: { title: string }) => {
- return <h2 class="text-lg mb-3">{props.title}</h2>;
+ return <h2 class="text-xl mb-3">{props.title}</h2>;
};
export const BulkEditEntityModalActionFooter = (props: {
diff --git a/js/app/packages/app/component/command/KonsoleItem.tsx b/js/app/packages/app/component/command/KonsoleItem.tsx
index 5497f00e8a..d3d413d978 100644
--- a/js/app/packages/app/component/command/KonsoleItem.tsx
+++ b/js/app/packages/app/component/command/KonsoleItem.tsx
@@ -10,6 +10,7 @@ import { Message } from '@core/component/Message';
import { UserIcon } from '@core/component/UserIcon';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { ENABLE_GMAIL_BASED_CONTACTS } from '@core/constant/featureFlags';
+import { HotkeyTags } from '@core/hotkey/constants';
import {
type CommandWithInfo,
getActiveCommandsFromScope,
@@ -453,7 +454,7 @@ export function filterItemByCategory(item: CommandItemCard) {
currentKonsoleMode() === 'SELECTION_MODIFICATION' &&
item.type === 'command'
) {
- return item.data.tags?.includes('selection-modification');
+ return item.data.tags?.includes(HotkeyTags.SelectionModification);
}
return false;
}
diff --git a/js/app/packages/core/hotkey/constants.ts b/js/app/packages/core/hotkey/constants.ts
index 0233231a3a..b020987a40 100644
--- a/js/app/packages/core/hotkey/constants.ts
+++ b/js/app/packages/core/hotkey/constants.ts
@@ -185,3 +185,11 @@ export const MODIFIER_LIST_MAC = [
] as const;
export const MODIFIER_LIST_NON_MAC = ['ctrlKey', 'altKey', 'shiftKey'] as const;
+
+// Hotkey tags are for sorting and filtering hotkeys in the command menu (and
+// other similar systems).
+export const HotkeyTags = {
+ // SelectionModification tag is for commands that apply to the current
+ // selected items - like 'delete items' or what have you.
+ SelectionModification: 'selection-modification',
+} as const;
diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.ts
index 7b78f9fe2e..12aed5fa62 100644
--- a/js/app/packages/core/hotkey/hotkeys.ts
+++ b/js/app/packages/core/hotkey/hotkeys.ts
@@ -121,7 +121,6 @@ export function registerHotkey(
icon,
tags,
} = args;
- ``;
if (!scopeId) {
logger.error('Scope ID is required for hotkey registration.', {
diff --git a/js/app/packages/core/util/sleep.ts b/js/app/packages/core/util/sleep.ts
index 71030181ee..01a0e8f97f 100644
--- a/js/app/packages/core/util/sleep.ts
+++ b/js/app/packages/core/util/sleep.ts
@@ -5,3 +5,11 @@ export function sleep(timeout: number) {
}, timeout);
});
}
+
+export async function waitForFrames(n: number) {
+ for (let i = 0; i < n; i++) {
+ await new Promise<void>((resolve) =>
+ requestAnimationFrame(() => resolve())
+ );
+ }
+}