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(channels): keep the /gif picker visible on mobile (#8813)

Wolf Mermelstein2701108248c3
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
index 83d9e4f85c..146ba47d65 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/ActionsMenu.tsx
@@ -63,6 +63,11 @@ function ActionsMenuItem(props: {
e.preventDefault();
e.stopPropagation();
}}
+ on:pointerdown={(e) => {
+ // Keep the editor focused so /gif (and other slash actions) can run.
+ // iOS still emits mousedown after a cancelled pointerdown; cancel both.
+ e.preventDefault();
+ }}
on:mousedown={(e) => {
e.preventDefault();
e.stopPropagation();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.test.tsx
index 862cb4a78b..059eaae009 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.test.tsx
@@ -76,6 +76,30 @@ function mountPicker() {
return { editor, open, setCanEdit };
}
+it('opens the picker when the editor has no selection', async () => {
+ const { editor } = mountPicker();
+ editor.update(
+ () => {
+ editor.dispatchCommand(TRY_INSERT_GIF_COMMAND, undefined);
+ },
+ { discrete: true }
+ );
+ expect(await screen.findByRole('searchbox')).toBeTruthy();
+});
+
+it('inserts a GIF when the editor has no saved caret', async () => {
+ const { editor } = mountPicker();
+ editor.update(
+ () => {
+ $getRoot().append($createParagraphNode());
+ editor.dispatchCommand(TRY_INSERT_GIF_COMMAND, undefined);
+ },
+ { discrete: true }
+ );
+ fireEvent.click(await screen.findByRole('button', { name: 'Audit GIF' }));
+ expect(insertGif).toHaveBeenCalledOnce();
+});
+
it('inserts a selected GIF while editing remains allowed', async () => {
const { open } = mountPicker();
open();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.tsx
index 86a470a2ec..f3a844dda9 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/FloatingGifMenu.tsx
@@ -1,11 +1,17 @@
import { type PortalScope, ScopedPortal } from '@core/component/ScopedPortal';
import clickOutside from '@core/directive/clickOutside';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { useCanEdit } from '@core/signal/permissions';
import MagnifyingGlassIcon from '@phosphor/magnifying-glass.svg';
import { createCallback } from '@solid-primitives/rootless';
import { debounce } from '@solid-primitives/scheduled';
import { cn, InputGroup, Surface } from '@ui';
-import { $getSelection, $setSelection, type BaseSelection } from 'lexical';
+import {
+ $getRoot,
+ $getSelection,
+ $setSelection,
+ type BaseSelection,
+} from 'lexical';
import {
type Accessor,
createEffect,
@@ -38,10 +44,14 @@ false && clickOutside;
const COLUMNS = 2;
const RESULT_LIMIT = 30;
+// Search field, padding, and "Powered by" row around the grid.
+const PANEL_CHROME_HEIGHT = 76;
+const MAX_GRID_HEIGHT = 280;
/**
* GIF search, opened via TRY_INSERT_GIF_COMMAND (`/gif` or a composer's +).
- * The search field takes focus; arrows move through the grid, Enter inserts,
+ * Desktop focuses the search field; touch leaves the composer focused so the
+ * picker does not vanish. Arrows move through the grid, Enter inserts,
* Escape closes. Portalled like the slash menu so the editor shell's click
* and keydown handlers don't swallow the picker's events.
*/
@@ -62,6 +72,18 @@ export function FloatingGifMenu(
const [searchTerm, setSearchTerm] = createSignal('');
const [debouncedSearchTerm, setDebouncedSearchTerm] = createSignal('');
const [selectedIndex, setSelectedIndex] = createSignal(0);
+ const [menuAvailableHeight, setMenuAvailableHeight] = createSignal<
+ number | undefined
+ >(undefined);
+
+ const gridMaxHeight = () => {
+ const available = menuAvailableHeight();
+ if (available === undefined) return MAX_GRID_HEIGHT;
+ return Math.min(
+ MAX_GRID_HEIGHT,
+ Math.max(0, available - PANEL_CHROME_HEIGHT)
+ );
+ };
// The search field takes focus, so the editor's caret is kept to insert at.
let insertAt: BaseSelection | null = null;
let inputRef: HTMLInputElement | undefined;
@@ -104,7 +126,9 @@ export function FloatingGifMenu(
setTimeout(() => {
if (!canEdit() || !editor()?.isEditable()) return;
setMenuOpen(true);
- inputRef?.focus();
+ // Autofocusing search on touch moves focus out of the composer and
+ // lets iOS hide the caret — the picker then vanishes. Tap to search.
+ if (!isTouchDevice()) inputRef?.focus();
}, 0);
});
@@ -118,6 +142,7 @@ export function FloatingGifMenu(
currentEditor.update(() => {
if (!canEdit() || !currentEditor.isEditable()) return;
if (selection) $setSelection(selection.clone());
+ else if (!$getSelection()) $getRoot().selectEnd();
$insertGifNode(gif);
});
closeToEditor();
@@ -167,10 +192,16 @@ export function FloatingGifMenu(
use:floatWithSelection={{
selection: untrack(() => window.getSelection()),
reactiveOnContainer: editor()?.getRootElement(),
+ onAvailableHeight: setMenuAvailableHeight,
+ fullHeight: MAX_GRID_HEIGHT + PANEL_CHROME_HEIGHT,
}}
use:clickOutside={resetMenu}
on:touchstart={(event) => event.stopPropagation()}
- // Keep focus in the search field while picking a GIF.
+ // Keep composer/search focus while picking a GIF. Cancel both
+ // pointerdown and mousedown; iOS still emits the latter.
+ on:pointerdown={(event) => {
+ if (event.target !== inputRef) event.preventDefault();
+ }}
on:mousedown={(event) => {
if (event.target !== inputRef) event.preventDefault();
}}
@@ -190,7 +221,10 @@ export function FloatingGifMenu(
</InputGroup.Addon>
</InputGroup>
- <div class="h-70 overflow-y-auto overscroll-contain scrollbar-hidden">
+ <div
+ class="overflow-y-auto overscroll-contain scrollbar-hidden"
+ style={{ height: `${gridMaxHeight()}px` }}
+ >
<Switch>
<Match when={gifs.error}>
<div class="flex h-full flex-col items-center justify-center gap-1 text-sm text-ink-muted">
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts
index 2001da084d..61daef2a27 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.browser.e2e.ts
@@ -32,3 +32,18 @@ test('a menu under a composer near the top still opens below it', async ({
expect(menu.y).toBeGreaterThanOrEqual(composer.y + composer.height);
expect(menu.height).toBeGreaterThanOrEqual(256);
});
+
+test('a picker that focuses its search field stays visible above a bottom composer', async ({
+ page,
+}) => {
+ await page.goto(`${fixture}?stealFocus=1`);
+ await expect(page.getByTestId('search')).toBeFocused();
+ const { menu, composer } = await boxes(page);
+
+ expect(
+ await page
+ .getByTestId('menu')
+ .evaluate((el) => getComputedStyle(el).visibility)
+ ).toBe('visible');
+ expect(menu.y + menu.height).toBeLessThanOrEqual(composer.y);
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx
index d47ef9e06e..b7d7007a7a 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/browser-test/composer-menu.tsx
@@ -6,7 +6,7 @@ import { floatWithSelection } from '../floatWithSelection';
const PANEL_DECORATION_HEIGHT = 18;
const MAX_CONTENT_HEIGHT = 256;
-function Menu(props: { rows: number }) {
+function Menu(props: { rows: number; stealFocus?: boolean }) {
const [availableHeight, setAvailableHeight] = createSignal<number>();
const contentMaxHeight = () => {
const h = availableHeight();
@@ -29,6 +29,9 @@ function Menu(props: { rows: number }) {
}
>
<div class="menu-surface rounded-xl p-px py-2">
+ <Show when={props.stealFocus}>
+ <input data-testid="search" type="search" aria-label="Search" />
+ </Show>
<div
class="overflow-y-auto"
style={{ 'max-height': `${contentMaxHeight()}px` }}
@@ -48,6 +51,8 @@ function Menu(props: { rows: number }) {
function Fixture() {
const caretAtTop =
new URLSearchParams(location.search).get('caret') === 'top';
+ const stealFocus =
+ new URLSearchParams(location.search).get('stealFocus') === '1';
const [open, setOpen] = createSignal(false);
const [rows, setRows] = createSignal(1);
let composer!: HTMLDivElement;
@@ -59,6 +64,15 @@ function Fixture() {
document.getSelection()?.removeAllRanges();
document.getSelection()?.addRange(range);
setOpen(true);
+ if (stealFocus) {
+ // GIF picker's search field takes focus after open; the live Range
+ // from getSelection() would otherwise follow it and hide() the menu.
+ setTimeout(() => {
+ document
+ .querySelector<HTMLInputElement>('[data-testid=search]')
+ ?.focus();
+ }, 50);
+ }
setTimeout(() => setRows(12), 100);
});
return (
@@ -73,7 +87,7 @@ function Fixture() {
/
</div>
<Show when={open()}>
- <Menu rows={rows()} />
+ <Menu rows={rows()} stealFocus={stealFocus} />
</Show>
</main>
);
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
index a26d94b9a3..0e118fdb16 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/directive/floatWithSelection.ts
@@ -108,7 +108,9 @@ export function floatWithSelection(
let anchor: Range | Element | null = null;
if (selection.rangeCount >= 1) {
- const range = selection.getRangeAt(0);
+ // Snapshot the caret. getRangeAt() is live, so focusing a picker
+ // search field would rewrite this anchor and hide() the menu.
+ const range = selection.getRangeAt(0).cloneRange();
if (range.collapsed && range.startContainer instanceof Text) {
anchor = range;
} else if (range.collapsed && range.startContainer instanceof Element) {
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/gif/gifPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/gif/gifPlugin.ts
index 045c52957a..2af099b657 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/gif/gifPlugin.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/gif/gifPlugin.ts
@@ -1,6 +1,5 @@
import { $createImageNode, ImageNode } from '@macro-inc/lexical-core';
import {
- $getSelection,
COMMAND_PRIORITY_NORMAL,
createCommand,
type LexicalCommand,
@@ -26,10 +25,9 @@ function registerGifPickerPlugin(
return editor.registerCommand(
TRY_INSERT_GIF_COMMAND,
() => {
- const selection = $getSelection();
- if (!selection) {
- return false;
- }
+ // iOS can clear the Lexical selection on the tap that chose /gif
+ // before this command runs. The picker still opens; insert restores
+ // the caret or falls back to the end of the document.
props.onOpenPicker();
return true;
},
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index c87dee5218..d63a712506 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -279,7 +279,7 @@ above the action row, including for empty and single-line drafts, so the
attachment, delete-reply, and send controls have their own space.
Both the expanded and collapsed composers start with a `+` button (`Add`). It
opens a menu on desktop and a bottom drawer on mobile: `Mention` (opens the `@` typeahead), `Attach files` (the file
-picker; the iOS media picker on iOS), then under `Create` the same actions as
+picker; the iOS media picker on iOS), `GIF` (the same picker as `/gif`), then under `Create` the same actions as
`/task`, `/poll`, `/form` and `/document` (poll and form only with forms on),
then `Ask Macro` (inserts an `@Macro` mention) and, in a channel, `Start a call`
(`Join call` while one is live). On phones, starting a new call opens a
@@ -320,6 +320,10 @@ An `@` inside a word stays literal text. Check hardware-keyboard input too;
it should open only one menu.
The same software-keyboard check applies to `:` for emoji and `/` for formatting
commands: type a search and tap a result without sending the draft.
+Type `/gif` or choose **GIF** from `+`. The picker opens above the composer on
+phones and stays visible after you choose the action, including with the iOS
+keyboard open. Trending GIFs show first; tap search to filter, then tap a GIF
+to insert it without sending the draft.
Closed mention menus do not gather, rank, or paginate candidates. When checking
channel-switch performance, include touch navigation back to the list and reopening