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.

unified-list: fix enter hotkey on tab switch and return from block (#422)

Caleb Taylorf5a38685d9f0
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index d1af00cb17..1134e4fcd1 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -1187,9 +1187,6 @@ export function createNavigationEntityListShortcut({
scopeId: entityHotkeyScope,
description: 'Open',
keyDownHandler: () => {
- const [preview] = previewState;
- if (!preview()) return false;
-
const entity = getHighlightedEntity()?.entity;
if (!entity) return false;
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index 3f58783328..8d83d37f14 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -238,7 +238,19 @@ export function UnifiedListView(props: UnifiedListViewProps) {
if (!localEntityListRef) return;
setEntityListRef(localEntityListRef);
- if (view()?.hasUserInteractedEntity) return;
+ if (view()?.hasUserInteractedEntity) {
+ if (selectedEntity()) {
+ if (localEntityListRef && localEntityListRef.isConnected) {
+ // focusing non-first entity causes issue where 100ms later, that focused entity loses focus and document.body is focused
+ // forcing refocus on that entity works for now
+ // read TODO inside function for more info
+ tryFocusEntity(selectedEntity()!.id, {
+ forceRefocusOnce: true,
+ });
+ }
+ }
+ return;
+ }
// select first item from entityList until interaction
if (!_entities() || !_entities()?.length) return;
@@ -247,25 +259,56 @@ export function UnifiedListView(props: UnifiedListViewProps) {
setViewDataStore(selectedView(), 'highlightedId', firstEntity.id);
setViewDataStore(selectedView(), 'selectedEntity', firstEntity);
- setTimeout(() => {
- // don't steal focus outside of entityList
- if (
- !(
- document.activeElement === document.body ||
- document.activeElement === panelRef() ||
- localEntityListRef.contains(document.activeElement)
- )
- ) {
- return;
+ tryFocusEntity(firstEntity.id);
+
+ function tryFocusEntity(
+ entityId: string,
+ { forceRefocusOnce }: { forceRefocusOnce: boolean } = {
+ forceRefocusOnce: false,
}
+ ) {
+ setTimeout(() => {
+ const dontFocus = () => {
+ if (!localEntityListRef) return true;
+ // don't steal focus outside of entityList
+ if (
+ !(
+ document.activeElement === document.body ||
+ document.activeElement === panelRef() ||
+ localEntityListRef.contains(document.activeElement)
+ )
+ ) {
+ return true;
+ }
+ return false;
+ };
- const focusElement = localEntityListRef.querySelector(
- `[data-entity-id="${firstEntity.id}"]`
- ) as HTMLElement;
+ if (dontFocus()) return;
- if (focusElement instanceof HTMLElement)
- focusElement.focus({ preventScroll: true });
- });
+ const focusElement = localEntityListRef!.querySelector(
+ `[data-entity-id="${entityId}"]`
+ ) as HTMLElement;
+
+ if (focusElement instanceof HTMLElement) {
+ focusElement.focus({ preventScroll: true });
+
+ // TODO: figure out what's causing document.body to be focused
+ // 100ms later or so, document.body is focused, despite focueElement still connected, and not shuffled
+ // without this, createMenu on close doesn't refocus on entity
+ if (forceRefocusOnce) {
+ focusElement.addEventListener(
+ 'blur',
+ () => {
+ if (dontFocus()) return;
+
+ focusElement.focus({ preventScroll: true });
+ },
+ { once: true }
+ );
+ }
+ }
+ });
+ }
}
)
);