From 6886628cb18df4b29ae9ff755b23111292af4fac Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Wed, 28 Oct 2026 07:53:41 +0100 Subject: [PATCH] ui : Search dialog (#31173) * ui : replace the sidebar search mode with a search dialog Search opens a spotlight dialog (Cmd+K or the Search entry under New chat in the sidebar) with keyboard navigation over recent chats and sidebar actions. Phones keep the search page. Sidebar actions show their shortcuts, with new ones for Settings (Cmd+,) and Models (Shift+Cmd+M). Assisted-by: Claude (Opus 5.5 Medium) * ui : ignore search dialog keys while an IME is composing Enter confirms an IME candidate and the arrow keys move through the candidates, so the search field leaves them to the IME instead of opening the highlighted result or moving the highlight. Assisted-by: Claude (Opus 5.5 Medium) --- .../app/dialogs/DialogSearch.svelte | 261 ++++++++++++++++++ .../src/lib/components/app/dialogs/index.ts | 8 + .../app/misc/KeyboardShortcutInfo.svelte | 5 +- .../SidebarNavigation.svelte | 118 ++++---- .../SidebarNavigationActions.svelte | 97 ++----- .../SidebarNavigationConversationItem.svelte | 15 +- .../SidebarNavigationConversationList.svelte | 180 +++++------- .../lib/components/app/navigation/index.ts | 20 +- .../src/lib/constants/formatters.constants.ts | 4 + tools/ui/src/lib/constants/index.ts | 1 + .../constants/keyboard-shortcuts.constants.ts | 9 + tools/ui/src/lib/constants/ui.constants.ts | 12 +- tools/ui/src/lib/enums/keyboard.enums.ts | 3 + tools/ui/src/lib/enums/ui.enums.ts | 1 + .../hooks/use-keyboard-shortcuts.svelte.ts | 22 +- tools/ui/src/lib/utils/formatters.ts | 30 ++ tools/ui/src/lib/utils/index.ts | 1 + tools/ui/src/routes/+layout.svelte | 18 +- .../stories/SidebarNavigation.stories.svelte | 5 +- tools/ui/tests/unit/formatters.test.ts | 44 ++- 20 files changed, 575 insertions(+), 279 deletions(-) create mode 100644 tools/ui/src/lib/components/app/dialogs/DialogSearch.svelte create mode 100644 tools/ui/src/lib/constants/keyboard-shortcuts.constants.ts diff --git a/tools/ui/src/lib/components/app/dialogs/DialogSearch.svelte b/tools/ui/src/lib/components/app/dialogs/DialogSearch.svelte new file mode 100644 index 000000000..58de5b025 --- /dev/null +++ b/tools/ui/src/lib/components/app/dialogs/DialogSearch.svelte @@ -0,0 +1,261 @@ + + +{#snippet hint(label: string, keys: (string | Component)[])} + + {label} + + + {#each keys as Key, index (index)} + + {#if typeof Key === 'string'} + {Key} + {:else} + + {/if} + + {/each} + + +{/snippet} + + + { + event.preventDefault(); + inputRef?.focus(); + }} + > + Search + +
+
+ 0 ? `search-result-${activeIndex}` : undefined} + aria-controls="search-results" + aria-expanded="true" + autocomplete="off" + class="h-10 min-w-0 flex-1 border-0 bg-transparent px-1 text-lg outline-none placeholder:text-muted-foreground focus:outline-none focus-visible:ring-0" + oninput={() => (highlighted = 0)} + onkeydown={handleKeydown} + placeholder="Search" + role="combobox" + spellcheck={false} + /> + + handleOpenChange(false)} + /> +
+
+ +
+ {#each sections as section, sectionIndex (section.title)} + {@const offset = sections + .slice(0, sectionIndex) + .reduce((total, previous) => total + previous.entries.length, 0)} + +
+

+ {section.title} +

+ + {#each section.entries as entry, entryIndex (entry.id)} + {@const index = offset + entryIndex} + {@const isActive = index === activeIndex} + + + {/each} +
+ {:else} +

{emptyMessage}

+ {/each} +
+ +
+ {@render hint('Close', ['Esc'])} + + {@render hint('Navigate', [ArrowUp, ArrowDown])} + + {@render hint('Open', [CornerDownLeft])} +
+
+
diff --git a/tools/ui/src/lib/components/app/dialogs/index.ts b/tools/ui/src/lib/components/app/dialogs/index.ts index f038c447b..2083e2660 100644 --- a/tools/ui/src/lib/components/app/dialogs/index.ts +++ b/tools/ui/src/lib/components/app/dialogs/index.ts @@ -108,6 +108,14 @@ export { default as DialogExportSettings } from './DialogExportSettings.svelte'; */ export { default as DialogConfirmation } from './DialogConfirmation.svelte'; +/** + * **DialogSearch** - Spotlight-style search over chats and sidebar actions + * + * Opens over the app with a focused input and a keyboard-driven result list: + * arrow keys move the highlight, Enter opens, Escape closes. Desktop only; phones use the `/search` page. + */ +export { default as DialogSearch } from './DialogSearch.svelte'; + /** * **DialogConfirmDownload** - Confirm a destructive download action * diff --git a/tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte b/tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte index 35d38d246..2c51423ec 100644 --- a/tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte +++ b/tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte @@ -1,5 +1,6 @@ @@ -505,7 +525,7 @@ /> - {#if isOnMobile || (uiStore.isSidebarExpanded && !alwaysShowOnDesktop)} + {#if isOnMobile || uiStore.isSidebarExpanded}
- + {#if isOnMobile || !alwaysShowOnDesktop} + + {/if}
{/if} @@ -536,26 +558,14 @@ : ''} {deviceStore.isMobile && !uiStore.isSidebarExpanded ? 'opacity-0 !h-0' : ''}" > 768 ? uiStore.isSidebarExpanded : true} - onManageModelsClick={() => openDialog(() => uiStore.openModelsManager())} - onMcpClick={() => openDialog(() => (mcpDialogOpen = true))} - onNewChat={() => { + onAction={handleSidebarAction} + onNavigate={() => { if (deviceStore.isMobile) { scheduleMobileCollapse(); } }} - onSearchClick={() => { - uiStore.isSidebarExpanded = true; - isSearchModeActive = true; - }} - onSearchDeactivated={() => { - isSearchModeActive = false; - searchQuery = ''; - }} - onSettingsClick={() => openDialog(() => (settingsDialogOpen = true))} /> {#if uiStore.isSidebarExpanded || isOnMobile} @@ -565,9 +575,8 @@ allVisibleSelected={visibleSelectionStats.visibleCount > 0 && visibleSelectionStats.selectedVisibleCount === visibleSelectionStats.visibleCount} class="px-2" + conversations={conversationsStore.conversations} {currentChatId} - {filteredConversations} - {isSearchModeActive} {isSelectionMode} onBulkDelete={handleBulkDelete} onBulkExport={handleBulkExport} @@ -583,7 +592,6 @@ onStop={handleStopGeneration} onToggleSelect={toggleSelected} {pinStateIsMixed} - {searchQuery} {selectedIds} someVisibleSelected={visibleSelectionStats.selectedVisibleCount > 0 && visibleSelectionStats.selectedVisibleCount < visibleSelectionStats.visibleCount} @@ -638,6 +646,8 @@ + + diff --git a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte b/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte index d048bbce8..599de6c03 100644 --- a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte +++ b/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte @@ -1,18 +1,16 @@
- {#if isSearchModeActive} - - {:else} - {#if pinnedConversations.length > 0} -
-
- + {#if pinnedConversations.length > 0} +
+
+ - Pinned -
+ Pinned
+
-
    - {#each pinnedConversations as { conversation, depth } (conversation.id)} +
      + {#each pinnedConversations as { conversation, depth } (conversation.id)} +
    • + +
    • + {/each} +
    + {/if} + +
    + {#if conversations.length > 0} +
    + Recent conversations +
    + {/if} + +
    +
      + {#each unpinnedConversations as { conversation, depth } (conversation.id)}
    • {/each} + + {#if unpinnedConversations.length === 0} +
    • +

      No conversations yet

      +
    • + {/if}
    - {/if} - -
    - {#if filteredConversations.length > 0} -
    - Recent conversations -
    - {/if} - -
    -
      - {#each unpinnedConversations as { conversation, depth } (conversation.id)} -
    • - -
    • - {/each} - - {#if unpinnedConversations.length === 0} -
    • -

      - {recentEmptyMessage} -

      -
    • - {/if} -
    -
    +
    - {#if isSelectionMode} - - {/if} + {#if isSelectionMode} + {/if}
    diff --git a/tools/ui/src/lib/components/app/navigation/index.ts b/tools/ui/src/lib/components/app/navigation/index.ts index ea5ad1794..aeee92051 100644 --- a/tools/ui/src/lib/components/app/navigation/index.ts +++ b/tools/ui/src/lib/components/app/navigation/index.ts @@ -66,14 +66,13 @@ export { default as DropdownMenuActions } from './DropdownMenuActions.svelte'; /** * **SidebarNavigation** - Sidebar with actions menu and conversation list * - * Collapsible sidebar displaying conversation history with search and - * management actions. Integrates with ShadCN sidebar component for + * Collapsible sidebar displaying conversation history and management actions. Integrates with ShadCN sidebar component for * consistent styling and mobile responsiveness. * * **Architecture:** * - Uses ShadCN Sidebar.* components for structure * - Fetches conversations from conversationsStore - * - Manages search state and filtered results locally + * - Owns the search dialog (desktop) and routes phones to the search page * - Handles conversation CRUD operations via conversationsStore * * **Navigation:** @@ -88,7 +87,7 @@ export { default as DropdownMenuActions } from './DropdownMenuActions.svelte'; * - Delete All: Removes all conversations with confirmation * * **Features:** - * - Search/filter conversations by title + * - Search dialog (Cmd+K) over chats and sidebar actions * - Conversation list with message previews (first message truncated) * - Active conversation highlighting * - Mobile-responsive collapse/expand via ShadCN sidebar @@ -96,7 +95,6 @@ export { default as DropdownMenuActions } from './DropdownMenuActions.svelte'; * - Settings button opens DialogChatSettings * * **Exported API:** - * - `activateSearchMode()` - Focus search input programmatically * - `editActiveConversation()` - Open rename dialog for current conversation * * @example @@ -148,17 +146,14 @@ export { default as SidebarNavigationSelectionBar } from './SidebarNavigation/Si * **SidebarNavigationConversationList** - Grouped conversation list * * Pure-presentational list of conversations. Splits items into a Pinned - * section (when not in search mode) and a Recent Conversations / Search - * Results section with the unpinned items. Item selection, edit, delete, + * section and a Recent Conversations section with the unpinned items. Item selection, edit, delete, * and stop-generation are delegated to the caller via callbacks. * * @example * ```svelte * void; editActiveConversation?: () => void; - onSearchActivated?: () => void; deleteActiveConversation?: () => void; navigateToPrevConversation?: () => void; navigateToNextConversation?: () => void; navigateToPrevTab?: () => void; navigateToNextTab?: () => void; + openModelsManager?: () => void; + openSearch?: () => void; + openSettings?: () => void; toggleSidebar?: () => void; } @@ -21,8 +22,12 @@ export function useKeyboardShortcuts(callbacks: KeyboardShortcutsCallbacks) { if (isCmdOrCtrl && event.key === KeyboardKey.K_LOWER) { event.preventDefault(); - callbacks.activateSearchMode?.(); - callbacks.onSearchActivated?.(); + callbacks.openSearch?.(); + } + + if (isCmdOrCtrl && event.key === KeyboardKey.COMMA) { + event.preventDefault(); + callbacks.openSettings?.(); } if (isCmdOrCtrl && event.key === KeyboardKey.B_LOWER) { @@ -40,6 +45,15 @@ export function useKeyboardShortcuts(callbacks: KeyboardShortcutsCallbacks) { void conversationsStore.openNewChat(); } + if ( + isCmdOrCtrl && + event.shiftKey && + (event.key === KeyboardKey.M_LOWER || event.key === KeyboardKey.M_UPPER) + ) { + event.preventDefault(); + callbacks.openModelsManager?.(); + } + if (event.shiftKey && isCmdOrCtrl && event.key === KeyboardKey.E_UPPER) { event.preventDefault(); callbacks.editActiveConversation?.(); diff --git a/tools/ui/src/lib/utils/formatters.ts b/tools/ui/src/lib/utils/formatters.ts index 20abde51c..6a174cd48 100644 --- a/tools/ui/src/lib/utils/formatters.ts +++ b/tools/ui/src/lib/utils/formatters.ts @@ -1,6 +1,8 @@ import { MEDIUM_DURATION_THRESHOLD, MS_PER_SECOND, + RELATIVE_TIME_MAX_DAYS, + SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SHORT_DURATION_THRESHOLD @@ -102,6 +104,34 @@ export function formatJsonPretty(jsonString: string): string { } } +/** + * Formats a past timestamp as a coarse relative label. + * Examples: "just now", "37 minutes ago", "1 hour ago", "3 days ago" + * + * @param timestamp - Epoch milliseconds in the past + * @returns Relative time string + */ +export function formatRelativeTime(timestamp: number): string { + const elapsedSeconds = (Date.now() - timestamp) / MS_PER_SECOND; + const plural = (value: number, unit: string) => `${value} ${unit}${value === 1 ? '' : 's'} ago`; + + if (elapsedSeconds < SECONDS_PER_MINUTE) return 'just now'; + + if (elapsedSeconds < SECONDS_PER_HOUR) { + return plural(Math.floor(elapsedSeconds / SECONDS_PER_MINUTE), 'minute'); + } + + if (elapsedSeconds < SECONDS_PER_DAY) { + return plural(Math.floor(elapsedSeconds / SECONDS_PER_HOUR), 'hour'); + } + + if (elapsedSeconds < RELATIVE_TIME_MAX_DAYS * SECONDS_PER_DAY) { + return plural(Math.floor(elapsedSeconds / SECONDS_PER_DAY), 'day'); + } + + return new Date(timestamp).toLocaleDateString(); +} + /** * Format time as HH:MM:SS in 24-hour format * diff --git a/tools/ui/src/lib/utils/index.ts b/tools/ui/src/lib/utils/index.ts index f6686a5a2..1f9cffcbe 100644 --- a/tools/ui/src/lib/utils/index.ts +++ b/tools/ui/src/lib/utils/index.ts @@ -99,6 +99,7 @@ export { formatJsonPretty, formatTime, formatPerformanceTime, + formatRelativeTime, formatAttachmentText } from './formatters'; diff --git a/tools/ui/src/routes/+layout.svelte b/tools/ui/src/routes/+layout.svelte index 2bec18b6c..3fc1e46ef 100644 --- a/tools/ui/src/routes/+layout.svelte +++ b/tools/ui/src/routes/+layout.svelte @@ -13,7 +13,6 @@ HEADERS, MODELS_ROUTE_ID, NEW_CHAT_TAB_ID, - ROUTES, SETTINGS_KEYS, TOOLTIP_DELAY_DURATION } from '$lib/constants'; @@ -47,12 +46,7 @@ let innerHeight = $state(); let innerWidth = $state(browser ? window.innerWidth : 0); - let chatSidebar: - | { - activateSearchMode?: () => void; - editActiveConversation?: () => void; - } - | undefined = $state(); + let chatSidebar: { editActiveConversation?: () => void } | undefined = $state(); let showBuildVersion = $derived( settingsStore.config[SETTINGS_KEYS.SHOW_BUILD_VERSION] as boolean @@ -308,15 +302,7 @@
    - { - if (deviceStore.isMobile) { - goto(ROUTES.SEARCH); - } else if (chatSidebar?.activateSearchMode) { - chatSidebar.activateSearchMode(); - } - }} - /> +