dsh-remote-vs 0.13.0 → 0.15.1
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/README.en.md +455 -443
- package/README.md +408 -396
- package/lib/client.js +8062 -2651
- package/lib/index.js +1058 -288
- package/lib/p2-router-fs.js +1 -1
- package/lib/p2-router-refs.js +89 -10
- package/lib/p2-router-spill.js +73 -1
- package/lib/p2-router-subprocess.js +18 -6
- package/lib/spill-retention-BwKEWrl5.js +115 -0
- package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
- package/lib/types/archive.d.ts +1 -1
- package/lib/types/changes/recorder.d.ts +34 -2
- package/lib/types/client/CodeEditor.d.ts +12 -0
- package/lib/types/client/ConnectionStatus.d.ts +17 -0
- package/lib/types/client/DirectoryFlow.d.ts +2 -0
- package/lib/types/client/DoctorPanel.d.ts +25 -0
- package/lib/types/client/QuickOpen.d.ts +17 -0
- package/lib/types/client/RemoteExplorer.d.ts +192 -1
- package/lib/types/client/RemoteRoot.d.ts +17 -0
- package/lib/types/client/SearchView.d.ts +55 -0
- package/lib/types/client/TerminalView.d.ts +38 -0
- package/lib/types/client/WorkspaceWizard.d.ts +17 -0
- package/lib/types/client/api.d.ts +54 -4
- package/lib/types/client/changes/undo-affordance.d.ts +16 -0
- package/lib/types/client/changes/undo-context.d.ts +14 -18
- package/lib/types/client/changes/undo-target.d.ts +78 -0
- package/lib/types/client/connection.d.ts +111 -0
- package/lib/types/client/doctor.d.ts +122 -0
- package/lib/types/client/download.d.ts +35 -5
- package/lib/types/client/downloads.d.ts +18 -1
- package/lib/types/client/file-open-probe.d.ts +64 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/quickopen-model.d.ts +332 -0
- package/lib/types/client/scm/DiffView.d.ts +34 -0
- package/lib/types/client/scm/actions.d.ts +18 -0
- package/lib/types/client/scm/diff-model.d.ts +17 -1
- package/lib/types/client/scm/git-cache.d.ts +10 -2
- package/lib/types/client/scm/read-queue.d.ts +2 -1
- package/lib/types/client/scm/stage-queue.d.ts +13 -0
- package/lib/types/client/scm/status-map.d.ts +3 -1
- package/lib/types/client/store.d.ts +114 -5
- package/lib/types/client/vsc/FindWidget.d.ts +7 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
- package/lib/types/deploy.d.ts +44 -2
- package/lib/types/git-format.d.ts +15 -0
- package/lib/types/http.d.ts +44 -0
- package/lib/types/p2/file-refs.d.ts +39 -2
- package/lib/types/p2/helper-rpc.d.ts +26 -0
- package/lib/types/p2/router-spill.d.ts +19 -0
- package/lib/types/p2/router-subprocess.d.ts +2 -0
- package/lib/types/p2/spill-retention.d.ts +74 -0
- package/lib/types/p2/worlds.d.ts +11 -0
- package/lib/types/pool.d.ts +73 -11
- package/lib/types/protocol.d.ts +63 -0
- package/lib/types/routes.d.ts +18 -0
- package/lib/types/sftp.d.ts +114 -8
- package/lib/types/store.d.ts +34 -0
- package/lib/types/timeouts.d.ts +14 -0
- package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
- package/package.json +1 -1
- package/src/archive.ts +41 -9
- package/src/changes/recorder.ts +227 -31
- package/src/changes/status.ts +37 -1
- package/src/client/CodeEditor.tsx +84 -2
- package/src/client/ConnectionStatus.tsx +130 -0
- package/src/client/DirectoryFlow.tsx +40 -5
- package/src/client/DoctorPanel.tsx +202 -0
- package/src/client/DownloadDock.tsx +13 -25
- package/src/client/EditorPane.tsx +291 -7
- package/src/client/HostsView.tsx +17 -8
- package/src/client/QuickOpen.tsx +371 -0
- package/src/client/RemoteDirectoryPicker.tsx +54 -3
- package/src/client/RemoteExplorer.tsx +879 -160
- package/src/client/RemoteRoot.tsx +178 -1
- package/src/client/SearchView.tsx +180 -6
- package/src/client/SettingsHosts.tsx +1 -1
- package/src/client/TerminalView.tsx +174 -9
- package/src/client/WorkspaceWizard.tsx +110 -16
- package/src/client/WorkspacesView.tsx +22 -6
- package/src/client/api.ts +197 -11
- package/src/client/changes/ChangesDock.tsx +35 -8
- package/src/client/changes/undo-affordance.ts +33 -0
- package/src/client/changes/undo-context.ts +14 -18
- package/src/client/changes/undo-target.ts +139 -0
- package/src/client/connection.ts +264 -0
- package/src/client/doctor.ts +441 -0
- package/src/client/download.ts +148 -12
- package/src/client/downloads.ts +43 -2
- package/src/client/file-open-probe.ts +83 -0
- package/src/client/i18n.ts +244 -0
- package/src/client/index.tsx +5 -2
- package/src/client/quickopen-model.ts +778 -0
- package/src/client/remote-file-open.ts +21 -33
- package/src/client/scm/DiffView.tsx +116 -6
- package/src/client/scm/ScmPanel.tsx +19 -0
- package/src/client/scm/actions.ts +34 -2
- package/src/client/scm/diff-model.ts +33 -37
- package/src/client/scm/git-cache.ts +61 -4
- package/src/client/scm/read-queue.ts +33 -2
- package/src/client/scm/stage-queue.ts +72 -1
- package/src/client/scm/status-map.ts +22 -1
- package/src/client/store.tsx +704 -21
- package/src/client/vsc/FindWidget.tsx +20 -0
- package/src/client/vsc/kit.tsx +115 -6
- package/src/client/vsc/reveal-line.ts +33 -14
- package/src/client/vsc/save-shortcut.ts +131 -0
- package/src/client/vsc/vsc.css +419 -0
- package/src/deploy.ts +185 -33
- package/src/git-format.ts +136 -22
- package/src/git-ops.ts +14 -6
- package/src/http.ts +80 -12
- package/src/importers.ts +80 -21
- package/src/index.ts +21 -1
- package/src/p2/file-refs.ts +112 -10
- package/src/p2/helper-rpc.ts +73 -36
- package/src/p2/router-spill.ts +96 -1
- package/src/p2/router-subprocess.ts +18 -5
- package/src/p2/spill-retention.ts +134 -0
- package/src/p2/ssh-proc.ts +22 -0
- package/src/p2/worlds.ts +24 -0
- package/src/pool.ts +329 -47
- package/src/protocol.ts +66 -0
- package/src/routes.ts +251 -43
- package/src/sftp.ts +486 -26
- package/src/store.ts +207 -85
- package/src/terminal.ts +38 -2
- package/src/timeouts.ts +14 -0
- package/src/tools.ts +14 -5
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ctrl+P quick open: the portal modal, its list and its keyboard handling.
|
|
3
|
+
*
|
|
4
|
+
* Mounted by `RemoteRoot` only while it is open, so unmounting IS closing (no
|
|
5
|
+
* "is it visible" state to keep in sync), and it reads the same store the tree
|
|
6
|
+
* does: opening a hit is one `store.openFile()`, which makes a quick-open file
|
|
7
|
+
* indistinguishable from one opened in the tree — including cross-workspace
|
|
8
|
+
* binding resolution and the "already open → activate" rule.
|
|
9
|
+
*
|
|
10
|
+
* The index, scoring and the remote command live in `quickopen-model.ts` (pure, and
|
|
11
|
+
* covered by `scripts/check-quickopen.mjs`); this file owns pixels, focus and
|
|
12
|
+
* keys only.
|
|
13
|
+
*/
|
|
14
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from 'react'
|
|
15
|
+
import { createPortal } from 'react-dom'
|
|
16
|
+
import { api, remoteWriteSequence } from './api.ts'
|
|
17
|
+
import {
|
|
18
|
+
QUICKOPEN_RESULT_LIMIT,
|
|
19
|
+
absoluteFromRoot,
|
|
20
|
+
applyIndexFailure,
|
|
21
|
+
applyIndexResult,
|
|
22
|
+
beginIndexBuild,
|
|
23
|
+
buildFileIndex,
|
|
24
|
+
errorText,
|
|
25
|
+
failIndexNow,
|
|
26
|
+
indexNeedsRebuild,
|
|
27
|
+
loadRecentFiles,
|
|
28
|
+
matchPositions,
|
|
29
|
+
quickOpenIndexState,
|
|
30
|
+
rankFiles,
|
|
31
|
+
relativeToRoot,
|
|
32
|
+
rememberRecentFile,
|
|
33
|
+
replaceQuickOpenIndexState,
|
|
34
|
+
splitPath,
|
|
35
|
+
subscribeQuickOpenIndex,
|
|
36
|
+
} from './quickopen-model.ts'
|
|
37
|
+
import { useExplorer } from './store.tsx'
|
|
38
|
+
import { MiniSpinner } from './vsc/kit.tsx'
|
|
39
|
+
|
|
40
|
+
/** One result row: directory dimmed, file name with the matched characters marked. */
|
|
41
|
+
function Row(props: {
|
|
42
|
+
path: string
|
|
43
|
+
query: string
|
|
44
|
+
active: boolean
|
|
45
|
+
index: number
|
|
46
|
+
onPick: () => void
|
|
47
|
+
onHover: () => void
|
|
48
|
+
}): ReactNode {
|
|
49
|
+
const { dir, name } = splitPath(props.path)
|
|
50
|
+
const positions = useMemo(() => new Set(matchPositions(props.query, name)), [props.query, name])
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
className={props.active ? 'rvs-qo-row active' : 'rvs-qo-row'}
|
|
54
|
+
role="option"
|
|
55
|
+
aria-selected={props.active}
|
|
56
|
+
id={`rvs-qo-option-${props.index}`}
|
|
57
|
+
data-qo-index={props.index}
|
|
58
|
+
// mousedown, not click: the list must not lose focus to the page before
|
|
59
|
+
// the pick runs, and a click after a re-render could land on a different
|
|
60
|
+
// row than the one the user pointed at.
|
|
61
|
+
onMouseDown={(event) => {
|
|
62
|
+
event.preventDefault()
|
|
63
|
+
props.onPick()
|
|
64
|
+
}}
|
|
65
|
+
onMouseEnter={props.onHover}
|
|
66
|
+
>
|
|
67
|
+
{dir !== '' && <span className="rvs-qo-dir" title={dir}>{dir}</span>}
|
|
68
|
+
<span className="rvs-qo-name">
|
|
69
|
+
{/* `split('')` keeps the indices code-unit aligned with the offsets
|
|
70
|
+
`matchPositions` produced (`Array.from` would iterate code points
|
|
71
|
+
and shift astral characters out of place). */}
|
|
72
|
+
{name.split('').map((character, at) => (
|
|
73
|
+
positions.has(at)
|
|
74
|
+
? <mark key={at} className="rvs-qo-hit">{character}</mark>
|
|
75
|
+
: <span key={at}>{character}</span>
|
|
76
|
+
))}
|
|
77
|
+
</span>
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function QuickOpen(props: { onClose: () => void }): ReactNode {
|
|
83
|
+
const store = useExplorer()
|
|
84
|
+
const t = store.t
|
|
85
|
+
const alias = store.alias
|
|
86
|
+
const root = store.root
|
|
87
|
+
/**
|
|
88
|
+
* The index is a MODULE cache, not component state.
|
|
89
|
+
*
|
|
90
|
+
* A listing outlives the modal that started it: closing and reopening while it
|
|
91
|
+
* is in flight must show its result when it lands, and reopening must reuse a
|
|
92
|
+
* listing that is still valid. Both are properties of the cache, so the
|
|
93
|
+
* component subscribes to it instead of keeping a copy (see `quickopen-model.ts`).
|
|
94
|
+
*/
|
|
95
|
+
const state = useSyncExternalStore(subscribeQuickOpenIndex, quickOpenIndexState)
|
|
96
|
+
const [query, setQuery] = useState('')
|
|
97
|
+
const [active, setActive] = useState(0)
|
|
98
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
99
|
+
const listRef = useRef<HTMLDivElement>(null)
|
|
100
|
+
const boxRef = useRef<HTMLDivElement>(null)
|
|
101
|
+
|
|
102
|
+
/** Latest close handler, for the window listener installed once below. */
|
|
103
|
+
const closeRef = useRef(props.onClose)
|
|
104
|
+
closeRef.current = props.onClose
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Where focus was before the modal opened.
|
|
108
|
+
*
|
|
109
|
+
* The sheet is portaled to `<body>`, so nothing restores focus by itself: the
|
|
110
|
+
* keyboard user would be dumped on the document body after Esc, one Tab away
|
|
111
|
+
* from wherever they were working. Same rule the themed dialogs follow.
|
|
112
|
+
*/
|
|
113
|
+
const openerRef = useRef<HTMLElement | null>(
|
|
114
|
+
typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
inputRef.current?.focus()
|
|
119
|
+
return () => {
|
|
120
|
+
const opener = openerRef.current
|
|
121
|
+
if (opener !== null && document.body.contains(opener)) opener.focus()
|
|
122
|
+
}
|
|
123
|
+
}, [])
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Tab stays inside the sheet.
|
|
127
|
+
*
|
|
128
|
+
* There is exactly one focusable control (the query field) and the rows are
|
|
129
|
+
* `role="option"` items driven from it, so without a trap the first Tab lands
|
|
130
|
+
* on the page behind the mask — with the modal still open and covering it.
|
|
131
|
+
*/
|
|
132
|
+
const onDialogKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {
|
|
133
|
+
if (event.key !== 'Tab') return
|
|
134
|
+
const box = boxRef.current
|
|
135
|
+
if (box === null) return
|
|
136
|
+
const items = Array.from(box.querySelectorAll<HTMLElement>(
|
|
137
|
+
'input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])',
|
|
138
|
+
))
|
|
139
|
+
if (items.length === 0) return
|
|
140
|
+
const first = items[0]
|
|
141
|
+
const last = items[items.length - 1]
|
|
142
|
+
const at = document.activeElement
|
|
143
|
+
const inside = at !== null && box.contains(at)
|
|
144
|
+
if (!inside) {
|
|
145
|
+
event.preventDefault()
|
|
146
|
+
first.focus()
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
if (event.shiftKey && at === first) {
|
|
150
|
+
event.preventDefault()
|
|
151
|
+
last.focus()
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
if (!event.shiftKey && at === last) {
|
|
155
|
+
event.preventDefault()
|
|
156
|
+
first.focus()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
const onKey = (event: KeyboardEvent): void => {
|
|
162
|
+
if (event.key !== 'Escape') return
|
|
163
|
+
event.preventDefault()
|
|
164
|
+
event.stopPropagation()
|
|
165
|
+
closeRef.current()
|
|
166
|
+
}
|
|
167
|
+
window.addEventListener('keydown', onKey, true)
|
|
168
|
+
return () => window.removeEventListener('keydown', onKey, true)
|
|
169
|
+
}, [])
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Build the index on open, when the cached one cannot answer.
|
|
173
|
+
*
|
|
174
|
+
* The failure branch MUST NOT be turned into an empty index: the footer prints
|
|
175
|
+
* the reason, which is what keeps "the host is unreachable" from looking like
|
|
176
|
+
* "this tree has no files".
|
|
177
|
+
*/
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (alias === '' || root === '') {
|
|
180
|
+
replaceQuickOpenIndexState(failIndexNow(t('quickopen.noWorkspace')))
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
const writeSeq = remoteWriteSequence()
|
|
184
|
+
if (!indexNeedsRebuild(quickOpenIndexState(), alias, root, writeSeq)) return
|
|
185
|
+
replaceQuickOpenIndexState(beginIndexBuild(quickOpenIndexState(), alias, root))
|
|
186
|
+
// The answer is published to the cache whether or not this mount still
|
|
187
|
+
// exists: the next open must see it (and an in-flight build must not leave
|
|
188
|
+
// the footer saying "building…" for a modal that re-opened mid-flight).
|
|
189
|
+
//
|
|
190
|
+
// Both settles read the CURRENT cache state, never the state this effect
|
|
191
|
+
// captured: the settle helpers drop a result whose workspace is no longer
|
|
192
|
+
// the one on screen (the user switched while the listing was in flight), and
|
|
193
|
+
// `target` is what they compare against.
|
|
194
|
+
const target = { alias, root }
|
|
195
|
+
void buildFileIndex({ exec: api.exec, writeSequence: remoteWriteSequence }, target)
|
|
196
|
+
.then(
|
|
197
|
+
index => replaceQuickOpenIndexState(applyIndexResult(quickOpenIndexState(), index)),
|
|
198
|
+
(error: unknown) => replaceQuickOpenIndexState(applyIndexFailure(quickOpenIndexState(), errorText(error), target)),
|
|
199
|
+
)
|
|
200
|
+
}, [alias, root, t])
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Recent files, as workspace-relative paths.
|
|
204
|
+
*
|
|
205
|
+
* Stored absolute (that is what `openFile` takes) and filtered to the CURRENT
|
|
206
|
+
* root: an entry from another workspace must not be shown here, because Enter
|
|
207
|
+
* on it would act on a path whose binding is no longer on screen.
|
|
208
|
+
*/
|
|
209
|
+
const recent = useMemo(() => {
|
|
210
|
+
if (alias === '' || root === '') return []
|
|
211
|
+
const list: string[] = []
|
|
212
|
+
for (const absolute of loadRecentFiles(alias)) {
|
|
213
|
+
const relative = relativeToRoot(root, absolute)
|
|
214
|
+
if (relative !== undefined && relative !== '') list.push(relative)
|
|
215
|
+
}
|
|
216
|
+
return list
|
|
217
|
+
}, [alias, root])
|
|
218
|
+
|
|
219
|
+
const showingRecent = query.trim() === ''
|
|
220
|
+
const candidates = showingRecent ? recent : (state.index?.paths ?? [])
|
|
221
|
+
const ranked = useMemo(
|
|
222
|
+
() => rankFiles(query, candidates, QUICKOPEN_RESULT_LIMIT),
|
|
223
|
+
[query, candidates],
|
|
224
|
+
)
|
|
225
|
+
const count = ranked.hits.length
|
|
226
|
+
const current = count === 0 ? -1 : Math.min(active, count - 1)
|
|
227
|
+
|
|
228
|
+
// A new query (or a new index) starts at the top, never on a stale row.
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
setActive(0)
|
|
231
|
+
}, [query, state.phase, state.index])
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
if (current < 0) return
|
|
235
|
+
const row = listRef.current?.querySelector<HTMLElement>(`[data-qo-index="${current}"]`)
|
|
236
|
+
row?.scrollIntoView?.({ block: 'nearest' })
|
|
237
|
+
}, [current])
|
|
238
|
+
|
|
239
|
+
const pick = (relative: string): void => {
|
|
240
|
+
if (alias === '' || root === '') return
|
|
241
|
+
const absolute = absoluteFromRoot(root, relative)
|
|
242
|
+
rememberRecentFile(alias, absolute)
|
|
243
|
+
store.openFile(absolute)
|
|
244
|
+
props.onClose()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {
|
|
248
|
+
// An IME candidate window uses Enter and the arrows to pick characters.
|
|
249
|
+
// Acting on them would open a file while the user is still composing a
|
|
250
|
+
// Chinese/Japanese/Korean query — a real mis-click for anyone searching a
|
|
251
|
+
// tree by a localized file name. `isComposing` is the platform-agnostic
|
|
252
|
+
// signal; `keyCode === 229` is the older Safari/Chrome fallback.
|
|
253
|
+
if (event.nativeEvent.isComposing === true || event.keyCode === 229) return
|
|
254
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
255
|
+
event.preventDefault()
|
|
256
|
+
if (count === 0) return
|
|
257
|
+
setActive((previous) => {
|
|
258
|
+
const at = Math.min(previous, count - 1)
|
|
259
|
+
if (event.key === 'ArrowDown') return (at + 1) % count
|
|
260
|
+
return at <= 0 ? count - 1 : at - 1
|
|
261
|
+
})
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
if (event.key === 'Enter') {
|
|
265
|
+
event.preventDefault()
|
|
266
|
+
const target = current >= 0 ? ranked.hits[current] : undefined
|
|
267
|
+
if (target !== undefined) pick(target)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The status line under the list.
|
|
273
|
+
*
|
|
274
|
+
* Priority is deliberate: a failure and a build in progress are NOT "no
|
|
275
|
+
* results" and are said first. Truncation is a SECOND line rather than a
|
|
276
|
+
* replacement, because "this index only covers N files" is a standing caveat —
|
|
277
|
+
* it must not hide "nothing matched your query" (nor the other way round).
|
|
278
|
+
*/
|
|
279
|
+
const note = (): ReactNode => {
|
|
280
|
+
if (state.phase === 'error') {
|
|
281
|
+
return (
|
|
282
|
+
<span className="rvs-qo-note error" role="status">
|
|
283
|
+
{t('quickopen.indexError').replace('{reason}', state.error ?? '')}
|
|
284
|
+
</span>
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
if (state.phase === 'loading') {
|
|
288
|
+
return <span className="rvs-qo-note" role="status"><MiniSpinner /> {t('quickopen.indexing')}</span>
|
|
289
|
+
}
|
|
290
|
+
if (showingRecent) {
|
|
291
|
+
return count === 0
|
|
292
|
+
? <span className="rvs-qo-note">{t('quickopen.emptyRecent')}</span>
|
|
293
|
+
: <span className="rvs-qo-note">{t('quickopen.recent')}</span>
|
|
294
|
+
}
|
|
295
|
+
if (count === 0) return <span className="rvs-qo-note">{t('quickopen.noResults')}</span>
|
|
296
|
+
if (ranked.truncated) return <span className="rvs-qo-note">{t('quickopen.more')}</span>
|
|
297
|
+
return null
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (typeof document === 'undefined') return null
|
|
301
|
+
return createPortal(
|
|
302
|
+
<div className="rvs-portal">
|
|
303
|
+
<div
|
|
304
|
+
className="rvs-qo-mask"
|
|
305
|
+
onMouseDown={(event) => { if (event.target === event.currentTarget) props.onClose() }}
|
|
306
|
+
>
|
|
307
|
+
<div
|
|
308
|
+
className="rvs-qo"
|
|
309
|
+
role="dialog"
|
|
310
|
+
aria-modal="true"
|
|
311
|
+
aria-label={t('quickopen.title')}
|
|
312
|
+
ref={boxRef}
|
|
313
|
+
onKeyDown={onDialogKeyDown}
|
|
314
|
+
>
|
|
315
|
+
<div className="rvs-qo-bar">
|
|
316
|
+
<input
|
|
317
|
+
ref={inputRef}
|
|
318
|
+
className="rvs-qo-input"
|
|
319
|
+
type="text"
|
|
320
|
+
value={query}
|
|
321
|
+
placeholder={t('quickopen.placeholder')}
|
|
322
|
+
spellCheck={false}
|
|
323
|
+
autoComplete="off"
|
|
324
|
+
role="combobox"
|
|
325
|
+
aria-expanded
|
|
326
|
+
aria-controls="rvs-qo-list"
|
|
327
|
+
aria-activedescendant={current >= 0 ? `rvs-qo-option-${current}` : undefined}
|
|
328
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
329
|
+
onKeyDown={onInputKeyDown}
|
|
330
|
+
/>
|
|
331
|
+
<span className="rvs-qo-hint">{t('quickopen.hint')}</span>
|
|
332
|
+
</div>
|
|
333
|
+
<div className="rvs-qo-list" id="rvs-qo-list" role="listbox" ref={listRef}>
|
|
334
|
+
{ranked.hits.map((path, index) => (
|
|
335
|
+
<Row
|
|
336
|
+
key={path}
|
|
337
|
+
path={path}
|
|
338
|
+
query={query}
|
|
339
|
+
active={index === current}
|
|
340
|
+
index={index}
|
|
341
|
+
onPick={() => pick(path)}
|
|
342
|
+
onHover={() => setActive(index)}
|
|
343
|
+
/>
|
|
344
|
+
))}
|
|
345
|
+
</div>
|
|
346
|
+
<div className="rvs-qo-foot">
|
|
347
|
+
{note()}
|
|
348
|
+
{state.index?.truncated === true && (
|
|
349
|
+
<span className="rvs-qo-note warn" role="status">
|
|
350
|
+
{t('quickopen.truncated').replace('{count}', String(state.index.paths.length))}
|
|
351
|
+
</span>
|
|
352
|
+
)}
|
|
353
|
+
{state.index?.depthCapped !== undefined && (
|
|
354
|
+
<span className="rvs-qo-note warn" role="status">
|
|
355
|
+
{t('quickopen.depthCapped')
|
|
356
|
+
.replace('{depth}', String(state.index.depthCapped))
|
|
357
|
+
.replace('{count}', String(state.index.paths.length))}
|
|
358
|
+
</span>
|
|
359
|
+
)}
|
|
360
|
+
{state.index?.warning !== undefined && (
|
|
361
|
+
<span className="rvs-qo-note warn" role="status">
|
|
362
|
+
{t('quickopen.warning').replace('{detail}', state.index.warning)}
|
|
363
|
+
</span>
|
|
364
|
+
)}
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
</div>
|
|
368
|
+
</div>,
|
|
369
|
+
document.body,
|
|
370
|
+
)
|
|
371
|
+
}
|
|
@@ -26,6 +26,13 @@ export function RemoteDirectoryPicker(props: {
|
|
|
26
26
|
const [loading, setLoading] = useState(false)
|
|
27
27
|
const [error, setError] = useState<string | undefined>(undefined)
|
|
28
28
|
const generation = useRef(0)
|
|
29
|
+
const boxRef = useRef<HTMLDivElement>(null)
|
|
30
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
31
|
+
const openerRef = useRef<HTMLElement | null>(null)
|
|
32
|
+
const cancelRef = useRef(props.onCancel)
|
|
33
|
+
cancelRef.current = props.onCancel
|
|
34
|
+
const openRef = useRef(props.open)
|
|
35
|
+
openRef.current = props.open
|
|
29
36
|
|
|
30
37
|
const browse = async (dir: string): Promise<void> => {
|
|
31
38
|
const gen = ++generation.current
|
|
@@ -66,6 +73,51 @@ export function RemoteDirectoryPicker(props: {
|
|
|
66
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
74
|
}, [props.open, props.alias])
|
|
68
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Keyboard/focus management for the modal.
|
|
78
|
+
*
|
|
79
|
+
* Opening focuses the path field; Escape works from ANY focus position (it
|
|
80
|
+
* used to be an `onKeyDown` on the inner box, so it only fired while focus was
|
|
81
|
+
* already inside — the usual state right after opening was "outside"); Tab is
|
|
82
|
+
* trapped; closing puts focus back where it came from.
|
|
83
|
+
*/
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!props.open) return
|
|
86
|
+
openerRef.current = typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null)
|
|
87
|
+
const focusTimer = window.setTimeout(() => inputRef.current?.focus(), 0)
|
|
88
|
+
const onKey = (e: KeyboardEvent): void => {
|
|
89
|
+
if (e.key === 'Escape') {
|
|
90
|
+
e.preventDefault()
|
|
91
|
+
cancelRef.current()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
if (e.key !== 'Tab') return
|
|
95
|
+
const box = boxRef.current
|
|
96
|
+
if (box === null) return
|
|
97
|
+
const items = Array.from(box.querySelectorAll<HTMLElement>(
|
|
98
|
+
'button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])',
|
|
99
|
+
))
|
|
100
|
+
if (items.length === 0) return
|
|
101
|
+
const first = items[0] as HTMLElement
|
|
102
|
+
const last = items[items.length - 1] as HTMLElement
|
|
103
|
+
const active = document.activeElement
|
|
104
|
+
if (e.shiftKey && (active === first || active === null || !box.contains(active))) {
|
|
105
|
+
e.preventDefault()
|
|
106
|
+
last.focus()
|
|
107
|
+
} else if (!e.shiftKey && active === last) {
|
|
108
|
+
e.preventDefault()
|
|
109
|
+
first.focus()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
window.addEventListener('keydown', onKey)
|
|
113
|
+
return () => {
|
|
114
|
+
window.clearTimeout(focusTimer)
|
|
115
|
+
window.removeEventListener('keydown', onKey)
|
|
116
|
+
const opener = openerRef.current
|
|
117
|
+
if (opener !== null && document.body.contains(opener)) opener.focus()
|
|
118
|
+
}
|
|
119
|
+
}, [props.open])
|
|
120
|
+
|
|
69
121
|
if (!props.open) return null
|
|
70
122
|
|
|
71
123
|
const parent = path !== '/' ? path.replace(/\/+$/, '').split('/').slice(0, -1).join('/') || '/' : undefined
|
|
@@ -83,6 +135,7 @@ export function RemoteDirectoryPicker(props: {
|
|
|
83
135
|
onClick={props.onCancel}
|
|
84
136
|
>
|
|
85
137
|
<div
|
|
138
|
+
ref={boxRef}
|
|
86
139
|
style={{
|
|
87
140
|
width: 'min(560px, calc(100vw - 32px))',
|
|
88
141
|
maxHeight: 'min(640px, calc(100vh - 32px))',
|
|
@@ -96,13 +149,11 @@ export function RemoteDirectoryPicker(props: {
|
|
|
96
149
|
fontSize: 13,
|
|
97
150
|
}}
|
|
98
151
|
onClick={(e) => e.stopPropagation()}
|
|
99
|
-
onKeyDown={(e) => {
|
|
100
|
-
if (e.key === 'Escape') props.onCancel()
|
|
101
|
-
}}
|
|
102
152
|
>
|
|
103
153
|
<div style={{ fontWeight: 600, marginBottom: 8 }}>{props.title}</div>
|
|
104
154
|
<div style={{ display: 'flex', gap: 8, marginBottom: 8 }}>
|
|
105
155
|
<input
|
|
156
|
+
ref={inputRef}
|
|
106
157
|
value={draft}
|
|
107
158
|
onChange={(e) => setDraft(e.target.value)}
|
|
108
159
|
onKeyDown={(e) => {
|