Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions cardinal/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2051,3 +2051,116 @@ button:active:not(:disabled) {
overflow-x: auto;
overflow-y: hidden;
}

.search-history {
position: relative;
display: inline-flex;
align-items: center;
}

.search-history-toggle {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 1.8rem;
width: 1.8rem;
height: 1.8rem;
padding: 0;
border: none;
border-radius: 0.55rem;
background: transparent;
box-shadow: none;
color: var(--color-muted);
cursor: pointer;
user-select: none;
}

.search-history-toggle:hover {
background-color: var(--search-toggle-hover-bg);
}

.search-history-toggle[aria-expanded='true'] {
color: var(--color-accent);
background-color: rgba(var(--color-accent-rgb), 0.08);
}

.search-history-toggle svg {
display: block;
width: 1rem;
height: 1rem;
}

.search-history-panel {
position: absolute;
top: calc(100% + 0.45rem);
right: 0;
z-index: 40;
display: flex;
flex-direction: column;
width: min(24rem, 72vw);
max-height: 19rem;
padding: 0.3rem;
border-radius: 12px;
border: 1px solid rgba(var(--color-accent-rgb), 0.14);
background-color: var(--color-elevated-bg);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
box-sizing: border-box;
}

.search-history-list {
display: flex;
flex-direction: column;
overflow-y: auto;
min-height: 0;
}

.search-history-item {
display: block;
width: 100%;
padding: 0.4rem 0.55rem;
border: none;
border-radius: 8px;
background: transparent;
box-shadow: none;
color: var(--color-text);
font-size: 0.85rem;
font-family: var(--font-sans);
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}

.search-history-item:hover {
background-color: rgba(var(--color-accent-rgb), 0.08);
}

.search-history-empty {
padding: 0.55rem;
color: var(--color-muted);
font-size: 0.85rem;
text-align: center;
}

.search-history-clear {
display: block;
width: 100%;
margin-top: 0.2rem;
padding: 0.4rem 0.55rem;
border: none;
border-top: 1px solid rgba(var(--color-accent-rgb), 0.12);
border-radius: 0 0 8px 8px;
background: transparent;
box-shadow: none;
color: var(--color-muted);
font-size: 0.8rem;
font-family: var(--font-sans);
text-align: center;
cursor: pointer;
}

.search-history-clear:hover {
color: var(--color-accent);
background-color: rgba(var(--color-accent-rgb), 0.06);
}
38 changes: 36 additions & 2 deletions cardinal/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useCallback, useEffect, useMemo } from 'react';
import { useRef, useCallback, useEffect, useMemo, useState } from 'react';
import type { ChangeEvent, CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
import './App.css';
import { FileRow } from './components/FileRow';
Expand All @@ -23,13 +23,14 @@ import type { FSEventsPanelHandle } from './components/FSEventsPanel';
import { useTranslation } from 'react-i18next';
import { useFullDiskAccessPermission } from './hooks/useFullDiskAccessPermission';
import type { DisplayState } from './components/StateDisplay';
import { openResultPath } from './utils/openResultPath';
import { openResultPath, subscribeResultOpened } from './utils/openResultPath';
import { useStableEvent } from './hooks/useStableEvent';
import { useAppHotkeys } from './hooks/useAppHotkeys';
import { useAppPreferences } from './hooks/useAppPreferences';
import { useAppWindowListeners } from './hooks/useAppWindowListeners';
import { useFilesTabEffects } from './hooks/useFilesTabEffects';
import { useFilesTabState } from './hooks/useFilesTabState';
import { useRecentSearches } from './hooks/useRecentSearches';

function App() {
const {
Expand Down Expand Up @@ -106,6 +107,9 @@ function App() {
searchInputRef.current?.blur();
}, [displayedResults.length, selectSingleRow]);

const { recentSearches, recordSearch, clearRecentSearches } = useRecentSearches();
const [historyOpen, setHistoryOpen] = useState(false);

const {
activeTab,
isSearchFocused,
Expand All @@ -127,7 +131,28 @@ function App() {
queueSearch,
queueDirectorySearch,
onNavigateFromSearchToResults: navigateFromSearchToResults,
onQueryCommitted: recordSearch,
});

// Record the active query whenever a result is opened — a search that led to an
// open is a successful search worth keeping in history.
const recordOpenedSearch = useStableEvent(() => {
recordSearch(searchParams.query);
});
useEffect(() => subscribeResultOpened(recordOpenedSearch), [recordOpenedSearch]);

const toggleHistory = useCallback(() => {
setHistoryOpen((open) => !open);
}, []);

const selectHistoryEntry = useCallback(
(query: string) => {
setHistoryOpen(false);
submitFilesQuery(query, { immediate: true });
searchInputRef.current?.focus();
},
[submitFilesQuery],
);
const { filteredEvents } = useRecentFSEvents({
caseSensitive,
isActive: activeTab === 'events',
Expand Down Expand Up @@ -392,6 +417,15 @@ function App() {
caseSensitiveLabel={caseSensitiveLabel}
onFocus={handleSearchFocus}
onBlur={handleSearchBlur}
historyEnabled={activeTab === 'files'}
historyEntries={recentSearches}
historyOpen={historyOpen}
onToggleHistory={toggleHistory}
onSelectHistoryEntry={selectHistoryEntry}
onClearHistory={clearRecentSearches}
historyLabel={t('search.history.toggle')}
historyEmptyLabel={t('search.history.empty')}
historyClearLabel={t('search.history.clear')}
/>
<div className={resultsContainerClassName} style={containerStyle}>
{activeTab === 'events' ? (
Expand Down
110 changes: 110 additions & 0 deletions cardinal/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import React, { useCallback, useEffect, useRef } from 'react';
import type { ChangeEvent, FocusEventHandler } from 'react';
import { hasModifierKey } from '../utils/keyboard';

const HISTORY_ICON = (
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<path
d="M8 2.5a5.5 5.5 0 1 1-5.35 6.8"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
/>
<path d="M2.2 5.4V9l3.4-.9z" fill="currentColor" stroke="none" />
<path
d="M8 5.2V8l2.2 1.4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);

const MACOS_FOLDER_ICON =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGg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6Gf4M3wH7WAEHYL6M8jUOtIQvCfhfwg+aE5B+lBx09YnlGKQAAAABJRU5ErkJggg==';

Expand All @@ -25,6 +46,15 @@ type SearchBarProps = {
caseSensitiveLabel: string;
onFocus: FocusEventHandler<HTMLInputElement>;
onBlur: FocusEventHandler<HTMLInputElement>;
historyEnabled?: boolean;
historyEntries?: string[];
historyOpen?: boolean;
onToggleHistory?: () => void;
onSelectHistoryEntry?: (query: string) => void;
onClearHistory?: () => void;
historyLabel?: string;
historyEmptyLabel?: string;
historyClearLabel?: string;
};

const isCollapsedAtStart = (input: HTMLInputElement): boolean =>
Expand Down Expand Up @@ -55,15 +85,50 @@ export function SearchBar({
caseSensitiveLabel,
onFocus,
onBlur,
historyEnabled = false,
historyEntries = [],
historyOpen = false,
onToggleHistory,
onSelectHistoryEntry,
onClearHistory,
historyLabel = 'Search history',
historyEmptyLabel = 'No search history yet',
historyClearLabel = 'Clear history',
}: SearchBarProps): React.JSX.Element {
const directoryInputRef = useRef<HTMLInputElement | null>(null);
const historyContainerRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (directoryScopeOpen) {
directoryInputRef.current?.focus();
}
}, [directoryScopeOpen]);

useEffect(() => {
if (!historyOpen) {
return;
}

const handlePointerDown = (event: MouseEvent) => {
const container = historyContainerRef.current;
if (container && event.target instanceof Node && !container.contains(event.target)) {
onToggleHistory?.();
}
};
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
onToggleHistory?.();
}
};

document.addEventListener('mousedown', handlePointerDown);
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('mousedown', handlePointerDown);
document.removeEventListener('keydown', handleKeyDown);
};
}, [historyOpen, onToggleHistory]);

const handleQueryKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLInputElement>) => {
if (
Expand Down Expand Up @@ -176,6 +241,51 @@ export function SearchBar({
/>
</div>
<div className="search-segment search-options">
{historyEnabled ? (
<div className="search-history" ref={historyContainerRef}>
<button
type="button"
className="search-history-toggle"
aria-label={historyLabel}
aria-haspopup="true"
aria-expanded={historyOpen}
title={historyLabel}
onClick={onToggleHistory}
>
{HISTORY_ICON}
</button>
{historyOpen ? (
<div className="search-history-panel" aria-label={historyLabel}>
{historyEntries.length === 0 ? (
<div className="search-history-empty">{historyEmptyLabel}</div>
) : (
<>
<div className="search-history-list">
{historyEntries.map((entry) => (
<button
type="button"
key={entry}
className="search-history-item"
title={entry}
onClick={() => onSelectHistoryEntry?.(entry)}
>
{entry}
</button>
))}
</div>
<button
type="button"
className="search-history-clear"
onClick={onClearHistory}
>
{historyClearLabel}
</button>
</>
)}
</div>
) : null}
</div>
) : null}
<label className="search-option" title={caseSensitiveLabel}>
<input
type="checkbox"
Expand Down
Loading
Loading