diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte index 8003940275ef..210560df3722 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte @@ -177,12 +177,18 @@ .getServers() .some((s) => s.enabled && prefs.isServerToolsEnabled(s.id) && s.url.trim()); }, + // a phone searches mentions in a drawer: each mobile browser moves the page its own + // way as the keyboard opens, so a list by the form can not stay clear of the text + mentionHasOwnSearch: () => deviceStore.isMobile, onCompact: () => chatStore.compactConversation(), openModelSelector: () => chatFormActionsRef?.openModelSelector(), - // TODO: no typed pickers with an on-screen keyboard for now: each mobile browser moves - // the page its own way as it opens, so a list by the form can not stay clear of the - // text. A drawer with its own search field (as the directory picker is) could. - opensOnInput: () => !deviceStore.isTouch, + // a phone has no `/` commands: a drawer on the first `/` would cover the message, and + // the prompt picker a command leads to is still a popover by the form + opensCommandsOnInput: () => !deviceStore.isMobile, + // with no file search to offer, a phone's drawer stays shut: a desktop's list says why + // by the form, a drawer would cover the message to say it + opensMentionsOnInput: () => + !deviceStore.isMobile || conversationsStore.preferences.isFileSearchEnabled(), setCaretOffset: (offset) => inputRef?.setCaretOffset(offset), setValue: (v) => { value = v; @@ -653,6 +659,7 @@ class="pointer-events-none absolute right-0 left-0" > inputRef?.focus()} diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte index 59020eec2d96..a9dc11d0a451 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte @@ -6,7 +6,7 @@ import * as Drawer from '$lib/components/ui/drawer'; import * as Popover from '$lib/components/ui/popover'; import { DEFAULT_MOBILE_BREAKPOINT, HOME_TILDE, SEARCH, UI_DATA_ATTRS } from '$lib/constants'; - import { BuiltInTool, GlobSearchType, KeyboardKey, ToolSource } from '$lib/enums'; + import { BuiltInTool, GlobSearchType, KeyboardKey } from '$lib/enums'; import { useDebouncedSearch } from '$lib/hooks/use-debounced-search.svelte'; import { usePickerNavigation } from '$lib/hooks/use-picker-navigation.svelte'; import { useScrollActiveRow } from '$lib/hooks/use-scroll-active-row.svelte'; @@ -61,11 +61,7 @@ // hidden too: it resolves the picked folder name through the same tool. const fileSearchKey = $derived(toolsStore.getPermissionKey(BuiltInTool.SERVER_FILE_GLOB_SEARCH)); // effective policy: the active conversation's tool policy, or global defaults - const fileSearchEnabled = $derived( - fileSearchKey !== null && - conversationsStore.preferences.isToolEnabled(fileSearchKey) && - conversationsStore.preferences.isCategoryEnabled(ToolSource.SERVER) - ); + const fileSearchEnabled = $derived(conversationsStore.preferences.isFileSearchEnabled()); const searchUnavailableMessage = $derived( fileSearchKey === null ? 'File search is unavailable on this server - type a full path and press Enter' diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte index d09a3d3cb85d..3683cad4fe49 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMention.svelte @@ -2,16 +2,11 @@ import { File, Folder } from '@lucide/svelte'; import { ChatFormPickerList, ChatFormPickerListItem } from '$lib/components/app/chat'; import HighlightedMatch from '$lib/components/app/forms/HighlightedMatch.svelte'; + import * as Drawer from '$lib/components/ui/drawer'; import * as Popover from '$lib/components/ui/popover'; import * as Tooltip from '$lib/components/ui/tooltip'; import { FILE_GLOB_SEARCH_PICKERS, HOME_TILDE, SEARCH } from '$lib/constants'; - import { - BuiltInTool, - FileMentionEntryType, - GlobSearchType, - KeyboardKey, - ToolSource - } from '$lib/enums'; + import { BuiltInTool, FileMentionEntryType, GlobSearchType, KeyboardKey } from '$lib/enums'; import { useDebouncedSearch } from '$lib/hooks/use-debounced-search.svelte'; import { usePickerNavigation } from '$lib/hooks/use-picker-navigation.svelte'; import { conversationsStore, deviceStore, settingsStore, toolsStore } from '$lib/stores'; @@ -19,14 +14,16 @@ import { abbreviateHome, runGlobSearchWithChildren } from '$lib/utils'; /** - * Floating file/folder mention picker. The chat input is the search - * surface: `query` (typed after `@`) drives a `file_glob_search` tool - * call scoped to `scopePath`. The parent owns the "dismissed token, - * don't re-open until it changes" snapshot. + * File/folder mention picker: `query` drives a `file_glob_search` tool + * call scoped to `scopePath`. It floats above the form with the chat + * input as the search surface (`query` is the text typed after `@`), + * or on a phone is a drawer with a search field of its own. The parent + * owns the "dismissed token, don't re-open until it changes" snapshot. */ interface Props { class?: string; isOpen: boolean; + /** Two-way bound: the drawer's search field writes it. */ query: string; customAnchor?: HTMLElement | null; scopePath?: string | null; @@ -43,7 +40,7 @@ onClose, onOpened, onSelect, - query, + query = $bindable(), scopePath = null }: Props = $props(); @@ -59,11 +56,7 @@ // why instead of firing searches that would only fail. const fileSearchKey = $derived(toolsStore.getPermissionKey(BuiltInTool.SERVER_FILE_GLOB_SEARCH)); // effective policy: the active conversation's tool policy, or global defaults - const fileSearchEnabled = $derived( - fileSearchKey !== null && - conversationsStore.preferences.isToolEnabled(fileSearchKey) && - conversationsStore.preferences.isCategoryEnabled(ToolSource.SERVER) - ); + const fileSearchEnabled = $derived(conversationsStore.preferences.isFileSearchEnabled()); let searchResults = $state([]); let searchError = $state(null); @@ -136,6 +129,9 @@ return 'File search is disabled - enable "Search files" in Settings > Tools to use @-mentions'; } + // nothing searched yet: the drawer opens before a query is typed + if (!trimmedQuery) return undefined; + return searchError ? `Search failed - ${searchError}` : 'No matching files or folders'; }); @@ -195,97 +191,130 @@ } - { - if (!open) onClose(); - }} - open={isOpen} -> - - - - event.preventDefault()} - onOpenAutoFocus={(event) => event.preventDefault()} - onkeydown={handleKeydown} - preventScroll={false} - side="top" - sideOffset={12} +{#snippet picker(inDrawer: boolean)} + entry.type + ':' + entry.path} + items={displayedItems} + onSearchClose={inDrawer ? onClose : undefined} + scrollTrigger={nav.scrollTrigger} + searchPlaceholder="Search files and folders" + selectedIndex={nav.hoveredIndex} + showSearchInput={inDrawer} > - entry.type + ':' + entry.path} - items={displayedItems} - scrollTrigger={nav.scrollTrigger} - searchQuery={query ?? ''} - selectedIndex={nav.hoveredIndex} - showSearchInput={false} - > - {#snippet item(entry, index, isSelected)} - handleSelect(entry)} - onmouseenter={() => nav.setHover(index)} - > - {@const Icon = entry.type === FileMentionEntryType.DIRECTORY ? Folder : File} - - -
-
- {#if showTooltip} - - - {#snippet child({ props })} - {entry.name} - {/snippet} - - - -

{entry.path}

-
-
- {:else} - {entry.name} - {/if} - - - {entry.type} - -
- - - + {#snippet item(entry, index, isSelected)} + handleSelect(entry)} + onmouseenter={() => nav.setHover(index)} + > + {@const Icon = entry.type === FileMentionEntryType.DIRECTORY ? Folder : File} + + +
+
+ {#if showTooltip} + + + {#snippet child({ props })} + {entry.name} + {/snippet} + + + +

{entry.path}

+
+
+ {:else} + {entry.name} + {/if} + + + {entry.type}
- - {/snippet} - - - + + + + +
+
+ {/snippet} + +{/snippet} + + +{#if deviceStore.isMobile} + + { + if (!open) onClose(); + }} + open={isOpen} + > + + + Mention a file or folder + + Search for a file or folder to mention in the message + + +
+ {@render picker(true)} +
+
+
+{:else} + { + if (!open) onClose(); + }} + open={isOpen} + > + + + + event.preventDefault()} + onOpenAutoFocus={(event) => event.preventDefault()} + onkeydown={handleKeydown} + preventScroll={false} + side="top" + sideOffset={12} + > + {@render picker(false)} + + +{/if} diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickers.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickers.svelte index 7f8ba3e6d1e9..ffdf9a73eb61 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickers.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickers.svelte @@ -42,7 +42,7 @@ isCommandPickerOpen, isMentionPickerOpen, isPromptPickerOpen, - mentionQuery, + mentionQuery = $bindable(''), onCommandPickerClose, onCommandSelect, onMentionOpened, @@ -100,12 +100,12 @@ /> {})} onOpened={onMentionOpened} onSelect={onMentionSelect ?? (() => {})} - query={mentionQuery ?? ''} scopePath={scopePath ?? null} /> diff --git a/ui/apps/chat/src/lib/hooks/use-chat-form-pickers.svelte.ts b/ui/apps/chat/src/lib/hooks/use-chat-form-pickers.svelte.ts index 4e29afed7ee1..e600c099a3de 100644 --- a/ui/apps/chat/src/lib/hooks/use-chat-form-pickers.svelte.ts +++ b/ui/apps/chat/src/lib/hooks/use-chat-form-pickers.svelte.ts @@ -20,8 +20,12 @@ export interface UseChatFormPickersOptions { getCaretOffset: () => number | undefined; setCaretOffset: (offset: number) => void; focusInput: () => void; - /** Whether typing `/` or `@` opens a picker at all. */ - opensOnInput: () => boolean; + /** Whether typing `/` opens the command picker. */ + opensCommandsOnInput: () => boolean; + /** Whether typing `@` opens the mention picker. */ + opensMentionsOnInput: () => boolean; + /** The mention picker has its own search field (a phone's drawer): a bare `@` opens it. */ + mentionHasOwnSearch: () => boolean; /** Gates `/model`. */ getShowModelSelector: () => boolean; /** Gates `/prompt`. */ @@ -120,12 +124,10 @@ export function useChatFormPickers(opts: UseChatFormPickersOptions) { } function handleInput() { - if (!opts.opensOnInput()) return; - const value = opts.getValue(); const cursor = opts.getCaretOffset() ?? value.length; - if (value.startsWith(PROMPT_TRIGGER_PREFIX)) { + if (opts.opensCommandsOnInput() && value.startsWith(PROMPT_TRIGGER_PREFIX)) { isMentionPickerOpen = false; mentionQuery = ''; isPromptPickerOpen = false; @@ -194,19 +196,24 @@ export function useChatFormPickers(opts: UseChatFormPickersOptions) { isWorkingDirectoryPickerOpen = false; } - const token = findMentionToken(value, cursor); + const token = opts.opensMentionsOnInput() ? findMentionToken(value, cursor) : null; if (token) { + const hasOwnSearch = opts.mentionHasOwnSearch(); // Dismissed token stays literal: don't reopen until it changes. + // A picker with its own search field takes the focus, so there + // the token stays literal until it is deleted. const isDismissedSticky = mentionDismissedSnapshot !== null && mentionDismissedSnapshot.start === token.start && - mentionDismissedSnapshot.query === token.query; + (hasOwnSearch || mentionDismissedSnapshot.query === token.query); if (!isDismissedSticky) { // Only search once a char follows `@`; a bare `@` is a no-op // (otherwise the picker flashes an empty hint on re-type). - if (token.query.length > 0) { + // A picker with its own search field opens on the bare `@`: + // the query is typed there, and the token only seeds it. + if (hasOwnSearch || token.query.length > 0) { mentionDismissedSnapshot = null; isMentionPickerOpen = true; mentionQuery = token.query; diff --git a/ui/apps/chat/src/lib/stores/conversations/preferences.svelte.ts b/ui/apps/chat/src/lib/stores/conversations/preferences.svelte.ts index 29d7c45ca091..f925d68f9059 100644 --- a/ui/apps/chat/src/lib/stores/conversations/preferences.svelte.ts +++ b/ui/apps/chat/src/lib/stores/conversations/preferences.svelte.ts @@ -12,7 +12,7 @@ */ import { REASONING_EFFORT_DEFAULT_LOCALSTORAGE_KEY } from '$lib/constants'; -import { ReasoningEffort, ToolSource } from '$lib/enums'; +import { BuiltInTool, ReasoningEffort, ToolSource } from '$lib/enums'; import { DatabaseService } from '$lib/services/database.service'; // direct imports between stores, not via the barrel, to avoid circular deps import { mcpStore } from '$lib/stores/mcp/index.svelte'; @@ -156,6 +156,13 @@ export class ConversationPreferences { return !this._disabledToolCategories.has(source); } + /** True when `file_glob_search`, which the pickers search with, is served and left enabled. */ + isFileSearchEnabled(): boolean { + const key = toolsStore.getPermissionKey(BuiltInTool.SERVER_FILE_GLOB_SEARCH); + + return key !== null && this.isToolEnabled(key) && this.isCategoryEnabled(ToolSource.SERVER); + } + /** Group checkbox state: the category flag, or the server key for MCP groups. */ isGroupChecked(group: ToolGroup): boolean { return group.source === ToolSource.MCP && group.serverId diff --git a/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts index 120587c1b80f..01ac8bc5e58a 100644 --- a/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts +++ b/ui/apps/chat/tests/client/chat-form-expansion.svelte.test.ts @@ -159,6 +159,19 @@ describe('ChatForm expansion', () => { expect(scroller.scrollHeight).toBeGreaterThan(scroller.clientHeight); }); + it('scrolls a long message inside the editor', async () => { + const draft = Array.from({ length: 200 }, (_, i) => `line ${i + 1}`).join('\n'); + const { container } = await renderForm(draft); + const input = container.querySelector('.chat-form-input')!; + const scroller = container.querySelector('.cm-scroller')!; + + // stands in for the stylesheet's --max-message-height, which the tests do not load + input.style.maxHeight = '200px'; + + await expect.poll(() => scroller.clientHeight).toBeLessThanOrEqual(200); + expect(scroller.scrollHeight).toBeGreaterThan(scroller.clientHeight); + }); + it('mirrors the height of the text onto the input', async () => { const { container, editor, write } = await renderForm(); const input = container.querySelector('.chat-form-input')!; diff --git a/ui/apps/chat/tests/client/chat-form-pickers-phone.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-pickers-phone.svelte.test.ts new file mode 100644 index 000000000000..238be99e1ff5 --- /dev/null +++ b/ui/apps/chat/tests/client/chat-form-pickers-phone.svelte.test.ts @@ -0,0 +1,259 @@ +// Guards the chat form's typed pickers on a phone: `@` opens a drawer with a search +// field of its own, since a list by the form can not be placed reliably around the +// on-screen keyboard, and `/` opens nothing. A desktop keeps its lists by the form. + +import ChatFormPickersHarness from './components/ChatFormPickersHarness.svelte'; +import ChatFormTestWrapper from './components/ChatFormTestWrapper.svelte'; +import { EditorView } from '@codemirror/view'; +import { BuiltInTool } from '$lib/enums'; +import { ToolsService } from '$lib/services/tools.service'; +import { toolsStore } from '$lib/stores/tools.svelte'; +import type { OpenAIToolDefinition } from '$lib/types'; +import { tick } from 'svelte'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { page, userEvent } from 'vitest/browser'; +import { render } from 'vitest-browser-svelte'; + +const PHONE = { height: 844, width: 390 }; +const DESKTOP = { height: 900, width: 1280 }; +const FILE_SEARCH_DEF: OpenAIToolDefinition = { + function: { description: '', name: BuiltInTool.SERVER_FILE_GLOB_SEARCH, parameters: {} }, + type: 'function' +}; +// what the editor holds once `src/main.ts` under `/home/u` is picked +const MENTION = '[main.ts](file:///home/u/src/main.ts) '; +// long enough for a picker to have mounted, as it does when it opens +const PICKER_MOUNT_MS = 300; + +// The store keeps its server tool list private; tests inject it through +// the reactive field so the derived gates recompute. +function setServerTools(defs: OpenAIToolDefinition[]) { + (toolsStore as unknown as { _serverTools: OpenAIToolDefinition[] })._serverTools = defs; +} + +async function renderForm(props: { expandable?: boolean } = {}) { + const { container } = render(ChatFormTestWrapper, props); + + await tick(); + + const content = container.querySelector('.cm-content'); + const editor = content && EditorView.findFromDOM(content); + + if (!editor) throw new Error('editor not rendered'); + + // as while writing: the keyboard is in the message + editor.focus(); + + // as typing does: the text goes in at the caret, which ends up after it + const type = async (text: string) => { + editor.dispatch(editor.state.replaceSelection(text)); + await tick(); + }; + const text = () => editor.state.doc.toString(); + const caret = () => editor.state.selection.main.head; + + return { caret, container, editor, text, type }; +} + +const drawer = () => document.querySelector('[data-slot="drawer-content"]'); +const popover = () => document.querySelector('[data-slot="popover-content"]'); +const searchField = () => drawer()?.querySelector('input[type="search"]') ?? null; +const settle = () => new Promise((resolve) => setTimeout(resolve, PICKER_MOUNT_MS)); + +async function pickMainTs() { + await userEvent.fill(searchField()!, 'main'); + await page.getByText('main.ts', { exact: true }).click(); +} + +describe('ChatForm pickers on a phone', () => { + beforeEach(() => { + setServerTools([FILE_SEARCH_DEF]); + vi.spyOn(ToolsService, 'executeToolRaw').mockResolvedValue({ + base: '/home/u', + entries: [{ path: 'src/main.ts', type: 'file' }] + }); + }); + + afterEach(async () => { + setServerTools([]); + vi.restoreAllMocks(); + await page.viewport(DESKTOP.width, DESKTOP.height); + }); + + it('opens the command picker on a desktop', async () => { + await page.viewport(DESKTOP.width, DESKTOP.height); + + const { type } = await renderForm(); + + await type('/'); + + await expect.poll(popover).not.toBeNull(); + }); + + it('searches mentions by the form on a desktop, once a character follows the @', async () => { + await page.viewport(DESKTOP.width, DESKTOP.height); + + const { type } = await renderForm(); + + await type('@'); + await settle(); + expect(popover()).toBeNull(); + + await type('m'); + + await expect.poll(popover).not.toBeNull(); + expect(drawer()).toBeNull(); + expect(popover()!.querySelector('input')).toBeNull(); + }); + + it('opens no picker for a / on a phone', async () => { + await page.viewport(PHONE.width, PHONE.height); + + const { type } = await renderForm(); + + await type('/'); + await settle(); + + expect(popover()).toBeNull(); + expect(drawer()).toBeNull(); + }); + + it('opens a drawer with a search field for an @ on a phone', async () => { + await page.viewport(PHONE.width, PHONE.height); + + const { type } = await renderForm(); + + await type('@'); + + await expect.poll(searchField).not.toBeNull(); + expect(popover()).toBeNull(); + // the query is typed in the drawer, not in the message: the focus moves there + await expect.poll(() => document.activeElement).toBe(searchField()); + }); + + it('opens no drawer for an @ on a phone when there is no file search to offer', async () => { + setServerTools([]); + await page.viewport(PHONE.width, PHONE.height); + + const { type } = await renderForm(); + + await type('@'); + await settle(); + + expect(drawer()).toBeNull(); + }); + + it('inserts the mention picked in the drawer where the @ was', async () => { + await page.viewport(PHONE.width, PHONE.height); + + const { caret, editor, text, type } = await renderForm(); + + await type('see now'); + // between the two spaces + editor.dispatch({ selection: { anchor: 4 } }); + await type('@'); + await expect.poll(searchField).not.toBeNull(); + await pickMainTs(); + + await expect.poll(text).toBe(`see ${MENTION} now`); + expect(caret()).toBe(`see ${MENTION}`.length); + await expect.poll(drawer).toBeNull(); + }); + + it('leaves the message and the caret alone when the drawer is dismissed', async () => { + await page.viewport(PHONE.width, PHONE.height); + + const { caret, editor, text, type } = await renderForm(); + + await type('a b'); + editor.dispatch({ selection: { anchor: 2 } }); + await type('@'); + await expect.poll(() => document.activeElement).toBe(searchField()); + await userEvent.fill(searchField()!, 'main'); + await userEvent.keyboard('{Escape}'); + + await expect.poll(drawer).toBeNull(); + expect(text()).toBe('a @ b'); + expect(caret()).toBe(3); + // writing goes on where it stopped + await expect.poll(() => editor.hasFocus).toBe(true); + + // the dismissed @ is plain text from here on + await type('alice'); + await settle(); + + expect(drawer()).toBeNull(); + expect(text()).toBe('a @alice b'); + }); + + it('opens the drawer from the expanded sheet too', async () => { + await page.viewport(PHONE.width, PHONE.height); + + const { container, text, type } = await renderForm({ expandable: true }); + + await type('one\ntwo\nthree\nfour '); + expect(container.querySelector('.chat-form-input.expanded')).not.toBeNull(); + + await type('@'); + await expect.poll(searchField).not.toBeNull(); + await pickMainTs(); + + await expect.poll(text).toBe(`one\ntwo\nthree\nfour ${MENTION}`); + await expect.poll(drawer).toBeNull(); + }); +}); + +describe('picker routing on a phone', () => { + it('opens the mention picker on a bare @ and seeds it with what follows', async () => { + const screen = render(ChatFormPickersHarness, { phone: true }); + const pickers = screen.component.getPickers(); + + screen.component.type('@'); + expect(pickers.isMentionPickerOpen).toBe(true); + expect(pickers.mentionQuery).toBe(''); + + pickers.handleMentionPickerClose(); + screen.component.type(''); + screen.component.type('@src'); + expect(pickers.isMentionPickerOpen).toBe(true); + expect(pickers.mentionQuery).toBe('src'); + }); + + it('keeps a dismissed @ literal until it is deleted', async () => { + const screen = render(ChatFormPickersHarness, { phone: true }); + const pickers = screen.component.getPickers(); + + screen.component.type('@'); + pickers.handleMentionPickerClose(); + + screen.component.type('@a'); + screen.component.type('@al'); + expect(pickers.isMentionPickerOpen).toBe(false); + + screen.component.type(''); + screen.component.type('@'); + expect(pickers.isMentionPickerOpen).toBe(true); + }); + + it('treats a leading / as text, so an @ after it still opens the picker', async () => { + const screen = render(ChatFormPickersHarness, { phone: true }); + const pickers = screen.component.getPickers(); + + screen.component.type('/model'); + expect(pickers.isCommandPickerOpen).toBe(false); + + screen.component.type('/tmp/build fails, see @'); + expect(pickers.isMentionPickerOpen).toBe(true); + }); + + it('waits for a character after the @ where the chat input is the search field', async () => { + const screen = render(ChatFormPickersHarness); + const pickers = screen.component.getPickers(); + + screen.component.type('@'); + expect(pickers.isMentionPickerOpen).toBe(false); + + screen.component.type('@s'); + expect(pickers.isMentionPickerOpen).toBe(true); + }); +}); diff --git a/ui/apps/chat/tests/client/components/ChatFormPickersHarness.svelte b/ui/apps/chat/tests/client/components/ChatFormPickersHarness.svelte index 9e1dda35ef4c..e3e638d350ce 100644 --- a/ui/apps/chat/tests/client/components/ChatFormPickersHarness.svelte +++ b/ui/apps/chat/tests/client/components/ChatFormPickersHarness.svelte @@ -4,6 +4,13 @@ type UseChatFormPickersReturn } from '$lib/hooks/use-chat-form-pickers.svelte'; + interface Props { + /** As on a phone: the mention picker has its own search field and `/` opens nothing. */ + phone?: boolean; + } + + let { phone = false }: Props = $props(); + let value = $state(''); let caretOffset = $state(0); const calls: string[] = []; @@ -19,13 +26,15 @@ getValue: () => value, hasCwdTools: () => true, hasPrompts: () => true, + mentionHasOwnSearch: () => phone, onCompact: () => { calls.push('onCompact'); }, openModelSelector: () => { calls.push('openModelSelector'); }, - opensOnInput: () => true, + opensCommandsOnInput: () => !phone, + opensMentionsOnInput: () => true, setCaretOffset: (o) => { caretOffset = o; },