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(spreadsheet): compact channel-style find bar in top-right (#8387)

Jacob Beckermandcdf40954d68
diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
index 670b9c79cd..b2bd8f735d 100644
--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts
@@ -111,10 +111,12 @@ test('keeps function insertion, find, and paste menu focus usable from the ribbo
await page
.getByRole('button', { name: 'Find and replace', exact: true })
.click();
+ const findBar = page.getByRole('search', { name: 'Find and replace' });
const find = page.getByRole('textbox', { name: 'Find in sheet' });
+ await expect(findBar).toBeVisible();
await expect(find).toBeFocused();
await find.press('Escape');
- await expect(page.getByRole('dialog')).toBeHidden();
+ await expect(findBar).toBeHidden();
await expect(grid).toBeFocused();
await page
diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts
index e4a6887a20..f1a0b6e2d7 100644
--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts
+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts
@@ -338,13 +338,13 @@ test('touch formatting and sheet navigation preserve workbook state', async ({
await page.getByRole('tab', { name: 'Sheet1', exact: true }).tap();
await expect(cell(page, 'B2')).toHaveText('$10.00');
await button(page, 'Find and replace').tap();
- const dialog = page.getByRole('dialog');
- await expectInsideViewport(page, dialog);
+ const findBar = page.getByRole('search', { name: 'Find and replace' });
+ await expectInsideViewport(page, findBar);
await page.getByRole('textbox', { name: 'Find in sheet' }).fill('Design');
- await button(page, 'Find next').tap();
- await expect(dialog.getByRole('status')).toContainText('1 of 1 matches');
- await button(page, 'Close find and replace').tap();
- await expect(dialog).toBeHidden();
+ await button(page, 'Next match').tap();
+ await expect(findBar.getByRole('status')).toContainText('1/1');
+ await button(page, 'Close find bar').tap();
+ await expect(findBar).toBeHidden();
await expect(addressBar(page)).toHaveValue('A2');
});
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetDialogs.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetDialogs.tsx
index dc0e3f7857..4aa92805e6 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetDialogs.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetDialogs.tsx
@@ -1,9 +1,14 @@
+import CaretDown from '@phosphor/caret-down.svg';
+import CaretUp from '@phosphor/caret-up.svg';
+import MagnifyingGlass from '@phosphor/magnifying-glass.svg';
+import Swap from '@phosphor/swap.svg';
import X from '@phosphor/x.svg';
import { Button } from '@ui/components/Button';
+import { createEffect, createSignal, on, Show } from 'solid-js';
import type { FindOptions } from '../core/sheet-operations';
import { SpreadsheetDialog as Dialog } from './SpreadsheetDialog';
-export function SpreadsheetFindDialog(props: {
+type SpreadsheetFindDialogProps = {
open: boolean;
onClose: () => void;
onRestoreFocus?: () => void;
@@ -19,128 +24,215 @@ export function SpreadsheetFindDialog(props: {
notice: string;
onFind: (backwards?: boolean) => void;
onReplace: (all: boolean) => void;
-}) {
+};
+
+/** Platform find shortcut (Cmd/Ctrl+F). */
+function isFindKey(event: KeyboardEvent) {
+ return (event.metaKey || event.ctrlKey) && event.code === 'KeyF';
+}
+
+/** Compact find bar (channel-style); expands for replace and search options. */
+export function SpreadsheetFindDialog(props: SpreadsheetFindDialogProps) {
+ const [replacing, setReplacing] = createSignal(false);
+ let findInputRef: HTMLInputElement | undefined;
+
+ const focusFind = () => {
+ findInputRef?.focus();
+ findInputRef?.select();
+ };
+
+ createEffect(
+ on(
+ () => props.open,
+ (open) => {
+ if (!open) {
+ setReplacing(false);
+ return;
+ }
+ queueMicrotask(focusFind);
+ }
+ )
+ );
+
+ const close = () => {
+ props.onClose();
+ props.onRestoreFocus?.();
+ };
+
+ const status = () => {
+ if (!props.query) return '';
+ if (!props.matchCount) return 'No results';
+ const current = props.matchIndex >= 0 ? props.matchIndex + 1 : '–';
+ return `${current}/${props.matchCount}`;
+ };
+
return (
- <Dialog
- onRestoreFocus={props.onRestoreFocus}
- open={props.open}
- onOpenChange={(open) => {
- if (!open) props.onClose();
- }}
- position="center"
- class="w-108"
- >
- <div class="p-5 text-ink" onKeyDown={(event) => event.stopPropagation()}>
- <div class="mb-4 flex items-center justify-between">
- <Dialog.Title class="text-sm font-semibold">
- Find and replace
- </Dialog.Title>
+ <Show when={props.open}>
+ <div
+ role="search"
+ aria-label="Find and replace"
+ class="absolute top-2 right-3 z-20 flex w-80 max-w-[calc(100%-1.5rem)] flex-col gap-1 rounded-md border border-edge bg-surface p-1 shadow-md focus-within:border-accent touch:top-[calc(var(--mobile-content-inset-top,0)+0.5rem)]"
+ onKeyDown={(event) => {
+ event.stopPropagation();
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ close();
+ return;
+ }
+ // Stop the browser find dialog while the bar owns keyboard focus.
+ if (isFindKey(event)) {
+ event.preventDefault();
+ focusFind();
+ }
+ }}
+ onPointerDown={(event) => event.stopPropagation()}
+ >
+ <div class="flex items-center gap-1">
<Button
- label="Close find and replace"
size="icon-sm"
- class="order-last text-ink-muted"
- tabIndex={-1}
- onClick={props.onClose}
+ variant="ghost"
+ aria-label="Search"
+ classList={{ '!text-accent': !!props.query.trim() }}
+ onClick={() => props.onFind()}
>
- <X class="size-4" />
+ <MagnifyingGlass />
</Button>
- </div>
- <Dialog.Description class="mb-4 text-xs text-ink-muted">
- Search this sheet. Formula results are preserved unless you choose to
- search formulas.
- </Dialog.Description>
- <label class="mb-3 block text-xs">
- <span class="mb-1.5 block">Find</span>
<input
+ ref={findInputRef}
+ type="text"
aria-label="Find in sheet"
+ placeholder="Find"
value={props.query}
+ spellcheck={false}
onInput={(e) => props.onQuery(e.currentTarget.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.isComposing) {
e.preventDefault();
props.onFind(e.shiftKey);
+ } else if (isFindKey(e)) {
+ e.preventDefault();
+ focusFind();
}
}}
- class="h-9 w-full touch:h-[44px] touch:text-[max(16px,1rem)] rounded-md border border-edge-muted bg-input px-3 text-sm outline-none focus:border-accent"
- />
- </label>
- <label class="mb-4 block text-xs">
- <span class="mb-1.5 block">Replace with</span>
- <input
- aria-label="Replace with"
- value={props.replacement}
- disabled={props.readonly}
- onInput={(e) => props.onReplacement(e.currentTarget.value)}
- class="h-9 w-full touch:h-[44px] touch:text-[max(16px,1rem)] rounded-md border border-edge-muted bg-input px-3 text-sm outline-none focus:border-accent disabled:opacity-40"
+ class="min-w-0 flex-1 border-0 bg-transparent px-1 text-sm text-ink placeholder:text-ink-placeholder outline-none focus:ring-0"
/>
- </label>
- <div class="flex flex-col gap-2.5 text-xs text-ink-muted">
- <label class="flex items-center gap-2 touch:min-h-[44px]">
- <input
- type="checkbox"
- class="touch:size-[20px]"
- checked={props.options.matchCase}
- onChange={(e) =>
- props.onOptions({ matchCase: e.currentTarget.checked })
- }
- />
- Match case
- </label>
- <label class="flex items-center gap-2 touch:min-h-[44px]">
- <input
- type="checkbox"
- class="touch:size-[20px]"
- checked={props.options.entireCell}
- onChange={(e) =>
- props.onOptions({ entireCell: e.currentTarget.checked })
- }
- />
- Match entire cell contents
- </label>
- <label class="flex items-center gap-2 touch:min-h-[44px]">
- <input
- type="checkbox"
- class="touch:size-[20px]"
- checked={props.options.formulas}
- onChange={(e) =>
- props.onOptions({ formulas: e.currentTarget.checked })
- }
- />
- Search within formulas
- </label>
- </div>
- <p role="status" class="min-h-10 py-3 text-xs text-ink-muted">
- {props.query
- ? `${props.matchIndex >= 0 ? props.matchIndex + 1 : 0} of ${props.matchCount} matches`
- : 'Enter text to search'}
- {props.notice ? ` · ${props.notice}` : ''}
- </p>
- <div class="flex flex-wrap justify-end gap-2 border-t border-edge-muted pt-3">
- <Button
- size="sm"
- disabled={!props.matchCount || props.readonly}
- onClick={() => props.onReplace(true)}
+ <span
+ role="status"
+ class="px-1 text-xs text-ink-muted tabular-nums whitespace-nowrap"
+ classList={{ invisible: !status() }}
>
- Replace all
- </Button>
+ {status() || '0/0'}
+ {props.notice ? ` · ${props.notice}` : ''}
+ </span>
<Button
- size="sm"
- disabled={props.matchIndex < 0 || props.readonly}
- onClick={() => props.onReplace(false)}
+ size="icon-sm"
+ variant="ghost"
+ aria-label="Previous match"
+ disabled={!props.matchCount}
+ onClick={() => props.onFind(true)}
>
- Replace
+ <CaretUp />
</Button>
<Button
- size="sm"
- variant="strong"
+ size="icon-sm"
+ variant="ghost"
+ aria-label="Next match"
disabled={!props.matchCount}
onClick={() => props.onFind()}
>
- Find next
+ <CaretDown />
+ </Button>
+ <Show when={!props.readonly}>
+ <Button
+ size="icon-sm"
+ variant="ghost"
+ label={replacing() ? 'Hide replace' : 'Replace'}
+ aria-pressed={replacing()}
+ onClick={() => setReplacing((open) => !open)}
+ >
+ <Swap />
+ </Button>
+ </Show>
+ <Button
+ size="icon-sm"
+ variant="ghost"
+ aria-label="Close find bar"
+ onClick={close}
+ >
+ <X />
</Button>
</div>
+ <Show when={replacing() && !props.readonly}>
+ <div class="flex flex-col gap-1.5 px-1 pb-1">
+ <div class="flex items-center gap-1">
+ <input
+ type="text"
+ aria-label="Replace with"
+ placeholder="Replace with"
+ value={props.replacement}
+ spellcheck={false}
+ onInput={(e) => props.onReplacement(e.currentTarget.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && !e.isComposing) {
+ e.preventDefault();
+ props.onReplace(false);
+ }
+ }}
+ class="h-7 min-w-0 flex-1 rounded-md border border-edge-muted bg-input px-2 text-sm text-ink outline-none focus:border-accent"
+ />
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={props.matchIndex < 0}
+ onClick={() => props.onReplace(false)}
+ >
+ Replace
+ </Button>
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={!props.matchCount}
+ onClick={() => props.onReplace(true)}
+ >
+ All
+ </Button>
+ </div>
+ <div class="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-ink-muted">
+ <label class="flex items-center gap-1.5">
+ <input
+ type="checkbox"
+ checked={props.options.matchCase}
+ onChange={(e) =>
+ props.onOptions({ matchCase: e.currentTarget.checked })
+ }
+ />
+ Match case
+ </label>
+ <label class="flex items-center gap-1.5">
+ <input
+ type="checkbox"
+ checked={props.options.entireCell}
+ onChange={(e) =>
+ props.onOptions({ entireCell: e.currentTarget.checked })
+ }
+ />
+ Entire cell
+ </label>
+ <label class="flex items-center gap-1.5">
+ <input
+ type="checkbox"
+ checked={props.options.formulas}
+ onChange={(e) =>
+ props.onOptions({ formulas: e.currentTarget.checked })
+ }
+ />
+ Formulas
+ </label>
+ </div>
+ </div>
+ </Show>
</div>
- </Dialog>
+ </Show>
);
}
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetWorkbookDialogs.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetWorkbookDialogs.test.tsx
index cdb5823429..d195b3a631 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetWorkbookDialogs.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetWorkbookDialogs.test.tsx
@@ -77,12 +77,14 @@ describe('workbook dialogs', () => {
it('returns focus to the editor when Find closes and leaves IME Enter alone', async () => {
const [open, setOpen] = createSignal(false);
const find = vi.fn();
+ const restoreFocus = vi.fn();
const view = render(() => (
<>
<div role="grid" aria-label="Spreadsheet" tabIndex={0} />
<SpreadsheetFindDialog
open={open()}
onClose={() => setOpen(false)}
+ onRestoreFocus={restoreFocus}
query="Budget"
onQuery={() => {}}
replacement=""
@@ -108,8 +110,70 @@ describe('workbook dialogs', () => {
fireEvent.keyDown(input, { key: 'Enter' });
expect(find).toHaveBeenCalledWith(false);
fireEvent.keyDown(input, { key: 'Escape' });
- await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
- await waitFor(() => expect(document.activeElement).toBe(grid));
+ await waitFor(() => expect(screen.queryByRole('search')).toBeNull());
+ expect(restoreFocus).toHaveBeenCalled();
+ });
+
+ it('blocks the browser find shortcut while the find bar is focused', async () => {
+ render(() => (
+ <SpreadsheetFindDialog
+ open
+ onClose={() => {}}
+ query="Budget"
+ onQuery={() => {}}
+ replacement=""
+ onReplacement={() => {}}
+ options={{ matchCase: false, entireCell: false, formulas: false }}
+ onOptions={() => {}}
+ matchCount={1}
+ matchIndex={0}
+ readonly={false}
+ notice=""
+ onFind={() => {}}
+ onReplace={() => {}}
+ />
+ ));
+ const input = await screen.findByRole('textbox', { name: 'Find in sheet' });
+ const event = new KeyboardEvent('keydown', {
+ key: 'f',
+ code: 'KeyF',
+ metaKey: true,
+ bubbles: true,
+ cancelable: true,
+ });
+ input.dispatchEvent(event);
+ expect(event.defaultPrevented).toBe(true);
+ });
+
+ it('keeps replace collapsed until the replace toggle is pressed', async () => {
+ const [open, setOpen] = createSignal(true);
+ render(() => (
+ <SpreadsheetFindDialog
+ open={open()}
+ onClose={() => setOpen(false)}
+ query="Budget"
+ onQuery={() => {}}
+ replacement=""
+ onReplacement={() => {}}
+ options={{ matchCase: false, entireCell: false, formulas: false }}
+ onOptions={() => {}}
+ matchCount={1}
+ matchIndex={0}
+ readonly={false}
+ notice=""
+ onFind={() => {}}
+ onReplace={() => {}}
+ />
+ ));
+ expect(screen.queryByRole('textbox', { name: 'Replace with' })).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Replace' }));
+ expect(
+ await screen.findByRole('textbox', { name: 'Replace with' })
+ ).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Hide replace' }));
+ await waitFor(() =>
+ expect(screen.queryByRole('textbox', { name: 'Replace with' })).toBeNull()
+ );
});
it('focuses and selects the sheet name on opening and reopening, and Escape closes', async () => {
diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
index 048280feeb..e5a36ac4f7 100644
--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
@@ -17,6 +17,8 @@ import {
createSignal,
For,
on,
+ onCleanup,
+ onMount,
Show,
} from 'solid-js';
import { match } from 'ts-pattern';
@@ -852,21 +854,38 @@ export function SpreadsheetEditor(props: {
}
}
+ // Capture so formula-bar / toolbar inputs that stopPropagation cannot open
+ // the browser find dialog; always route Cmd/Ctrl+F to the sheet find bar.
+ onMount(() => {
+ const onFindShortcut = (event: KeyboardEvent) => {
+ if (
+ !(event.metaKey || event.ctrlKey) ||
+ event.altKey ||
+ event.code !== 'KeyF'
+ )
+ return;
+ event.preventDefault();
+ event.stopPropagation();
+ command('find');
+ queueMicrotask(() => {
+ const input = editorElement.querySelector<HTMLInputElement>(
+ '[aria-label="Find in sheet"]'
+ );
+ input?.focus();
+ input?.select();
+ });
+ };
+ editorElement.addEventListener('keydown', onFindShortcut, true);
+ onCleanup(() =>
+ editorElement.removeEventListener('keydown', onFindShortcut, true)
+ );
+ });
+
return (
<section
ref={editorElement}
class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden bg-panel text-ink"
aria-label={`${props.name} spreadsheet`}
- onKeyDown={(event) => {
- if (
- (event.metaKey || event.ctrlKey) &&
- event.key.toLowerCase() === 'f'
- ) {
- event.preventDefault();
- event.stopPropagation();
- command('find');
- }
- }}
>
<SpreadsheetDialog
open={!!resize()}
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index 9d969c8f10..57a3893c2d 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -569,9 +569,15 @@ Escape from the address or font-size field returns keyboard navigation to the gr
the result in the empty cell below; for one cell it opens `=FUNCTION(` for reference
picking. An occupied result cell is never overwritten.
-The **Find and replace** ribbon button (Cmd/Ctrl+F in the grid) supports
-case-sensitive and whole-cell matching. Find next selects each result. Formula results can be searched
-but replacements preserve the formulas unless **Search within formulas** is checked.
+The **Find and replace** ribbon button (Cmd/Ctrl+F in the grid) opens a compact
+find bar in the top-right of the sheet (same pattern as channel find): query,
+match count, previous/next, and close. The sheet stays visible while searching.
+Cmd/Ctrl+F is captured on the editor (including the formula bar and find bar)
+so the browser find dialog never opens; a second press re-selects the query.
+Press the replace toggle to expand replace-with, Replace / All, and match options
+(case, entire cell, formulas). Next/previous select each result. Formula results
+can be searched, but replacements preserve the formulas unless **Formulas** is
+checked.
**Format and data** sorts the selected rectangle by its active column, keeping each
row's values, styles, and relative formulas together, or trims whitespace in text
cells. **Goal Seek…** in that menu finds the number to put in one cell so a formula