This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-11 17:55:44 -05:00
1 parent 751c871418
commit f0c9751879
14 files changed
+133 -31

No files matched your search

+3 -2
View File
@@ -50,15 +50,16 @@ export type FileMatch = {
name_match: boolean;
content_matches: ContentMatch[];
};
export type FileMatches = { results: FileMatch[]; truncated: boolean };
export type FileMatches = { results: FileMatch[]; next_offset: number | null };
export const getFileMatches = (
query: string,
path: string,
showHidden: boolean,
offset = 0,
signal?: AbortSignal
) =>
fetchJSON<FileMatches>(
`/api/workspace/files/matches?query=${encodeURIComponent(query)}&path=${encodeURIComponent(path)}&show_hidden=${showHidden}`,
`/api/workspace/files/matches?query=${encodeURIComponent(query)}&path=${encodeURIComponent(path)}&show_hidden=${showHidden}&offset=${offset}`,
{ signal }
);
@@ -2,6 +2,7 @@
// Module-level cache: survives component destroy/create cycles
const _treeExpandedCache = new Map();
const _treeContentsCache = new Map();
const _searchQueryCache = new Map();
</script>
<script lang="ts">
@@ -49,8 +50,10 @@
let searchQuery = $state('');
let matchResults = $state<FileMatch[] | null>(null);
let matchLoading = $state(false);
let matchLoadingMore = $state(false);
let matchError = $state<string | null>(null);
let matchesTruncated = $state(false);
let matchLoadMoreError = $state(false);
let nextMatchOffset = $state<number | null>(null);
let matchTimer: ReturnType<typeof setTimeout> | null = null;
let matchController: AbortController | null = null;
let matchRequestId = 0;
@@ -295,15 +298,18 @@
$effect(() => {
if (cwd) {
if (cwd !== _prevCwd) {
const isNavigation = _prevCwd !== '';
const previousCwd = _prevCwd;
const isNavigation = previousCwd !== '';
_prevCwd = cwd;
if (isNavigation) {
_searchQueryCache.delete(previousCwd);
searchQuery = '';
// Navigated to a new directory: reset tree state
expandedDirs = new Set();
dirContents = new Map();
initialLoad = true;
} else {
searchQuery = _searchQueryCache.get(cwd) ?? '';
// Component (re)mount: restore tree state from cache
const cachedExpanded = _treeExpandedCache.get(cwd);
if (cachedExpanded) {
@@ -329,7 +335,9 @@
if (!query) {
matchResults = null;
matchLoading = false;
matchesTruncated = false;
matchLoadingMore = false;
matchLoadMoreError = false;
nextMatchOffset = null;
return;
}
@@ -340,14 +348,17 @@
addMenuOpen = false;
sortMenuOpen = false;
matchLoading = true;
matchLoadingMore = false;
matchLoadMoreError = false;
nextMatchOffset = null;
matchTimer = setTimeout(async () => {
const controller = new AbortController();
matchController = controller;
try {
const data = await getFileMatches(query, cwd, hidden, controller.signal);
const data = await getFileMatches(query, cwd, hidden, 0, controller.signal);
if (requestId === matchRequestId) {
matchResults = data.results;
matchesTruncated = data.truncated;
nextMatchOffset = data.next_offset;
}
} catch (e: any) {
if (e.name !== 'AbortError' && requestId === matchRequestId) {
@@ -360,6 +371,48 @@
}, 200);
});
async function loadMoreMatches() {
const offset = nextMatchOffset;
if (offset === null || !isSearching || matchLoading || matchLoadingMore || matchLoadMoreError)
return;
const query = searchText;
const hidden = showHidden;
const requestId = matchRequestId;
matchLoadingMore = true;
const controller = new AbortController();
matchController = controller;
try {
const data = await getFileMatches(query, cwd, hidden, offset, controller.signal);
if (requestId === matchRequestId) {
matchResults = [...(matchResults ?? []), ...data.results];
nextMatchOffset = data.next_offset;
}
} catch (e: any) {
if (e.name !== 'AbortError' && requestId === matchRequestId) {
matchLoadMoreError = true;
}
} finally {
if (requestId === matchRequestId) matchLoadingMore = false;
}
}
function retryMoreMatches() {
matchLoadMoreError = false;
void loadMoreMatches();
}
function loadMoreOnVisible(node: HTMLElement) {
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) void loadMoreMatches();
},
{ rootMargin: '160px' }
);
observer.observe(node);
return { destroy: () => observer.disconnect() };
}
// Keep the websocket watch path in sync (separate effect so it doesn't
// re-trigger directory fetches via fsTick feedback loops)
$effect(() => {
@@ -524,6 +577,7 @@
}
function navigateTo(path: string) {
_searchQueryCache.delete(cwd);
searchQuery = '';
setFileBrowserCwd(path);
}
@@ -1140,9 +1194,16 @@
class="flex-1 border-none outline-none bg-transparent text-xs text-gray-900 dark:text-white placeholder:text-gray-400"
placeholder={$t('files.searchFilesAndContents')}
bind:value={searchQuery}
oninput={(event) => _searchQueryCache.set(cwd, event.currentTarget.value)}
/>
{#if searchQuery}
<button class="text-gray-400 flex items-center" onclick={() => (searchQuery = '')}>
<button
class="text-gray-400 flex items-center"
onclick={() => {
searchQuery = '';
_searchQueryCache.set(cwd, '');
}}
>
<Icon name="xmark" size={11} />
</button>
{/if}
@@ -1281,10 +1342,17 @@
</div>
{@render resultRows(contentOnlyMatches)}
{/if}
{#if matchesTruncated}
<p class="px-2 py-2 text-center text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$t('files.searchTruncated')}
</p>
{#if nextMatchOffset !== null}
<div use:loadMoreOnVisible class="flex h-8 items-center justify-center">
{#if matchLoadingMore}
<Spinner size={12} />
{:else if matchLoadMoreError}
<button
class="text-[0.6875rem] text-gray-400 hover:text-gray-600 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-75"
onclick={retryMoreMatches}>{$t('files.retry')}</button
>
{/if}
</div>
{/if}
{/if}
{:else if visibleEntries.length === 0 && !showNewInput}
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "Dein Computer, von überall.",
"home.greetingBeforeName": "Schön, dich zu sehen, ",
"home.greeting.morningBeforeName": "Morgen, ",
"home.greeting.afternoonBeforeName": "Noch dabei, ",
"home.greeting.eveningBeforeName": "Noch eine Sache, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Erstelle ein Konto, um loszulegen.",
"auth.signInSystemHint": "Melde dich mit deinem Systemkonto an.",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "Your computer, from anywhere.",
"home.greetingBeforeName": "Good to see you, ",
"home.greeting.morningBeforeName": "Morning, ",
"home.greeting.afternoonBeforeName": "Still at it, ",
"home.greeting.eveningBeforeName": "One more thing, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Create your account to get started.",
"auth.signInSystemHint": "Sign in with your system account.",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "Tu computadora, desde cualquier lugar.",
"home.greetingBeforeName": "Qué gusto verte, ",
"home.greeting.morningBeforeName": "Buenos días, ",
"home.greeting.afternoonBeforeName": "Sigues con ello, ",
"home.greeting.eveningBeforeName": "Una cosa más, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Crea tu cuenta para comenzar.",
"auth.signInSystemHint": "Inicia sesión con tu cuenta del sistema.",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "Votre ordinateur, où que vous soyez.",
"home.greetingBeforeName": "Ravi de vous voir, ",
"home.greeting.morningBeforeName": "Bonjour, ",
"home.greeting.afternoonBeforeName": "Toujours à l’œuvre, ",
"home.greeting.eveningBeforeName": "Encore une chose, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Créez votre compte pour commencer.",
"auth.signInSystemHint": "Connectez-vous avec votre compte système.",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "どこからでも、あなたのコンピュータへ。",
"home.greetingBeforeName": "会えてうれしいです、",
"home.greeting.morningBeforeName": "おはよう、",
"home.greeting.afternoonBeforeName": "まだやってるね、",
"home.greeting.eveningBeforeName": "もう一つだけ、",
"home.greetingAfterName": "さん。",
"auth.createAccountHint": "アカウントを作成して始めましょう。",
"auth.signInSystemHint": "システムアカウントでサインインしてください。",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "어디서든, 당신의 컴퓨터로.",
"home.greetingBeforeName": "다시 만나서 반가워요, ",
"home.greeting.morningBeforeName": "좋은 아침이에요, ",
"home.greeting.afternoonBeforeName": "계속하고 있네요, ",
"home.greeting.eveningBeforeName": "한 가지만 더, ",
"home.greetingAfterName": "님.",
"auth.createAccountHint": "계정을 만들어 시작하세요.",
"auth.signInSystemHint": "시스템 계정으로 로그인하세요.",
@@ -1,6 +1,8 @@
{
"app.tagline": "Seu computador, de qualquer lugar.",
"home.greetingBeforeName": "Que bom ver você, ",
"home.greeting.morningBeforeName": "Bom dia, ",
"home.greeting.afternoonBeforeName": "Ainda nessa, ",
"home.greeting.eveningBeforeName": "Só mais uma coisa, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Crie sua conta para começar.",
"auth.signInSystemHint": "Faça login com sua conta do sistema.",
+3 -1
View File
@@ -1,6 +1,8 @@
{
"app.tagline": "Ваш компьютер, откуда угодно.",
"home.greetingBeforeName": "Рад вас видеть, ",
"home.greeting.morningBeforeName": "Доброе утро, ",
"home.greeting.afternoonBeforeName": "Всё ещё в деле, ",
"home.greeting.eveningBeforeName": "Ещё одна вещь, ",
"home.greetingAfterName": ".",
"auth.createAccountHint": "Создайте аккаунт, чтобы начать.",
"auth.signInSystemHint": "Войдите с помощью системной учётной записи.",
@@ -1,6 +1,8 @@
{
"app.tagline": "随时随地,掌控你的电脑。",
"home.greetingBeforeName": "很高兴见到你,",
"home.greeting.morningBeforeName": "早上好,",
"home.greeting.afternoonBeforeName": "还在忙,",
"home.greeting.eveningBeforeName": "还有一件事,",
"home.greetingAfterName": "。",
"auth.createAccountHint": "创建账户以开始使用。",
"auth.signInSystemHint": "使用系统账户登录。",
@@ -1,6 +1,8 @@
{
"app.tagline": "隨時隨地,掌控你的電腦。",
"home.greetingBeforeName": "很高興見到你,",
"home.greeting.morningBeforeName": "早安,",
"home.greeting.afternoonBeforeName": "還在忙,",
"home.greeting.eveningBeforeName": "還有一件事,",
"home.greetingAfterName": "。",
"auth.createAccountHint": "建立帳號以開始使用。",
"auth.signInSystemHint": "使用系統帳號登入。",
+4 -1
View File
@@ -51,6 +51,9 @@
let folderPickerIntent = $state<LaunchIntent | null>(null);
let folderPickerWorkspace = $state<string | null>(null);
const welcomeName = $derived($session?.display_name || $session?.username);
const greetingTime = $derived(
new Date().getHours() < 12 ? 'morning' : new Date().getHours() < 18 ? 'afternoon' : 'evening'
);
const activeHomeTab = $derived(
$homeGroup.tabs.find((tab) => tab.id === $homeGroup.activeTabId) ?? $homeGroup.tabs[0]
);
@@ -913,7 +916,7 @@
<div class="flex items-baseline gap-2">
<h1 class="text-lg font-medium tracking-tight text-gray-900 dark:text-white">
{#if welcomeName}
{$t('home.greetingBeforeName')}<span class="capitalize">{welcomeName}</span>{$t('home.greetingAfterName')}
{$t(`home.greeting.${greetingTime}BeforeName`)}<span class="capitalize">{welcomeName}</span>{$t('home.greetingAfterName')}
{:else}
Computer
{/if}
+18 -8
View File
@@ -326,7 +326,7 @@ SEARCH_IGNORE_DIRS = {
".DS_Store",
}
MAX_MATCH_RESULTS = 100
MATCH_PAGE_SIZE = 100
MAX_CONTENT_MATCHES_PER_FILE = 3
MAX_CONTENT_SEARCH_FILE_SIZE = 1 * 1024 * 1024
@@ -348,7 +348,7 @@ class FileMatch(BaseModel):
class FileMatches(BaseModel):
results: list[FileMatch]
truncated: bool
next_offset: int | None = None
def _is_search_ignored(name: str) -> bool:
@@ -475,14 +475,20 @@ def _content_matches_with_python(
return matches, truncated
def find_file_matches(root: Path, query: str, show_hidden: bool = False) -> FileMatches:
def find_file_matches(
root: Path,
query: str,
show_hidden: bool = False,
offset: int = 0,
limit: int = MATCH_PAGE_SIZE,
) -> FileMatches:
"""Find filename/path and literal text matches below a browser directory."""
query = query.strip()
query_lower = query.lower()
entries = list(_walk_match_entries(root, show_hidden))
files = {path.resolve() for path, kind in entries if kind == "file" and not path.is_symlink()}
content_result = _content_matches_with_rg(root, query, query_lower, show_hidden, files)
content_matches, truncated = (
content_matches, _ = (
content_result if content_result is not None else _content_matches_with_python(files, query_lower)
)
@@ -522,9 +528,11 @@ def find_file_matches(root: Path, query: str, show_hidden: bool = False) -> File
)
matches.sort(key=lambda item: (item[0], item[1], item[2].relative_path.lower()))
if len(matches) > MAX_MATCH_RESULTS:
truncated = True
return FileMatches(results=[item[2] for item in matches[:MAX_MATCH_RESULTS]], truncated=truncated)
next_offset = offset + limit if offset + limit < len(matches) else None
return FileMatches(
results=[item[2] for item in matches[offset : offset + limit]],
next_offset=next_offset,
)
@router.get("/matches", response_model=FileMatches)
@@ -532,6 +540,8 @@ async def file_matches(
query: str = Query(..., description="Literal text to match"),
path: str = Query(..., description="Root path to search"),
show_hidden: bool = Query(False, description="Include dotfiles and dot-directories"),
offset: int = Query(0, ge=0, description="Result offset"),
limit: int = Query(MATCH_PAGE_SIZE, ge=1, le=MATCH_PAGE_SIZE, description="Page size"),
):
"""Return filename/path and content matches below a directory."""
if not query.strip():
@@ -541,7 +551,7 @@ async def file_matches(
if not root.exists() or not root.is_dir():
raise HTTPException(status_code=404, detail=f"Path not found: {path}")
return await asyncio.to_thread(find_file_matches, root, query, show_hidden)
return await asyncio.to_thread(find_file_matches, root, query, show_hidden, offset, limit)
class SearchResult(BaseModel):