dsh-remote-vs 0.11.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/archive.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Remote directory archiving for the download route.
3
+ *
4
+ * The archive is produced ON the remote host (`tar -czf -`) and streamed
5
+ * straight into the HTTP response, so the Host never builds it in memory or
6
+ * writes it to its own disk. Pure string builders (no fs, no exec) so the
7
+ * download gate can pin the exact command shape.
8
+ */
9
+
10
+ import { posix } from 'node:path'
11
+ import { shQuote } from './git-format.ts'
12
+ import { MAX_SELECTION_DOWNLOAD } from './protocol.ts'
13
+
14
+ /** Download file name for one archived directory. */
15
+ export function directoryArchiveName(dir: string): string {
16
+ const trimmed = String(dir).replace(/[\\/]+$/, '')
17
+ const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'))
18
+ const base = at < 0 ? trimmed : trimmed.slice(at + 1)
19
+ return `${base === '' ? 'root' : base}.tar.gz`
20
+ }
21
+
22
+ /**
23
+ * One POSIX shell command that writes the directory's gzip tar to stdout.
24
+ *
25
+ * The member name is prefixed with `./` so a directory whose name starts with
26
+ * `-` cannot be read as a tar option; `-C` names the parent instead of relying
27
+ * on a shell `cd`, and both paths are single-quoted (`shQuote`) so spaces,
28
+ * quotes and `$()` in a real path cannot escape into the command.
29
+ */
30
+ export function directoryArchiveCommand(dir: string): string {
31
+ const path = String(dir).replace(/\\/g, '/').replace(/\/+$/, '')
32
+ if (path === '' || path === '/') throw new Error('refusing to archive the remote root')
33
+ if (!path.startsWith('/')) throw new Error('remote path must be absolute')
34
+ const parent = posix.dirname(path)
35
+ const name = posix.basename(path)
36
+ return `tar -czf - -C ${shQuote(parent)} ${shQuote(`./${name}`)}`
37
+ }
38
+
39
+ /**
40
+ * One POSIX shell command archiving several selected paths to stdout.
41
+ *
42
+ * GNU tar accepts one `-C` before each member, so every entry is stored as its
43
+ * own bare `./name` while keeping its real parent on the remote side; that is
44
+ * what lets a selection span several directories (mixed files and directories
45
+ * are fine — tar recurses into directories). Two entries with the same basename
46
+ * from different directories collide inside the archive by design: the
47
+ * alternative would be a synthetic directory tree the remote never had.
48
+ */
49
+ export function selectionArchiveCommand(paths: readonly string[]): string {
50
+ if (paths.length === 0) throw new Error('refusing to archive an empty selection')
51
+ if (paths.length > MAX_SELECTION_DOWNLOAD) throw new Error(`too many entries: ${paths.length} (max ${MAX_SELECTION_DOWNLOAD})`)
52
+ let command = 'tar -czf -'
53
+ for (const raw of paths) {
54
+ const path = String(raw).replace(/\\/g, '/').replace(/\/+$/, '')
55
+ if (path === '' || path === '/') throw new Error('refusing to archive the remote root')
56
+ if (!path.startsWith('/')) throw new Error('remote path must be absolute')
57
+ command += ` -C ${shQuote(posix.dirname(path))} ${shQuote(`./${posix.basename(path)}`)}`
58
+ }
59
+ return command
60
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Download progress dock.
3
+ *
4
+ * Rendered through a PORTAL on `document.body`: the dock starts inside the
5
+ * sidebar's keep-alive slot, and a `position: fixed` descendant of a hidden
6
+ * ancestor disappears with it — which would take the progress bar (and the
7
+ * cancel button) of a running download along when the user switches rail views.
8
+ *
9
+ * The runner lives in `downloads.ts`, outside React, so an unmount of this
10
+ * component never interrupts a transfer; the dock only reads its snapshot.
11
+ */
12
+
13
+ import { useSyncExternalStore, type ReactNode } from 'react'
14
+ import { createPortal } from 'react-dom'
15
+ import { cancelDownload, dismissDownload, downloadsStore, formatByteCount, type DownloadTask } from './downloads.ts'
16
+ import { FileIcon, FolderIcon, IconButton, IconClose, IconStop } from './vsc/kit.tsx'
17
+
18
+ const STATUS_KEY: Record<DownloadTask['status'], string> = {
19
+ running: 'downloads.running',
20
+ done: 'downloads.done',
21
+ failed: 'downloads.failed',
22
+ cancelled: 'downloads.cancelled',
23
+ }
24
+
25
+ /** One line of detail under the bar (bytes, fallback note, or the failure). */
26
+ function detailText(task: DownloadTask, t: (key: string) => string): string {
27
+ if (task.status === 'failed') return task.error ?? t('downloads.failed')
28
+ if (task.status === 'cancelled') return t('downloads.cancelled')
29
+ if (task.status === 'done') {
30
+ return task.via === 'browserDefault' ? t('downloads.browserDefault') : t('downloads.done')
31
+ }
32
+ const loaded = formatByteCount(task.loaded)
33
+ const archive = task.directory || task.selection !== undefined
34
+ if (task.total !== undefined && task.total > 0) return `${loaded} / ${formatByteCount(task.total)}`
35
+ // An archive has no length by design (chunked tar). A plain FILE with no
36
+ // known total means a shell/proxy stripped content-length (DSH Desktop does)
37
+ // — saying "packaging…" there wrongly suggests we re-archive the file.
38
+ return `${loaded} · ${t(archive ? 'downloads.indeterminate' : 'downloads.sizeUnknown')}`
39
+ }
40
+
41
+ /** Percent for the bar, or `undefined` while the size is unknown (archives). */
42
+ function percentOf(task: DownloadTask): number | undefined {
43
+ if (task.total === undefined || task.total <= 0) return undefined
44
+ return Math.min(100, Math.round((task.loaded / task.total) * 100))
45
+ }
46
+
47
+ function DownloadRow(props: { task: DownloadTask; t: (key: string) => string }): ReactNode {
48
+ const { task, t } = props
49
+ const percent = percentOf(task)
50
+ return (
51
+ <div className={`rvs-download ${task.status}`}>
52
+ <div className="rvs-download-head">
53
+ <span className="rvs-download-icon">
54
+ {task.directory ? <FolderIcon path={task.name} open={false} size={14} /> : <FileIcon path={task.name} size={14} />}
55
+ </span>
56
+ <span className="rvs-download-name" title={task.name}>{task.name}{task.directory ? '.tar.gz' : ''}</span>
57
+ <span className={`rvs-download-status ${task.status}`}>{t(STATUS_KEY[task.status])}</span>
58
+ {task.status === 'running'
59
+ ? (
60
+ <IconButton title={t('downloads.cancel')} onClick={() => cancelDownload(task.id)}>
61
+ <IconStop size={12} />
62
+ </IconButton>
63
+ )
64
+ : (
65
+ <IconButton title={t('downloads.close')} onClick={() => dismissDownload(task.id)}>
66
+ <IconClose size={12} />
67
+ </IconButton>
68
+ )}
69
+ </div>
70
+ {task.status === 'running' && (
71
+ <div className="rvs-download-bar" aria-hidden="true">
72
+ <div
73
+ className={`rvs-download-fill${percent === undefined ? ' indeterminate' : ''}`}
74
+ style={percent === undefined ? undefined : { width: `${percent}%` }}
75
+ />
76
+ </div>
77
+ )}
78
+ <div className={`rvs-download-meta ${task.status}`} title={task.error}>{detailText(task, t)}</div>
79
+ </div>
80
+ )
81
+ }
82
+
83
+ export function DownloadDock(props: { t: (key: string) => string }): ReactNode {
84
+ const tasks = useSyncExternalStore(downloadsStore.subscribe, downloadsStore.getSnapshot, downloadsStore.getSnapshot)
85
+ if (typeof document === 'undefined') return null
86
+ if (tasks.length === 0) return null
87
+ return createPortal(
88
+ <div className="rvs-downloads" role="status" aria-live="polite">
89
+ {tasks.map(task => <DownloadRow key={task.id} task={task} t={props.t} />)}
90
+ </div>,
91
+ document.body,
92
+ )
93
+ }
@@ -12,9 +12,11 @@
12
12
  */
13
13
  import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
14
14
  import { copyIntoCommand, joinAbs, moveToCommand } from '../fs-ops.ts'
15
- import type { RemoteFileEntry } from '../protocol.ts'
15
+ import { MAX_SELECTION_DOWNLOAD, type RemoteFileEntry } from '../protocol.ts'
16
16
  import { api, uploadFile } from './api.ts'
17
+ import { startDownload, startSelectionDownload } from './downloads.ts'
17
18
  import { insertRemoteReference, sameLocalDir } from './composer.ts'
19
+ import { ListingRequests } from './listing-requests.ts'
18
20
  import { repoRelative, useExplorer } from './store.tsx'
19
21
  import { planUpload, withDroppedDirs, type DroppedFile } from './upload-plan.ts'
20
22
  import { collectDroppedFiles, type EntryLike } from './upload-source.ts'
@@ -146,6 +148,13 @@ function formatUploadLabel(
146
148
  /** How many directory listings stay cached; each one is a whole directory. */
147
149
  const LISTING_CACHE_KEEP = 50
148
150
 
151
+ /**
152
+ * Hover intent before a directory's listing is prefetched: long enough that
153
+ * sweeping the pointer across the tree does not fire a request per row, short
154
+ * enough that arriving at a folder and clicking it finds the listing warm.
155
+ */
156
+ const PREFETCH_HOVER_MS = 150
157
+
149
158
  /**
150
159
  * Insert one listing as the newest, so "the first key is the oldest" stays
151
160
  * true and `trimListings` can evict from the front.
@@ -195,6 +204,16 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
195
204
  const { t, alias, root, repoRoot, marks } = store
196
205
  const ctx = store.ctx
197
206
  const [listings, setListings] = useState<Record<string, RemoteFileEntry[]>>({})
207
+ /**
208
+ * The same listings, readable synchronously. `prefetchDir` has to answer "is
209
+ * this already cached?" at pointer time, and a state value would be one render
210
+ * behind (asking again for a directory that was just listed).
211
+ */
212
+ const listingsRef = useRef<Record<string, RemoteFileEntry[]>>({})
213
+ /** Set false on unmount so a listing that lands late does not touch state. */
214
+ const alive = useRef(true)
215
+ /** Hover-intent timer for prefetch; one pointer means one candidate. */
216
+ const prefetchTimer = useRef<number | undefined>(undefined)
198
217
  const [loading, setLoading] = useState<Set<string>>(new Set())
199
218
  const [expanded, setExpanded] = useState<Set<string>>(new Set())
200
219
  const [selected, setSelected] = useState<Set<string>>(new Set())
@@ -237,23 +256,56 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
237
256
  && viewedAliasPath !== undefined
238
257
  && sameLocalDir(chatTarget.sessionWorkspacePath, viewedAliasPath)
239
258
 
259
+ /**
260
+ * The revision this component's listing traffic is labelled with.
261
+ *
262
+ * A ref, not a hook dependency: a revision bump must not re-create `loadDir`
263
+ * (the reveal/refresh effects list it, and their identity churn would re-run
264
+ * both). Only the request-time check in `ListingRequests` reads it. It is
265
+ * written during render on purpose (an idempotent latest-value ref): an
266
+ * effect-synced ref is one commit stale, so a read triggered from the same
267
+ * commit as the write could still be labelled with the previous revision.
268
+ */
269
+ const revisionRef = useRef(store.revision)
270
+ revisionRef.current = store.revision
271
+ /** Current binding, for the late-answer guard below (the memo is per alias). */
272
+ const aliasRef = useRef(alias)
273
+
274
+ /**
275
+ * The in-flight listing reads (see `ListingRequests`).
276
+ *
277
+ * A hover prefetch and the click that follows it are the same request, and so
278
+ * are a double click and the reveal chain's level: without the shared map each
279
+ * one opened its own SFTP listing for the same path. A request is only shared
280
+ * when it started at the same revision, so a read AFTER a write never gets an
281
+ * answer issued before it.
282
+ */
283
+ const listingsApi = useMemo(() => new ListingRequests(
284
+ dir => dirKey(alias, dir),
285
+ dir => api.fileOp.list(alias, dir),
286
+ (key, entries) => {
287
+ // A late answer must not paint after unmount, nor write the PREVIOUS
288
+ // workspace's cache key after a binding change.
289
+ if (alive.current && aliasRef.current === alias) setListings(prev => withListing(prev, key, entries))
290
+ },
291
+ ), [alias])
292
+
240
293
  const loadDir = useCallback(async (dir: string, force = false): Promise<void> => {
241
294
  if (alias === '') return
242
295
  const key = dirKey(alias, dir)
243
- // NOTE: a cached listing is deliberately NOT reused here. The old form was
244
- // `setListings(prev => prev[key] === undefined ? prev : prev)`, an identity
245
- // update that changed nothing and read like a cache short-circuit; every
246
- // caller therefore re-lists, which is what the tree relies on after a
247
- // write. (The `force` flag only distinguishes caller intent.)
248
- void force
296
+ // NOTE: a cached listing is deliberately NOT reused as the only source. The
297
+ // tree relies on every caller re-listing after a write (`force` = start a
298
+ // fresh request instead of joining one that may predate the write); a
299
+ // PREFETCHED listing is still on screen while the revalidation runs, which
300
+ // is what makes the open feel instant without serving stale content as
301
+ // final.
249
302
  setLoading(prev => {
250
303
  const next = new Set(prev)
251
304
  next.add(key)
252
305
  return next
253
306
  })
254
307
  try {
255
- const entries = await api.fileOp.list(alias, dir)
256
- setListings(prev => withListing(prev, key, entries))
308
+ await listingsApi.request(dir, revisionRef.current, force)
257
309
  } catch (error) {
258
310
  toast(error instanceof Error ? error.message : String(error), true)
259
311
  } finally {
@@ -263,7 +315,37 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
263
315
  return next
264
316
  })
265
317
  }
266
- }, [alias])
318
+ }, [alias, listingsApi])
319
+
320
+ /**
321
+ * Warm the listing cache for a directory the pointer is resting on.
322
+ *
323
+ * The open itself still revalidates through `loadDir` (the explorer must show
324
+ * writes made elsewhere), but with the rows already in memory the expand
325
+ * paints immediately instead of showing a loading line for one round trip.
326
+ * Speculative by nature, so a failure is not a toast — the real listing, when
327
+ * the user opens it, still explains itself.
328
+ */
329
+ const prefetchDir = useCallback((dir: string): void => {
330
+ if (alias === '') return
331
+ const key = dirKey(alias, dir)
332
+ if (listingsRef.current[key] !== undefined) return
333
+ if (listingsApi.busy(dir)) return
334
+ listingsApi.request(dir, revisionRef.current).catch(() => undefined)
335
+ }, [alias, listingsApi])
336
+
337
+ /** Hover intent: prefetch the row under the pointer after a short rest. */
338
+ const hoverDir = (path: string | undefined): void => {
339
+ if (prefetchTimer.current !== undefined) {
340
+ window.clearTimeout(prefetchTimer.current)
341
+ prefetchTimer.current = undefined
342
+ }
343
+ if (path === undefined) return
344
+ prefetchTimer.current = window.setTimeout(() => {
345
+ prefetchTimer.current = undefined
346
+ prefetchDir(path)
347
+ }, PREFETCH_HOVER_MS)
348
+ }
267
349
 
268
350
  /**
269
351
  * "Show this folder in the tree" — raised by a search result's menu.
@@ -312,6 +394,10 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
312
394
 
313
395
  // Root listing + refresh on the shared revision bump (git writes, saves...).
314
396
  const revision = store.revision
397
+ /** Keep the late-answer guard current for the NEXT commit's callbacks. */
398
+ useEffect(() => {
399
+ aliasRef.current = alias
400
+ }, [alias])
315
401
  /**
316
402
  * The binding this tree was listed from and the revision it was listed at.
317
403
  * A parked panel stays MOUNTED behind `display:none`, so a write made off
@@ -336,7 +422,8 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
336
422
  if (rebind) setExpanded(new Set([root]))
337
423
  // Root plus every open directory, once each: `expanded` always holds the
338
424
  // root, and listing it separately on top of the loop listed it twice. They
339
- // are fired concurrently — each one opens its own SFTP session host side.
425
+ // are fired concurrently; Host side they share the alias's browse SFTP
426
+ // session, so a refresh of a deep tree no longer opens one channel per level.
340
427
  for (const dir of new Set(rebind ? [root] : [root, ...expanded])) void loadDir(dir, true)
341
428
  // `expanded` is deliberately not a dependency: opening a directory lists it
342
429
  // itself, so re-listing the whole tree per expand would put the bug back.
@@ -357,6 +444,23 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
357
444
  setListings(prev => trimListings(prev, keep))
358
445
  }, [expanded, alias, listings])
359
446
 
447
+ /** Keep the synchronous cache view in step (prefetch reads it at pointer time). */
448
+ useEffect(() => {
449
+ listingsRef.current = listings
450
+ }, [listings])
451
+
452
+ /** A hover prefetch / late listing must not fire or paint after the panel is gone. */
453
+ useEffect(() => {
454
+ // Re-armed on every effect run: a StrictMode/replay remount runs
455
+ // setup → cleanup → setup, and an `alive` that only ever got set to false
456
+ // would freeze every listing on the second pass.
457
+ alive.current = true
458
+ return () => {
459
+ alive.current = false
460
+ if (prefetchTimer.current !== undefined) window.clearTimeout(prefetchTimer.current)
461
+ }
462
+ }, [])
463
+
360
464
  const rowsOf = useCallback((dir: string): RemoteFileEntry[] | undefined => {
361
465
  const rows = listings[dirKey(alias, dir)]
362
466
  if (rows === undefined) return undefined
@@ -987,6 +1091,19 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
987
1091
  // the listeners are re-attached whenever that identity would change.
988
1092
  }, [root, alias, uploadFromDataTransfer])
989
1093
 
1094
+ // ------------------------------------------------------------- download
1095
+
1096
+ /**
1097
+ * Download one remote file, or one directory as a `.tar.gz`.
1098
+ *
1099
+ * Everything after the click (stat preflight, save dialog, progress, cancel,
1100
+ * completion/failure) lives in `downloads.ts`, so the transfer keeps running
1101
+ * when this panel is hidden or unmounted.
1102
+ */
1103
+ const downloadEntry = (entry: RemoteFileEntry): void => {
1104
+ startDownload(alias, entry.path, { name: entry.name, directory: entry.isDir })
1105
+ }
1106
+
990
1107
  // ---------------------------------------------------------- context menu
991
1108
 
992
1109
  const openMenu = (event: React.MouseEvent, entry: RemoteFileEntry | undefined): void => {
@@ -1073,6 +1190,22 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1073
1190
  })
1074
1191
  entries.push({ label: t('files.copyRel'), onSelect: () => { void copyText(targets.map(item => repoRelative(repoRoot, item.path) || item.path).join('\n')); toast(t('files.copiedClipboard')) }, separated: true })
1075
1192
  entries.push({ label: t('files.copyAbs'), onSelect: () => { void copyText(targets.map(item => item.path).join('\n')); toast(t('files.copiedClipboard')) } })
1193
+ entries.push({
1194
+ label: t('files.download') + (targets.length > 1 ? ` (${targets.length})` : ''),
1195
+ onSelect: () => {
1196
+ if (targets.length === 1) {
1197
+ downloadEntry(entry)
1198
+ return
1199
+ }
1200
+ if (targets.length > MAX_SELECTION_DOWNLOAD) {
1201
+ toast(t('downloads.tooMany'), true)
1202
+ return
1203
+ }
1204
+ // One archive for the whole selection: the user answers ONE save
1205
+ // dialog instead of one per entry, and mixed files/directories work.
1206
+ startSelectionDownload(alias, targets.map(item => item.path))
1207
+ },
1208
+ })
1076
1209
  entries.push({
1077
1210
  label: t('files.referenceFile'),
1078
1211
  onSelect: () => {
@@ -1153,7 +1286,22 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1153
1286
  draggable
1154
1287
  onClick={(e) => selectRow(entry, e)}
1155
1288
  onDoubleClick={() => { if (!entry.isDir) store.openFile(entry.path) }}
1156
- onContextMenu={(e) => openMenu(e, entry)}
1289
+ // Hover-intent prefetch: a directory the pointer rests on gets its
1290
+ // listing warmed, so the click that follows paints instead of
1291
+ // waiting one round trip. Leave/collapse cancels the pending one.
1292
+ onMouseEnter={() => { if (entry.isDir) hoverDir(entry.path) }}
1293
+ onMouseLeave={() => hoverDir(undefined)}
1294
+ // Right-click opens on POINTERDOWN — the first event of the
1295
+ // gesture — so the menu is already mounted before any later
1296
+ // event of the same click (a platform may replay mousedown, and
1297
+ // a background git refresh may scroll) can close it. The
1298
+ // contextmenu fallback covers surfaces that only send that
1299
+ // (touch long-press).
1300
+ onPointerDown={(e) => { if (e.button === 2) openMenu(e, entry) }}
1301
+ onContextMenu={(e) => {
1302
+ e.preventDefault()
1303
+ if (menu.menu === undefined) openMenu(e, entry)
1304
+ }}
1157
1305
  onDragStart={(e) => {
1158
1306
  dragPaths.current = selected.has(entry.path) ? [...selected] : [entry.path]
1159
1307
  e.dataTransfer.effectAllowed = 'move'
@@ -1359,7 +1507,14 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
1359
1507
  }}
1360
1508
  onDrop={(e) => handleDrop(root, e)}
1361
1509
  >
1362
- <div className="rvs-tree" onContextMenu={(e) => openMenu(e, undefined)}>
1510
+ <div
1511
+ className="rvs-tree"
1512
+ onPointerDown={(e) => { if (e.button === 2) openMenu(e, undefined) }}
1513
+ onContextMenu={(e) => {
1514
+ e.preventDefault()
1515
+ if (menu.menu === undefined) openMenu(e, undefined)
1516
+ }}
1517
+ >
1363
1518
  <div className="rvs-empty" style={{ textAlign: 'left', padding: '2px 8px', direction: 'rtl', unicodeBidi: 'plaintext' }} title={rootLabel}>
1364
1519
  <code style={{ fontSize: 11 }}>{rootLabel}</code>
1365
1520
  </div>
@@ -12,6 +12,7 @@ import type { Context } from '@deepseek-ai/cordis'
12
12
  import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
13
13
  import { EditorPane } from './EditorPane.tsx'
14
14
  import { FloatingEditorPlaceholder } from './FloatingPlaceholder.tsx'
15
+ import { DownloadDock } from './DownloadDock.tsx'
15
16
  import { RemoteExplorer } from './RemoteExplorer.tsx'
16
17
  import { SearchView } from './SearchView.tsx'
17
18
  import { HistoryPanel } from './scm/HistoryPanel.tsx'
@@ -328,6 +329,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
328
329
 
329
330
  return (
330
331
  <div className="rvs-root" ref={attachRoot}>
332
+ <DownloadDock t={t} />
331
333
  <div className="rvs-rail">
332
334
  {railButton('explorer', t('tab.files'), <IconCode size={17} />)}
333
335
  {railButton('search', t('tab.search'), <IconSearch size={17} />)}
@@ -22,6 +22,7 @@ import {
22
22
  import { searchFiles, type SearchHit } from './scm/actions.ts'
23
23
  import { repoRelative, useExplorer } from './store.tsx'
24
24
  import { api } from './api.ts'
25
+ import { startDownload } from './downloads.ts'
25
26
  import {
26
27
  ContextMenu,
27
28
  FileIcon,
@@ -239,6 +240,12 @@ export function SearchView(): ReactNode {
239
240
  return { abs, dir }
240
241
  }
241
242
 
243
+ /** Download one found path (a file, or a directory as a `.tar.gz`). */
244
+ const downloadHit = (hit: SearchHit): void => {
245
+ const { abs } = nameHitPaths(hit)
246
+ startDownload(alias, abs, { name: baseName(abs), directory: hit.isDir })
247
+ }
248
+
242
249
  /**
243
250
  * Right-click on a name result: what one does with a found path.
244
251
  *
@@ -256,6 +263,7 @@ export function SearchView(): ReactNode {
256
263
  menu.open(event.clientX, event.clientY, [
257
264
  { label: t('files.copyAbs'), onSelect: () => { void copyText(abs); toast(t('files.copiedClipboard')) } },
258
265
  { label: t('files.copyRel'), onSelect: () => { void copyText(rel); toast(t('files.copiedClipboard')) } },
266
+ { label: t('files.download'), onSelect: () => { downloadHit(hit) } },
259
267
  {
260
268
  label: t('files.openInFloat'),
261
269
  onSelect: () => { store.openInFloatEditor(abs) },