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.

feat(web): add detail list hotkeys (#6504)

dev-rbea9118c211e7
diff --git a/apps/web/src/components/entity-detail/use-list-navigation-hotkeys.ts b/apps/web/src/components/entity-detail/use-list-navigation-hotkeys.ts
new file mode 100644
index 0000000000..2c8483355b
--- /dev/null
+++ b/apps/web/src/components/entity-detail/use-list-navigation-hotkeys.ts
@@ -0,0 +1,40 @@
+import type { ListDetailNavigationTarget } from '@app/components/list';
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
+import { type Accessor, onCleanup } from 'solid-js';
+
+export function useListNavigationHotkeys(options: {
+ scopeId: string;
+ enabled: Accessor<boolean>;
+ navigation: ListDetailNavigationTarget;
+}) {
+ const group = createHotkeyGroup();
+
+ registerHotkey({
+ hotkey: 'j',
+ hotkeyToken: TOKENS.entity.step.end,
+ scopeId: options.scopeId,
+ description: 'Next item',
+ condition: () => options.enabled() && options.navigation.canNext(),
+ keyDownHandler: () => {
+ options.navigation.next();
+ return true;
+ },
+ hide: true,
+ }).withGroup(group);
+
+ registerHotkey({
+ hotkey: 'k',
+ hotkeyToken: TOKENS.entity.step.start,
+ scopeId: options.scopeId,
+ description: 'Previous item',
+ condition: () => options.enabled() && options.navigation.canPrevious(),
+ keyDownHandler: () => {
+ options.navigation.previous();
+ return true;
+ },
+ hide: true,
+ }).withGroup(group);
+
+ onCleanup(() => group.dispose());
+}
diff --git a/apps/web/src/components/list/index.ts b/apps/web/src/components/list/index.ts
index a7437e0068..ed5c55c2f7 100644
--- a/apps/web/src/components/list/index.ts
+++ b/apps/web/src/components/list/index.ts
@@ -34,6 +34,12 @@ export type {
ListNavigationOptions,
ListRestoreFocusOptions,
} from './types';
+export {
+ type ListDetailNavigation,
+ type ListDetailNavigationOptions,
+ type ListDetailNavigationTarget,
+ useListDetailNavigation,
+} from './use-list-detail-navigation';
export {
type ListInteractionActivation,
type ListInteractionActivationIntent,
diff --git a/apps/web/src/components/list/use-list-detail-navigation.ts b/apps/web/src/components/list/use-list-detail-navigation.ts
new file mode 100644
index 0000000000..895fc5dcbc
--- /dev/null
+++ b/apps/web/src/components/list/use-list-detail-navigation.ts
@@ -0,0 +1,148 @@
+import { type Accessor, createSignal, onCleanup } from 'solid-js';
+import type { ListDataSource } from './list-data-source';
+
+export type ListDetailNavigationTarget = {
+ canPrevious: Accessor<boolean>;
+ canNext: Accessor<boolean>;
+ previous: () => void;
+ next: () => void;
+};
+
+export type ListDetailNavigationOptions<TEntity> = {
+ fallbackDirection?: -1 | 1;
+ beforeOpen?: (
+ next: TEntity | undefined,
+ current: TEntity | undefined
+ ) => boolean | void;
+};
+
+export type ListDetailNavigation<TEntity> = ListDetailNavigationTarget & {
+ navigate: (
+ direction: -1 | 1,
+ options?: ListDetailNavigationOptions<TEntity>
+ ) => Promise<void>;
+ open: (entity: TEntity) => void;
+};
+
+type NavigationStep<TEntity> =
+ | { kind: 'entity'; entity: TEntity }
+ | { kind: 'continuation'; load: () => Promise<unknown> };
+
+export function useListDetailNavigation<
+ TItem,
+ TEntity extends { id: string },
+>(options: {
+ currentId: Accessor<string>;
+ source: Pick<
+ ListDataSource<TItem>,
+ 'items' | 'hasMore' | 'loadMore' | 'error'
+ >;
+ getEntity: (item: TItem) => TEntity | undefined;
+ getContinuation?: (item: TItem) => (() => Promise<unknown>) | undefined;
+ open: (entity: TEntity) => void;
+ onError?: (error: unknown) => void;
+}): ListDetailNavigation<TEntity> {
+ const [navigating, setNavigating] = createSignal(false);
+ let disposed = false;
+
+ onCleanup(() => {
+ disposed = true;
+ });
+
+ const isCurrent = (id: string) => !disposed && options.currentId() === id;
+ const currentEntity = () =>
+ options.source
+ .items()
+ .map(options.getEntity)
+ .find((entity) => entity?.id === options.currentId());
+
+ const target = (direction: -1 | 1): NavigationStep<TEntity> | undefined => {
+ const items = options.source.items();
+ const currentIndex = items.findIndex(
+ (item) => options.getEntity(item)?.id === options.currentId()
+ );
+ if (currentIndex === -1) return;
+
+ for (
+ let index = currentIndex + direction;
+ index >= 0 && index < items.length;
+ index += direction
+ ) {
+ const item = items[index];
+ if (!item) continue;
+
+ const entity = options.getEntity(item);
+ if (entity) return { kind: 'entity', entity };
+
+ const load =
+ direction === 1 ? options.getContinuation?.(item) : undefined;
+ if (load) return { kind: 'continuation', load };
+ }
+
+ if (direction === 1 && options.source.hasMore()) {
+ return { kind: 'continuation', load: options.source.loadMore };
+ }
+ };
+
+ const resolve = async (
+ direction: -1 | 1,
+ currentId: string
+ ): Promise<TEntity | undefined> => {
+ while (isCurrent(currentId)) {
+ const step = target(direction);
+ if (!step) return;
+ if (step.kind === 'entity') return step.entity;
+
+ await step.load();
+ if (!isCurrent(currentId)) return;
+
+ const error = options.source.error();
+ if (error) throw error;
+ }
+ };
+
+ const open = (entity: TEntity) => {
+ if (!disposed) options.open(entity);
+ };
+
+ const navigate = async (
+ direction: -1 | 1,
+ navigationOptions: ListDetailNavigationOptions<TEntity> = {}
+ ) => {
+ if (disposed || navigating()) return;
+ setNavigating(true);
+ const currentId = options.currentId();
+ const current = currentEntity();
+
+ try {
+ let next = await resolve(direction, currentId);
+ if (
+ !next &&
+ navigationOptions.fallbackDirection !== undefined &&
+ isCurrent(currentId)
+ ) {
+ next = await resolve(navigationOptions.fallbackDirection, currentId);
+ }
+ if (!isCurrent(currentId)) return;
+ if (navigationOptions.beforeOpen?.(next, current) === false) return;
+ if (next) open(next);
+ } catch (error) {
+ if (isCurrent(currentId)) options.onError?.(error);
+ } finally {
+ setNavigating(false);
+ }
+ };
+
+ return {
+ canPrevious: () => !navigating() && target(-1)?.kind === 'entity',
+ canNext: () => !navigating() && target(1) !== undefined,
+ previous: () => {
+ void navigate(-1);
+ },
+ next: () => {
+ void navigate(1);
+ },
+ navigate,
+ open,
+ };
+}
diff --git a/apps/web/src/features/email-view/components/EmailDetailView.tsx b/apps/web/src/features/email-view/components/EmailDetailView.tsx
index 4f6a8f212d..5fb682857d 100644
--- a/apps/web/src/features/email-view/components/EmailDetailView.tsx
+++ b/apps/web/src/features/email-view/components/EmailDetailView.tsx
@@ -1,4 +1,5 @@
import { useEntityDetailNavigationStack } from '@app/components/entity-detail/EntityDetailNavigationStack';
+import { useListNavigationHotkeys } from '@app/components/entity-detail/use-list-navigation-hotkeys';
import { ViewBreadcrumbs } from '@app/components/view-shell';
import { displaySubject } from '@app/features/email-compose/core/subject-text';
import type { EmailThreadHost } from '@app/features/email-thread/context/email-thread-context';
@@ -145,6 +146,13 @@ export function EmailDetailView(props: { thread: EmailThreadTarget }) {
entry.data.type === 'email' && entry.data.id === props.thread.id
);
const breadcrumbValue = () => threadEntry()?.value ?? 'email-view';
+ useListNavigationHotkeys({
+ scopeId: panel.splitHotkeyScope,
+ enabled: () =>
+ panel.isPanelActive() &&
+ navigationStack.active()?.value === breadcrumbValue(),
+ navigation: listNavigation,
+ });
const loadResult = {
data: threadData,
error: () =>
diff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsx
index 920d71476e..1b4e578182 100644
--- a/apps/web/src/features/email-view/components/EmailList.tsx
+++ b/apps/web/src/features/email-view/components/EmailList.tsx
@@ -1,10 +1,5 @@
import '@entity/composed/ListEntity.css';
-import {
- createListController,
- type ListActivation,
- listOwnedSlotName,
- useListInteractions,
-} from '@app/components/list';
+import { type ListActivation, useListInteractions } from '@app/components/list';
import {
resolveEntityActionViewContext,
toEntityActionListState,
@@ -14,17 +9,13 @@ import {
createSoupEntityActions,
MaybeSoupEntityActionDrawerManager,
SoupEntityContextMenu,
- useSoupListNavigationHotkeys,
viewedProjectIdFromContent,
} from '@app/features/soup';
import { DEBUG_SETTING_KEYS, useDebugSetting } from '@app/lib/debugSettings';
import { makePersistedState } from '@app/lib/persistence';
import { PullToRefresh } from '@components/app/mobile/PullToRefresh';
import { SwipableRowProvider } from '@components/app/mobile/SwipableRow';
-import {
- useSplitPanelOrThrow,
- withSplitPanelOwner,
-} from '@components/app/split-layout/layoutUtils';
+import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import {
type EntityData,
@@ -56,7 +47,10 @@ import {
soupNavigationTouchHighlight,
} from '../../next-soup/soup-view/soup-navigation-touch-highlight';
import { openEntityInSplitFromUnifiedList } from '../../next-soup/utils';
-import { useEmailView } from '../email-view-context';
+import {
+ type EmailListActivationMetadata,
+ useEmailView,
+} from '../email-view-context';
import {
createEmailListEntryStorage,
DEFAULT_EMAIL_LIST_STATE,
@@ -72,18 +66,13 @@ type EmailActionRow = {
rowId: string;
};
-type EmailListActivationMetadata = {
- event?: MouseEvent;
- newSplit?: boolean;
-};
-
export type EmailListProps = {
/** The focusable list root, for callers that hand keyboard focus back. */
ref?: (element: HTMLDivElement) => void;
};
export function EmailList(props: EmailListProps) {
- const { state, source, listFocusTarget, clearListFocusTarget, openThread } =
+ const { state, source, list, registerListActivationHandler, openThread } =
useEmailView();
const panel = useSplitPanelOrThrow();
@@ -155,43 +144,7 @@ export function EmailList(props: EmailListProps) {
});
}
- const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>
- createListController<EmailDataSourceItem, EmailListActivationMetadata>({
- items: source.items,
- getKey: (row) => row.id,
- selection: {
- getKey: (row) => (row.kind === 'entity' ? row.entity.id : row.id),
- },
- isNavigable: (row) => row.kind === 'entity' || row.kind === 'load-more',
- isSelectable: (row) => row.kind === 'entity',
- onActivate,
- })
- );
-
- createEffect(() => {
- const target = listFocusTarget();
- if (!target) return;
- const row = source
- .items()
- .find((item) => item.kind === 'entity' && item.entity.id === target);
- if (!row) return;
- list.focus.set(row.id, { reason: 'programmatic', force: true });
- list.selection.setAnchor(row.id);
- clearListFocusTarget();
- });
-
- withSplitPanelOwner(listOwnedSlotName('navigation-hotkeys'), () => {
- useSoupListNavigationHotkeys({
- splitHotkeyScope: panel.splitHotkeyScope,
- viewId: 'mail',
- dataSource: source,
- controller: list,
- handle: panel.handle,
- openEntityInSplit: (entity, options) => {
- openEntity(entity, { mergeHistory: options.mergeHistory });
- },
- });
- });
+ registerListActivationHandler(onActivate);
const { buildActionGroups } = createSoupEntityActions();
const entityActionViewContext = () =>
@@ -221,7 +174,9 @@ export function EmailList(props: EmailListProps) {
const current = readListState();
const value = typeof next === 'function' ? next(current) : next;
- if (value.focusKey !== current.focusKey) {
+ // The view-owned controller survives inline detail navigation. Restore
+ // persisted focus only on a cold mount that has no live focus to preserve.
+ if (current.focusKey === undefined && value.focusKey !== undefined) {
list.focus.restore(value.focusKey, { reason: 'restore' });
}
diff --git a/apps/web/src/features/email-view/email-view-context.tsx b/apps/web/src/features/email-view/email-view-context.tsx
index 7e97819877..5b89b91a68 100644
--- a/apps/web/src/features/email-view/email-view-context.tsx
+++ b/apps/web/src/features/email-view/email-view-context.tsx
@@ -2,10 +2,16 @@ import {
createEntityDetailTarget,
useEntityDetailNavigationStack,
} from '@app/components/entity-detail/EntityDetailNavigationStack';
-import { listOwnedSlotName } from '@app/components/list';
+import {
+ createListController,
+ type ListActivation,
+ type ListController,
+ listOwnedSlotName,
+} from '@app/components/list';
import { setSidebarSectionCollapsed } from '@app/components/view-shell';
import { registerInboxFilterSplit } from '@app/features/next-soup/soup-view/inbox-filter-controllers';
import { normalizeFacetSelection } from '@app/features/soup';
+import { registerListNavigationSource } from '@app/features/soup/collection/list-navigation-source';
import { makePersistedState } from '@app/lib/persistence';
import { usePreference } from '@app/lib/preferences/use-preference';
import {
@@ -16,7 +22,7 @@ import { createAssertedContextProvider } from '@core/context/createContext';
import { useUserId } from '@core/context/user';
import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';
import type { ContextProviderProps } from '@solid-primitives/context';
-import { type Accessor, createSignal, onCleanup, type Setter } from 'solid-js';
+import { type Accessor, onCleanup, type Setter } from 'solid-js';
import {
createStore,
produce,
@@ -28,6 +34,7 @@ import { DEFAULT_EMAIL_TAB } from './constants';
import { createEmailViewPersistence } from './persistence';
import {
type EmailDataSource,
+ type EmailDataSourceItem,
useEmailDataSource,
} from './queries/use-email-query';
import type {
@@ -41,6 +48,16 @@ type EmailViewProviderProps = ContextProviderProps & {
initialState?: EmailViewStateOptions;
};
+export type EmailListActivationMetadata = {
+ event?: MouseEvent;
+ newSplit?: boolean;
+};
+
+type EmailListController = ListController<
+ EmailDataSourceItem,
+ EmailListActivationMetadata
+>;
+
export type EmailViewContext = {
state: Store<EmailViewState>;
setState: SetStoreFunction<EmailViewState>;
@@ -53,9 +70,16 @@ export type EmailViewContext = {
*/
showTags: (tagIds: string[]) => void;
source: EmailDataSource;
+ list: EmailListController;
+ registerListActivationHandler: (
+ handler: (
+ activation: ListActivation<
+ EmailDataSourceItem,
+ EmailListActivationMetadata
+ >
+ ) => void
+ ) => void;
selectedThread: Accessor<EmailThreadTarget | undefined>;
- listFocusTarget: Accessor<string | undefined>;
- clearListFocusTarget: () => void;
openThread: (thread: EmailThreadTarget) => void;
closeThread: () => void;
isSidebarSectionOpen: (id: string) => boolean;
@@ -108,7 +132,49 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>
useEmailDataSource(state, { tagSets, tagSetsReady })
);
- const [listFocusTarget, setListFocusTarget] = createSignal<string>();
+ withSplitPanelOwner(listOwnedSlotName('navigation-source'), () =>
+ registerListNavigationSource(panel.handle, {
+ viewId: 'mail',
+ entities: () =>
+ source
+ .items()
+ .flatMap((row) => (row.kind === 'entity' ? [row.entity] : [])),
+ hasMore: source.hasMore,
+ loadMore: async () => {
+ await source.loadMore();
+ const error = source.error();
+ if (error) throw error;
+ },
+ })
+ );
+ let listActivationHandler:
+ | ((
+ activation: ListActivation<
+ EmailDataSourceItem,
+ EmailListActivationMetadata
+ >
+ ) => void)
+ | undefined;
+ const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>
+ createListController<EmailDataSourceItem, EmailListActivationMetadata>({
+ items: source.items,
+ getKey: (row) => row.id,
+ selection: {
+ getKey: (row) => (row.kind === 'entity' ? row.entity.id : row.id),
+ },
+ isNavigable: (row) => row.kind === 'entity' || row.kind === 'load-more',
+ isSelectable: (row) => row.kind === 'entity',
+ onActivate: (activation) => listActivationHandler?.(activation),
+ })
+ );
+ const registerListActivationHandler = (
+ handler: NonNullable<typeof listActivationHandler>
+ ) => {
+ listActivationHandler = handler;
+ onCleanup(() => {
+ if (listActivationHandler === handler) listActivationHandler = undefined;
+ });
+ };
const selectedThread = (): EmailThreadTarget | undefined => {
const entry = navigationStack.entries.find(
@@ -122,7 +188,14 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
};
const openThread = (thread: EmailThreadTarget) => {
- setListFocusTarget(thread.id);
+ const row = source
+ .items()
+ .find((item) => item.kind === 'entity' && item.entity.id === thread.id);
+ if (row) {
+ list.focus.set(row.id, { reason: 'programmatic', force: true });
+ list.selection.setAnchor(row.id);
+ }
+
setState('openThreadId', thread.id);
navigationStack.reset(
createEntityDetailTarget(
@@ -145,7 +218,6 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
// on Signal, say) would silently narrow the next, so they reset with it.
const setTab = (tab: EmailTab) => {
closeThread();
- setListFocusTarget();
if (state.tab === tab) return;
setState(
@@ -158,13 +230,11 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
const setInboxIds = (ids: string[] | undefined) => {
closeThread();
- setListFocusTarget();
setState('inboxIds', ids === undefined ? undefined : [...ids]);
};
const setFacets = (facets: EmailViewState['facets']) => {
closeThread();
- setListFocusTarget();
setState('facets', reconcile(normalizeFacetSelection(facets)));
};
@@ -172,7 +242,6 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
// tab moves to All; as with `setTab`, that move drops the tab's other filters.
const showTags = (tagIds: string[]) => {
closeThread();
- setListFocusTarget();
setState(
produce((draft) => {
const movesToAll = tagIds.length > 0 && draft.tab !== 'all';
@@ -212,9 +281,9 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
setFacets,
showTags,
source,
+ list,
+ registerListActivationHandler,
selectedThread,
- listFocusTarget,
- clearListFocusTarget: () => setListFocusTarget(),
openThread,
closeThread,
isSidebarSectionOpen,
diff --git a/apps/web/src/features/email-view/use-email-detail-list-navigation.ts b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
index fcc21e59cd..0ce6ad41f6 100644
--- a/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
+++ b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
@@ -1,97 +1,52 @@
+import { useListDetailNavigation } from '@app/components/list';
import type {
EmailThreadCommands,
EmailThreadListNavigation,
} from '@app/features/email-thread/context/email-thread-context';
-import { adjacentEmail } from '@app/features/email-thread/core/adjacent-email';
import { toast } from '@core/component/Toast/Toast';
import type { EntityData } from '@entity';
-import { type Accessor, createSignal, onCleanup } from 'solid-js';
+import type { Accessor } from 'solid-js';
import { useEmailView } from './email-view-context';
+import type { EmailDataSourceItem } from './queries/use-email-query';
/** Keeps thread triage inside the Email view's filtered navigation stack. */
export function useEmailDetailListNavigation(
threadId: Accessor<string>
): EmailThreadListNavigation {
const { source, openThread } = useEmailView();
- const [navigating, setNavigating] = createSignal(false);
- let disposed = false;
- onCleanup(() => {
- disposed = true;
+ const navigation = useListDetailNavigation<EmailDataSourceItem, EntityData>({
+ currentId: threadId,
+ source,
+ getEntity: (row) => {
+ if (row.kind !== 'entity' || row.entity.type !== 'email') return;
+ return row.entity;
+ },
+ getContinuation: (row) =>
+ row.kind === 'load-more' ? source.loadMore : undefined,
+ open: (entity) => {
+ if (entity.type !== 'email') return;
+ openThread({ id: entity.id, fallbackName: entity.name });
+ },
+ onError: () => toast.failure('Unable to open the next or previous email'),
});
- const isCurrent = (id: string) => !disposed && threadId() === id;
-
- const entities = (): EntityData[] =>
- source
- .items()
- .flatMap((row) => (row.kind === 'entity' ? [row.entity] : []));
- const target = (direction: -1 | 1) =>
- adjacentEmail(entities(), threadId(), direction);
- const canLoadNext = () =>
- source.hasMore() &&
- entities().some(
- (entity) => entity.type === 'email' && entity.id === threadId()
- );
- const open = (entity: EntityData) => {
- if (entity.type !== 'email') return;
- openThread({ id: entity.id, fallbackName: entity.name });
- };
-
- const navigate = async (
- direction: -1 | 1,
- archiveThread?: EmailThreadCommands['archiveThread']
- ) => {
- if (disposed || navigating()) return;
- setNavigating(true);
- const currentId = threadId();
- const current = entities().find(
- (entity) => entity.type === 'email' && entity.id === currentId
- );
-
- try {
- while (direction === 1 && !target(direction) && canLoadNext()) {
- await source.loadMore();
- if (!isCurrent(currentId)) return;
- }
- if (!isCurrent(currentId)) return;
-
- const next =
- target(direction) ?? (archiveThread ? target(-1) : undefined);
- if (
- archiveThread &&
- !archiveThread({
- navigate: false,
- nextEntityId: next?.id,
- navigateBack:
- current && next
- ? () => {
- open(current);
- }
- : undefined,
- })
- ) {
- return;
- }
- if (next) open(next);
- } catch {
- if (isCurrent(currentId)) {
- toast.failure('Unable to open the next or previous email');
- }
- } finally {
- setNavigating(false);
- }
- };
return {
- canPrevious: () => !navigating() && !!target(-1),
- canNext: () => !navigating() && (!!target(1) || canLoadNext()),
- previous: () => {
- void navigate(-1);
- },
- next: () => {
- void navigate(1);
- },
- markDone: (archiveThread) => {
- void navigate(1, archiveThread);
+ ...navigation,
+ markDone: (archiveThread: EmailThreadCommands['archiveThread']) => {
+ void navigation.navigate(1, {
+ fallbackDirection: -1,
+ beforeOpen: (next, current) =>
+ archiveThread({
+ navigate: false,
+ nextEntityId: next?.id,
+ navigateBack:
+ current && next
+ ? () => {
+ navigation.open(current);
+ }
+ : undefined,
+ }),
+ });
},
};
}
diff --git a/apps/web/src/features/tasks-view/components/TasksDetailView.tsx b/apps/web/src/features/tasks-view/components/TasksDetailView.tsx
index b6105df941..7710781ca6 100644
--- a/apps/web/src/features/tasks-view/components/TasksDetailView.tsx
+++ b/apps/web/src/features/tasks-view/components/TasksDetailView.tsx
@@ -5,6 +5,8 @@ import {
type EntityDetailTarget,
useEntityDetailNavigationStack,
} from '@app/components/entity-detail/EntityDetailNavigationStack';
+import { useListNavigationHotkeys } from '@app/components/entity-detail/use-list-navigation-hotkeys';
+import { useListDetailNavigation } from '@app/components/list';
import { ViewBreadcrumbs } from '@app/components/view-shell';
import { useBlockEntityCommands } from '@app/features/next-soup/actions';
import { useMarkdownName } from '@block-md/component/MarkdownNameProvider';
@@ -19,6 +21,7 @@ import {
type EntityIconSelector,
} from '@core/component/EntityIcon';
import { Permissions } from '@core/component/SharePermissions';
+import { toast } from '@core/component/Toast/Toast';
import {
ShareDialogContext,
ShareTrigger,
@@ -276,8 +279,9 @@ function StackEntityDetail(props: { entry: EntityDetailEntry; order: number }) {
}
export function TasksDetailView(props: { task: TaskDetailTarget }) {
- const { closeTask } = useTasksView();
+ const { source, openTask, closeTask } = useTasksView();
const navigationStack = useEntityDetailNavigationStack();
+ const panel = useSplitPanelOrThrow();
const [shareOpen, setShareOpen] = createSignal(false);
const taskEntry = () =>
navigationStack.entries.find(
@@ -286,6 +290,25 @@ export function TasksDetailView(props: { task: TaskDetailTarget }) {
);
const isTaskActive = () =>
navigationStack.active()?.value === taskEntry()?.value;
+ const listNavigation = useListDetailNavigation({
+ currentId: () => props.task.id,
+ source,
+ getEntity: (row) => (row.kind === 'entity' ? row.entity : undefined),
+ getContinuation: (row) => {
+ if (row.kind !== 'load-more') return;
+ const groupId = row.groupId;
+ return groupId === undefined
+ ? source.loadMore
+ : () => source.loadMoreGroup(groupId);
+ },
+ open: (task) => openTask({ id: task.id, fallbackName: task.name }),
+ onError: () => toast.failure('Unable to open the next or previous task'),
+ });
+ useListNavigationHotkeys({
+ scopeId: panel.splitHotkeyScope,
+ enabled: () => panel.isPanelActive() && isTaskActive(),
+ navigation: listNavigation,
+ });
return (
<ShareDialogContext.Provider
diff --git a/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx b/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx
index 6f691bad2d..1960344d82 100644
--- a/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx
+++ b/apps/web/src/features/tasks-view/components/task-list/TaskList.tsx
@@ -1,9 +1,4 @@
-import {
- createListController,
- type ListActivation,
- listOwnedSlotName,
- useListInteractions,
-} from '@app/components/list';
+import { type ListActivation, useListInteractions } from '@app/components/list';
import {
resolveEntityActionViewContext,
toEntityActionListState,
@@ -22,11 +17,7 @@ import {
toggleValue,
} from '@app/lib/signals/store-array-updaters';
import { SwipableRowProvider } from '@components/app/mobile/SwipableRow';
-import {
- useSplitPanelOrThrow,
- withSplitPanelOwner,
-} from '@components/app/split-layout/layoutUtils';
-import { useUserId } from '@core/context/user';
+import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import {
type EntityData,
@@ -41,7 +32,6 @@ import CaretDownIcon from '@phosphor/caret-down.svg';
import CheckIcon from '@phosphor/check.svg';
import SpinnerIcon from '@phosphor/spinner.svg';
import { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from '@property';
-import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';
import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';
import { EntityType } from '@service-properties/generated/schemas/entityType';
import { Button, cn } from '@ui';
@@ -61,11 +51,11 @@ import {
DEFAULT_TASKS_LIST_STATE,
type TasksListStateSnapshot,
} from '../../persistence';
+import type { TasksDataSourceItem } from '../../queries/use-tasks-query';
import {
- type TasksDataSourceItem,
- useTasksDataSource,
-} from '../../queries/use-tasks-query';
-import { useTasksView } from '../../tasks-view-context';
+ type TasksListActivationMetadata,
+ useTasksView,
+} from '../../tasks-view-context';
import { TaskGroupHeader } from './TaskGroupHeader';
import { TaskListEntity } from './TaskListEntity';
import { TaskListHeader } from './TaskListHeader';
@@ -93,11 +83,6 @@ const getStatusProperty = (task: TaskEntityWithProperties) => {
}
};
-type TasksListActivationMetadata = {
- event?: MouseEvent;
- newSplit?: boolean;
-};
-
export type TaskListProps = {
/** The focusable list root, for callers that hand keyboard focus back. */
ref?: (element: HTMLDivElement) => void;
@@ -105,8 +90,14 @@ export type TaskListProps = {
export function TaskList(props: TaskListProps) {
const panel = useSplitPanelOrThrow();
- const { state, setState, openTask } = useTasksView();
- const userId = useUserId();
+ const {
+ state,
+ setState,
+ source,
+ list,
+ registerListActivationHandler,
+ openTask,
+ } = useTasksView();
const forceEmptyState = useDebugSetting(
DEBUG_SETTING_KEYS.FORCE_EMPTY_STATES
);
@@ -120,17 +111,6 @@ export function TaskList(props: TaskListProps) {
const toggleGroup = (groupId: string) =>
setState('collapsedGroupIds', toggleValue(groupId));
- const tagSets = useTagSets();
- const tagSetsReady = useTagSetsReady();
- const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>
- useTasksDataSource(state, {
- userId,
- tagSets,
- tagSetsReady,
- isGroupExpanded,
- })
- );
-
function openEntity(
entity: EntityData,
options: {
@@ -194,18 +174,7 @@ export function TaskList(props: TaskListProps) {
});
}
- const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>
- createListController<TasksDataSourceItem, TasksListActivationMetadata>({
- items: source.items,
- getKey: (row) => row.id,
- selection: {
- getKey: (row) => (row.kind === 'entity' ? row.entity.id : row.id),
- },
- isNavigable: (row) => row.kind !== 'section-header',
- isSelectable: (row) => row.kind === 'entity',
- onActivate,
- })
- );
+ registerListActivationHandler(onActivate);
const entityActionViewContext = () =>
resolveEntityActionViewContext({
@@ -226,7 +195,9 @@ export function TaskList(props: TaskListProps) {
const current = readListState();
const value = typeof next === 'function' ? next(current) : next;
- if (value.focusKey !== current.focusKey) {
+ // The view-owned controller survives inline detail navigation. Restore
+ // persisted focus only on a cold mount that has no live focus to preserve.
+ if (current.focusKey === undefined && value.focusKey !== undefined) {
list.focus.restore(value.focusKey, { reason: 'restore' });
}
diff --git a/apps/web/src/features/tasks-view/tasks-view-context.tsx b/apps/web/src/features/tasks-view/tasks-view-context.tsx
index d1f86e9a48..855126b330 100644
--- a/apps/web/src/features/tasks-view/tasks-view-context.tsx
+++ b/apps/web/src/features/tasks-view/tasks-view-context.tsx
@@ -2,14 +2,24 @@ import {
entityDetailTarget,
useEntityDetailNavigationStack,
} from '@app/components/entity-detail/EntityDetailNavigationStack';
+import {
+ createListController,
+ type ListActivation,
+ type ListController,
+ listOwnedSlotName,
+} from '@app/components/list';
import { setSidebarSectionCollapsed } from '@app/components/view-shell';
import { normalizeFacetSelection } from '@app/features/soup';
import { makePersistedState } from '@app/lib/persistence';
-import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import {
+ useSplitPanelOrThrow,
+ withSplitPanelOwner,
+} from '@components/app/split-layout/layoutUtils';
import { createAssertedContextProvider } from '@core/context/createContext';
import { useUserId } from '@core/context/user';
+import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';
import type { ContextProviderProps } from '@solid-primitives/context';
-import type { Accessor } from 'solid-js';
+import { type Accessor, onCleanup } from 'solid-js';
import {
createStore,
produce,
@@ -20,6 +30,11 @@ import {
import { TASK_DEFAULT_GROUP_BY } from './constants';
import { DEFAULT_TASK_FACET_SELECTION } from './filters/task-facets';
import { createTasksViewPersistence } from './persistence';
+import {
+ type TasksDataSource,
+ type TasksDataSourceItem,
+ useTasksDataSource,
+} from './queries/use-tasks-query';
import type {
TaskDetailTarget,
TaskSortId,
@@ -32,10 +47,30 @@ type TasksViewProviderProps = ContextProviderProps & {
initialState?: TasksViewStateOptions;
};
+export type TasksListActivationMetadata = {
+ event?: MouseEvent;
+ newSplit?: boolean;
+};
+
+type TasksListController = ListController<
+ TasksDataSourceItem,
+ TasksListActivationMetadata
+>;
+
export type TasksViewContext = {
state: Store<TasksViewState>;
setState: SetStoreFunction<TasksViewState>;
selectedTask: Accessor<TaskDetailTarget | undefined>;
+ source: TasksDataSource;
+ list: TasksListController;
+ registerListActivationHandler: (
+ handler: (
+ activation: ListActivation<
+ TasksDataSourceItem,
+ TasksListActivationMetadata
+ >
+ ) => void
+ ) => void;
openTask: (task: TaskDetailTarget) => void;
closeTask: () => void;
setTab: (tab: TaskTab) => void;
@@ -52,6 +87,8 @@ export const [TasksViewProvider, useTasksView] = createAssertedContextProvider<
const panel = useSplitPanelOrThrow();
const navigationStack = useEntityDetailNavigationStack();
const userId = useUserId();
+ const tagSets = useTagSets();
+ const tagSetsReady = useTagSetsReady();
const initial = props.initialState ?? {};
const initialTab = initial.tab ?? 'my-tasks';
@@ -80,6 +117,45 @@ export const [TasksViewProvider, useTasksView] = createAssertedContextProvider<
})
);
+ const isGroupExpanded = (groupId: string) =>
+ !state.collapsedGroupIds.includes(groupId);
+ const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>
+ useTasksDataSource(state, {
+ userId,
+ tagSets,
+ tagSetsReady,
+ isGroupExpanded,
+ })
+ );
+ let listActivationHandler:
+ | ((
+ activation: ListActivation<
+ TasksDataSourceItem,
+ TasksListActivationMetadata
+ >
+ ) => void)
+ | undefined;
+ const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>
+ createListController<TasksDataSourceItem, TasksListActivationMetadata>({
+ items: source.items,
+ getKey: (row) => row.id,
+ selection: {
+ getKey: (row) => (row.kind === 'entity' ? row.entity.id : row.id),
+ },
+ isNavigable: (row) => row.kind !== 'section-header',
+ isSelectable: (row) => row.kind === 'entity',
+ onActivate: (activation) => listActivationHandler?.(activation),
+ })
+ );
+ const registerListActivationHandler = (
+ handler: NonNullable<typeof listActivationHandler>
+ ) => {
+ listActivationHandler = handler;
+ onCleanup(() => {
+ if (listActivationHandler === handler) listActivationHandler = undefined;
+ });
+ };
+
const selectedTask = (): TaskDetailTarget | undefined => {
const taskEntry = navigationStack.entries.find(
(entry) =>
@@ -100,6 +176,14 @@ export const [TasksViewProvider, useTasksView] = createAssertedContextProvider<
};
const openTask = (task: TaskDetailTarget) => {
+ const row = source
+ .items()
+ .find((item) => item.kind === 'entity' && item.entity.id === task.id);
+ if (row) {
+ list.focus.set(row.id, { reason: 'programmatic', force: true });
+ list.selection.setAnchor(row.id);
+ }
+
navigationStack.reset(
entityDetailTarget.document({
id: task.id,
@@ -150,6 +234,9 @@ export const [TasksViewProvider, useTasksView] = createAssertedContextProvider<
state,
setState,
selectedTask,
+ source,
+ list,
+ registerListActivationHandler,
openTask,
closeTask,
setTab,
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 5632af1470..f883bd0c93 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -191,8 +191,9 @@ selecting it again clears that tag filter. Favorite rows open their tasks.
Normal row and favorite activation replaces the list with the editable task
document; its originating-tab breadcrumb returns to the list and its
header exposes Share and the task Details/Properties panel. Shift-click opens
-the task in a new split instead. Keyboard navigation moves list focus without
-opening a task until activation.
+the task in a new split instead. While the list is visible, `J` and `K` move
+focus without opening a task until activation. In an open task detail, they
+replace it with the next or previous task in the same filtered order.
The desktop `Create` → `Task` modal uses the standard dialog panel, circular
icon controls, and a pill-shaped `Create Task` button with 16px outer padding.
@@ -620,7 +621,8 @@ without comment permission have no comment composer, so Ask AI remains visible.
On touch devices, an email thread's floating action bar has Previous email and
Next email arrows beside the larger Mark done checkmark. The arrows follow the
source list's filtered order, skip non-email items, and disable at its ends.
-They do not wrap; a thread opened without a source list has disabled arrows.
+`J` and `K` use that same order in the Email view. They do not wrap; a thread
+opened without a source list has disabled arrows.
Mark done archives the current thread and opens the next email in that same
filtered list, loading pages until another email is found or the list ends.
On native mobile, stepping replaces the current email while preserving the