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(search): navigating should not refocus search bar (#3029)

gbirman4d78edf11244
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index d587330d5f..5e6339cdf1 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -49,6 +49,7 @@ import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';
import { ContextMenuContent, MenuItem } from '@core/component/Menu';
import { ContextMenu } from '@kobalte/core/context-menu';
import { useAnalytics } from '@app/component/analytics-context';
+import { requestSearchFocus } from '@app/component/next-soup/soup-view/search-controllers';
import { useHotkeyInterceptor } from '@app/signal/hotkeyRoot';
import {
InviteModal,
@@ -329,22 +330,12 @@ export const registerSidebarHotkeys = ({
content?.type === 'component' &&
content.id === 'search'
) {
- const splitEl = document.querySelector(
- `[data-split-id="${activeSplit.id}"]`
- );
- const searchContainer =
- splitEl?.querySelector<HTMLElement>('[data-soup-search]');
- if (searchContainer) {
- const editable =
- searchContainer.querySelector<HTMLElement>('[contenteditable]') ??
- searchContainer;
- editable.focus();
- return true;
- }
+ requestSearchFocus(activeSplit.id);
+ return true;
}
}
- openWithSplit(
+ const handle = openWithSplit(
{
type: 'component',
id: link.id,
@@ -355,6 +346,9 @@ export const registerSidebarHotkeys = ({
allowDuplicate: true,
}
);
+ if (link.id === 'search' && handle) {
+ requestSearchFocus(handle.id);
+ }
return true;
};
@@ -772,12 +766,15 @@ const SidebarLink = (props: SidebarLinkProps) => {
if (e.button === 1) return;
e.preventDefault();
- layout.openWithSplit(content(), {
+ const handle = layout.openWithSplit(content(), {
preferNewSplit: e.shiftKey,
mergeHistory: false,
allowDuplicate: true,
referredFrom: 'sidebar',
});
+ if (props.id === 'search' && handle) {
+ requestSearchFocus(handle.id);
+ }
layoutManager?.returnFocus();
}}
>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
index 6dfc46e7a8..d0c8f93b41 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-filters-bar.tsx
@@ -76,7 +76,6 @@ export const SoupFiltersBar = (props: SoupFiltersBarProps = {}) => {
<Match when={isComponentListView('search')}>
<div class="w-full flex flex-col gap-2 p-2 border-b border-edge-muted">
<SoupSearchbar
- autoFocus={!props.initialSearchText}
placeholder="Search, @mention contacts"
initialValue={props.initialSearchText}
/>
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
index 4f7054d12b..29b0606dc5 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/soup-view-search-bar.tsx
@@ -148,6 +148,9 @@ export const SoupSearchbar = (props: SoupSearchbarProps) => {
// rows so this stays put without needing a delay.
queueMicrotask(() => panel.panelRef()?.focus({ preventScroll: true }));
},
+ focus: () => {
+ setTimeout(() => editor.controls.focus());
+ },
});
onCleanup(dispose);
});
diff --git a/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts b/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts
index 5d7cdd6da0..7da988c94f 100644
--- a/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts
+++ b/js/app/packages/app/component/next-soup/soup-view/search-controllers.ts
@@ -10,15 +10,20 @@ export type SearchSplitOverrides = {
export type SearchSplitController = {
applyOverrides: (overrides: SearchSplitOverrides) => void;
+ focus: () => void;
};
const registry = new Map<SplitId, SearchSplitController>();
+const pendingFocusBySplit = new Set<SplitId>();
export function registerSearchSplit(
splitId: SplitId,
controller: SearchSplitController
): () => void {
registry.set(splitId, controller);
+ if (pendingFocusBySplit.delete(splitId)) {
+ controller.focus();
+ }
return () => {
if (registry.get(splitId) === controller) registry.delete(splitId);
};
@@ -29,3 +34,17 @@ export function getSearchSplit(
): SearchSplitController | undefined {
return registry.get(splitId);
}
+
+/**
+ * Focus the search bar in the given split. If the split's search controller
+ * is already registered, focus immediately; otherwise queue the request and
+ * focus once the controller registers (e.g. after the SoupView mounts).
+ */
+export function requestSearchFocus(splitId: SplitId) {
+ const controller = registry.get(splitId);
+ if (controller) {
+ controller.focus();
+ return;
+ }
+ pendingFocusBySplit.add(splitId);
+}