dsh-ris-ide 1.7.0 → 1.7.2
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.md +3 -3
- package/lib/client-codemirror.js +18 -0
- package/lib/client.js +1192 -123
- package/lib/index.js +1555 -52
- package/lib/standalone/window.html +89 -14
- package/package.json +1 -1
- package/skills/dsh-ris-ide-debug/SKILL.md +2 -2
- package/test/client-viewer.test.mjs +589 -33
- package/test/clipboard.test.mjs +254 -0
- package/test/host-search.test.mjs +125 -1
- package/test/host-tail.test.mjs +198 -21
- package/test/windows.test.mjs +198 -0
package/lib/client.js
CHANGED
|
@@ -269,6 +269,35 @@ window.__ModuleLoader__.load({
|
|
|
269
269
|
var retryTimer = null
|
|
270
270
|
var retryDelay = 3000
|
|
271
271
|
var failures = 0
|
|
272
|
+
/**
|
|
273
|
+
* True once a stream broke. A `dsh web` restart closes every EventSource, so
|
|
274
|
+
* the panes paint their retrying banners; the next successful open means the
|
|
275
|
+
* host is back and those banners are stale.
|
|
276
|
+
*/
|
|
277
|
+
var hadFailure = false
|
|
278
|
+
/** Panes that want to know when the host came back after an outage. */
|
|
279
|
+
var recoveryHandlers = new Set()
|
|
280
|
+
/**
|
|
281
|
+
* Tell every pane the host is reachable again so it can drop its error banner
|
|
282
|
+
* and re-read. Without this a successful background refresh could still leave
|
|
283
|
+
* the red retrying line on screen forever.
|
|
284
|
+
*/
|
|
285
|
+
function announceRecovery() {
|
|
286
|
+
recoveryHandlers.forEach(function (handler) {
|
|
287
|
+
try {
|
|
288
|
+
handler()
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error('[dsh-ris-ide] recovery handler failed', error)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
try {
|
|
294
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
|
|
295
|
+
window.dispatchEvent(new CustomEvent('dsh-ris-ide:host-recovered'))
|
|
296
|
+
}
|
|
297
|
+
} catch {
|
|
298
|
+
// No DOM (tests/SSR): the handler set is the whole contract.
|
|
299
|
+
}
|
|
300
|
+
}
|
|
272
301
|
function closeSource() {
|
|
273
302
|
if (source === null) return
|
|
274
303
|
try { source.close() } catch { /* already closed */ }
|
|
@@ -315,17 +344,30 @@ window.__ModuleLoader__.load({
|
|
|
315
344
|
if (tail !== undefined) url.searchParams.set('tail', tail)
|
|
316
345
|
if (tailBytes !== undefined) url.searchParams.set('bytes', String(tailBytes))
|
|
317
346
|
if (debugPath !== undefined) url.searchParams.set('path', debugPath)
|
|
347
|
+
// The standalone window's stream is also its REGISTRATION (`/windows`): the
|
|
348
|
+
// page never stops being a window, and after a `dsh web` restart it
|
|
349
|
+
// reconnects and re-registers by itself.
|
|
350
|
+
if (typeof window !== 'undefined' && window.__dshRisIdeWindow === true) {
|
|
351
|
+
url.searchParams.set('window', '1')
|
|
352
|
+
if (typeof window.__dshRisIdeWindowName === 'string' && window.__dshRisIdeWindowName !== '') {
|
|
353
|
+
url.searchParams.set('wname', window.__dshRisIdeWindowName)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
318
356
|
source = new EventSource(url.href)
|
|
319
357
|
source.addEventListener('open', function () {
|
|
358
|
+
var recovered = hadFailure === true
|
|
359
|
+
hadFailure = false
|
|
320
360
|
failures = 0
|
|
321
361
|
retryDelay = 3000
|
|
322
362
|
notifyOpen()
|
|
363
|
+
if (recovered === true) announceRecovery()
|
|
323
364
|
})
|
|
324
365
|
source.onerror = function () {
|
|
325
366
|
// EventSource retries by itself; tell subscribers so a panel that needs a
|
|
326
367
|
// fallback can start its own poll after repeated failures. A HARD failure
|
|
327
368
|
// (400/404, readyState 2) never heals: stop reconnecting so a stale
|
|
328
369
|
// session cannot keep hammering the host forever.
|
|
370
|
+
hadFailure = true
|
|
329
371
|
failures += 1
|
|
330
372
|
var readyState = source !== null ? source.readyState : 2
|
|
331
373
|
// Only a HARD failure (400/404, readyState 2) needs our own retry: the
|
|
@@ -413,6 +455,18 @@ window.__ModuleLoader__.load({
|
|
|
413
455
|
* @param {{topics: string[], sessionId?: string, cwd?: string, handlers: object, onOpen?: Function}} sub - the subscription.
|
|
414
456
|
* @returns {Function} unsubscribe.
|
|
415
457
|
*/
|
|
458
|
+
/**
|
|
459
|
+
* Run `handler` whenever the stream comes back after an outage (that is:
|
|
460
|
+
* `dsh web` restarted, or the network blinked). Panes use this to clear the
|
|
461
|
+
* error banner they painted while the host was gone and re-read their data.
|
|
462
|
+
* @param {function(): void} handler - called once per recovery.
|
|
463
|
+
* @returns {function(): void} unsubscribe.
|
|
464
|
+
*/
|
|
465
|
+
hostRecovered: function (handler) {
|
|
466
|
+
if (typeof handler !== 'function') return function () {}
|
|
467
|
+
recoveryHandlers.add(handler)
|
|
468
|
+
return function () { recoveryHandlers.delete(handler) }
|
|
469
|
+
},
|
|
416
470
|
subscribe: function (sub) {
|
|
417
471
|
subscribers.add(sub)
|
|
418
472
|
schedule()
|
|
@@ -1869,6 +1923,25 @@ window.__ModuleLoader__.load({
|
|
|
1869
1923
|
return out
|
|
1870
1924
|
}
|
|
1871
1925
|
|
|
1926
|
+
/**
|
|
1927
|
+
* Run `callback` every time the host becomes reachable again after an outage.
|
|
1928
|
+
*
|
|
1929
|
+
* The callback is kept in a ref, so a component can pass a fresh closure on
|
|
1930
|
+
* every render without resubscribing. `dsh web` restarting is the case this
|
|
1931
|
+
* exists for: the panes keep their last error banner, and nothing else tells
|
|
1932
|
+
* them the host is back.
|
|
1933
|
+
* @param {function(): void} callback - re-read whatever the pane shows.
|
|
1934
|
+
*/
|
|
1935
|
+
function useHostRecovery(callback) {
|
|
1936
|
+
var ref = useRef(callback)
|
|
1937
|
+
ref.current = callback
|
|
1938
|
+
useEffect(function () {
|
|
1939
|
+
var hub = risStreamHub()
|
|
1940
|
+
var off = hub.hostRecovered(function () { ref.current() })
|
|
1941
|
+
return function () { off() }
|
|
1942
|
+
}, [])
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1872
1945
|
function LogTail(props) {
|
|
1873
1946
|
// Inside the IDE this follows the A−/A+ ratio for its chrome; the sidebar's
|
|
1874
1947
|
// own `.log` viewer passes nothing and stays at the default set.
|
|
@@ -1948,6 +2021,9 @@ window.__ModuleLoader__.load({
|
|
|
1948
2021
|
busyRef.current = false
|
|
1949
2022
|
}
|
|
1950
2023
|
}, [path, sessionId, cwd])
|
|
2024
|
+
// The host going away used to leave the tail's error line up forever: after a
|
|
2025
|
+
// `dsh web` restart the pane is still mounted and nothing asks it to retry.
|
|
2026
|
+
useHostRecovery(function () { void refresh() })
|
|
1951
2027
|
|
|
1952
2028
|
// Tail only while this viewer is actually on screen. The sidebar keeps every
|
|
1953
2029
|
// open tab mounted, so without this guard each hidden `.log` viewer kept
|
|
@@ -2257,6 +2333,10 @@ window.__ModuleLoader__.load({
|
|
|
2257
2333
|
setFindIndex(0)
|
|
2258
2334
|
}
|
|
2259
2335
|
setFindOpen(true)
|
|
2336
|
+
// `findOpen` may already be true (the bar is open, focus is in the log
|
|
2337
|
+
// body), so the focus effect below would not run again — put the caret
|
|
2338
|
+
// in the find field right here, like the CodeMirror panel does.
|
|
2339
|
+
if (findInputRef.current !== null) findInputRef.current.focus()
|
|
2260
2340
|
return
|
|
2261
2341
|
}
|
|
2262
2342
|
if (event.key === 'Escape' && findOpen) {
|
|
@@ -2840,7 +2920,7 @@ window.__ModuleLoader__.load({
|
|
|
2840
2920
|
}
|
|
2841
2921
|
|
|
2842
2922
|
/** Deleted entries park here so Ctrl+Z can bring them back. */
|
|
2843
|
-
var TREE_TRASH_DIR = '.dsh-ris-ide
|
|
2923
|
+
var TREE_TRASH_DIR = '.dsh-ris-ide/trash'
|
|
2844
2924
|
|
|
2845
2925
|
/** The workspace's undo trash directory (created on first delete). */
|
|
2846
2926
|
function trashDirFor(root) {
|
|
@@ -3015,8 +3095,8 @@ window.__ModuleLoader__.load({
|
|
|
3015
3095
|
{
|
|
3016
3096
|
title: '配置',
|
|
3017
3097
|
rows: [
|
|
3018
|
-
{ keys: '📄 / ⚙', desc: '在控制台标题栏:📄 打开 .dsh-ris-ide.json,⚙ 按当前扫描结果生成/更新(你改过的字段与自定义程序保留)' },
|
|
3019
|
-
{ keys: '.dsh-ris-ide.json', desc: '在工作区根,是隐藏文件——文件树和检索里都看不到,用 📄 打开;defaults.jvmArgs 与每个程序的 jvmArgs / startCommand 都写这里' },
|
|
3098
|
+
{ keys: '📄 / ⚙', desc: '在控制台标题栏:📄 打开 .dsh-ris-ide/config.json,⚙ 按当前扫描结果生成/更新(你改过的字段与自定义程序保留)' },
|
|
3099
|
+
{ keys: '.dsh-ris-ide/config.json', desc: '在工作区根,是隐藏文件——文件树和检索里都看不到,用 📄 打开;defaults.jvmArgs 与每个程序的 jvmArgs / startCommand 都写这里' },
|
|
3020
3100
|
{ keys: '生效时间', desc: '保存后约 3 秒被读取;jvmArgs 改动要重启该程序才生效' },
|
|
3021
3101
|
],
|
|
3022
3102
|
},
|
|
@@ -3076,6 +3156,22 @@ window.__ModuleLoader__.load({
|
|
|
3076
3156
|
return cut === -1 ? value : value.slice(cut + 1)
|
|
3077
3157
|
}
|
|
3078
3158
|
|
|
3159
|
+
/**
|
|
3160
|
+
* Whether a DOM node is a text field that owns the paste gesture.
|
|
3161
|
+
*
|
|
3162
|
+
* The tree's Ctrl+V used to preventDefault() for EVERY paste while its own
|
|
3163
|
+
* clipboard was non-empty, which stole the keystroke from the editor and from
|
|
3164
|
+
* the OS clipboard. Text entries keep their native paste instead.
|
|
3165
|
+
* @param {EventTarget|null|undefined} node - the keydown/paste target.
|
|
3166
|
+
* @returns {boolean} true for input/textarea/select/contenteditable.
|
|
3167
|
+
*/
|
|
3168
|
+
function isTextEntry(node) {
|
|
3169
|
+
if (node === null || node === undefined || node.nodeType !== 1) return false
|
|
3170
|
+
var tag = String(node.tagName || '').toUpperCase()
|
|
3171
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true
|
|
3172
|
+
return node.isContentEditable === true
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3079
3175
|
/**
|
|
3080
3176
|
* Name of a duplicated copy, keeping the extension: `A.java` → `A - 副本.java`,
|
|
3081
3177
|
* `Makefile` → `Makefile - 副本`, a folder `pkg` → `pkg - 副本`.
|
|
@@ -3471,7 +3567,7 @@ window.__ModuleLoader__.load({
|
|
|
3471
3567
|
function heapHint(program) {
|
|
3472
3568
|
var args = program !== null && program !== undefined && Array.isArray(program.jvmArgs) ? program.jvmArgs : []
|
|
3473
3569
|
if (args.length > 0) return ''
|
|
3474
|
-
return ' · 未配置 jvmArgs:JVM 最大堆默认≈内存/4,多开时建议在 .dsh-ris-ide.json 设 defaults.jvmArgs(如 ["-Xmx768m"])'
|
|
3570
|
+
return ' · 未配置 jvmArgs:JVM 最大堆默认≈内存/4,多开时建议在 .dsh-ris-ide/config.json 设 defaults.jvmArgs(如 ["-Xmx768m"])'
|
|
3475
3571
|
}
|
|
3476
3572
|
|
|
3477
3573
|
/**
|
|
@@ -3595,6 +3691,28 @@ window.__ModuleLoader__.load({
|
|
|
3595
3691
|
return out
|
|
3596
3692
|
}
|
|
3597
3693
|
|
|
3694
|
+
/**
|
|
3695
|
+
* Whether `child` is `parent` itself or lives below it.
|
|
3696
|
+
*
|
|
3697
|
+
* The file tree can be re-rooted into a subfolder (context menu 进入 / a folder
|
|
3698
|
+
* search hit), so `activeRoot` is NOT always the workspace root: locating a
|
|
3699
|
+
* file then has to ask whether the file is reachable from where the tree is
|
|
3700
|
+
* currently rooted at all.
|
|
3701
|
+
* @param {string} parent - absolute directory (trailing slashes ignored).
|
|
3702
|
+
* @param {string} child - absolute path.
|
|
3703
|
+
* @returns {boolean} true when `child` is `parent` or inside it.
|
|
3704
|
+
*/
|
|
3705
|
+
function pathWithin(parent, child) {
|
|
3706
|
+
var raw = String(parent === undefined || parent === null ? '' : parent).replace(/\\/g, '/')
|
|
3707
|
+
var value = String(child === undefined || child === null ? '' : child).replace(/\\/g, '/')
|
|
3708
|
+
var base = raw.replace(/\/+$/, '')
|
|
3709
|
+
// The filesystem root is the one parent whose trailing slash IS its name.
|
|
3710
|
+
if (base === '' && raw !== '') base = '/'
|
|
3711
|
+
if (base === '' || value === '') return false
|
|
3712
|
+
if (base === '/') return value.charAt(0) === '/'
|
|
3713
|
+
return value === base || value.indexOf(base + '/') === 0
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3598
3716
|
/**
|
|
3599
3717
|
* The visible entry of ONE level that contains `filePath` (its own path, or a
|
|
3600
3718
|
* prefix of it). Compaction means a single entry can stand for a whole raw
|
|
@@ -3781,11 +3899,13 @@ window.__ModuleLoader__.load({
|
|
|
3781
3899
|
// A poll whose signature changed can still describe the SAME rows
|
|
3782
3900
|
// (gitignored churn, file content). Keep the old array, skip the render.
|
|
3783
3901
|
if (sameTreeEntries(levelsRef.current[path], listing.entries)) {
|
|
3784
|
-
|
|
3902
|
+
// A successful read proves the banner is stale, background or not:
|
|
3903
|
+
// keeping it up after `dsh web` came back was the bug.
|
|
3904
|
+
setError(undefined)
|
|
3785
3905
|
return true
|
|
3786
3906
|
}
|
|
3787
3907
|
setLevels(function (prev) { var next = Object.assign({}, prev); next[path] = listing.entries; return next })
|
|
3788
|
-
|
|
3908
|
+
setError(undefined)
|
|
3789
3909
|
if (listing.degraded === true) setDegraded(true)
|
|
3790
3910
|
return true
|
|
3791
3911
|
} catch (problem) {
|
|
@@ -3822,11 +3942,31 @@ window.__ModuleLoader__.load({
|
|
|
3822
3942
|
* (`cn.com.ris.cloud.model`) is expanded as the ONE row it is instead of
|
|
3823
3943
|
* walking absolute-path ancestors that no row represents — the old walk left
|
|
3824
3944
|
* the branch empty. Depth is capped and a visited set stops on any repeat.
|
|
3945
|
+
*
|
|
3946
|
+
* Two things used to make the button「sometimes do nothing」:
|
|
3947
|
+
* - the walk read its per-level key from the loop variable inside the
|
|
3948
|
+
* `setExpanded` updater, and React runs that updater LATER — by then the
|
|
3949
|
+
* variable held a deeper path, so the top ancestors never expanded and
|
|
3950
|
+
* the row never existed (the same trap `fetchLevel` documents). The chain
|
|
3951
|
+
* is collected in an array and committed in ONE update instead.
|
|
3952
|
+
* - a tree re-rooted into a subfolder (进入 / a folder search hit) walked
|
|
3953
|
+
* from that subfolder only, so a file outside it was unreachable and the
|
|
3954
|
+
* click silently did nothing. The walk now falls back to the workspace
|
|
3955
|
+
* root, which also re-roots the tree there.
|
|
3825
3956
|
* @param {string} target - file path (relative to `cwd` or absolute).
|
|
3826
3957
|
*/
|
|
3827
3958
|
async function locate(target) {
|
|
3828
3959
|
var filePath = absolutePath(cwd, target)
|
|
3829
|
-
var
|
|
3960
|
+
var workspaceRoot = absolutePath(cwd, rootPath)
|
|
3961
|
+
var startRoot = absolutePath(cwd, activeRoot)
|
|
3962
|
+
// The tree only walks from its current root; a file outside it is only
|
|
3963
|
+
// reachable from the workspace root, so the tree follows the locate.
|
|
3964
|
+
if (!pathWithin(startRoot, filePath) && pathWithin(workspaceRoot, filePath)) {
|
|
3965
|
+
startRoot = workspaceRoot
|
|
3966
|
+
setRootTrail([])
|
|
3967
|
+
}
|
|
3968
|
+
var chain = []
|
|
3969
|
+
var current = startRoot
|
|
3830
3970
|
var visited = {}
|
|
3831
3971
|
for (var guard = 0; guard < 64; guard += 1) {
|
|
3832
3972
|
if (visited[current] === true) break
|
|
@@ -3848,9 +3988,22 @@ window.__ModuleLoader__.load({
|
|
|
3848
3988
|
if (levels[descend] === undefined) {
|
|
3849
3989
|
try { await fetchLevel(descend) } catch (problem) { /* best effort */ }
|
|
3850
3990
|
}
|
|
3851
|
-
|
|
3991
|
+
chain.push(descend)
|
|
3852
3992
|
current = descend
|
|
3853
3993
|
}
|
|
3994
|
+
if (chain.length > 0) {
|
|
3995
|
+
// `chain` is frozen once the walk is done, and the updater reads it (never
|
|
3996
|
+
// the loop variable) — every ancestor of the file is open in one commit.
|
|
3997
|
+
setExpanded(function (prev) {
|
|
3998
|
+
var state = Object.assign({}, prev)
|
|
3999
|
+
for (var index = 0; index < chain.length; index += 1) state[chain[index]] = true
|
|
4000
|
+
return state
|
|
4001
|
+
})
|
|
4002
|
+
}
|
|
4003
|
+
// The located file becomes the tree's selection: a folder that happened to
|
|
4004
|
+
// be selected before (a right click, a multi-selection) must not keep the
|
|
4005
|
+
// strong tint next to the file the editor is now showing.
|
|
4006
|
+
selectOne(filePath)
|
|
3854
4007
|
props.onOpen(filePath)
|
|
3855
4008
|
revealRow(filePath)
|
|
3856
4009
|
}
|
|
@@ -4026,6 +4179,12 @@ window.__ModuleLoader__.load({
|
|
|
4026
4179
|
var [batchConflict, setBatchConflict] = useState(null)
|
|
4027
4180
|
/** Pending delete confirmation: the entry to remove. */
|
|
4028
4181
|
var [pendingDelete, setPendingDelete] = useState(null)
|
|
4182
|
+
/**
|
|
4183
|
+
* A drag that landed on a folder: the move waits for 确认 (`{paths, dir}`).
|
|
4184
|
+
* Dropping used to relocate files on release, so a slip of the mouse (or a
|
|
4185
|
+
* drop meant for the editor) moved them with no way to notice in time.
|
|
4186
|
+
*/
|
|
4187
|
+
var [pendingMove, setPendingMove] = useState(null)
|
|
4029
4188
|
/** Clipboard for copy/cut: `{mode, items:[{path,isDir,name}]}`. */
|
|
4030
4189
|
var [clipboard, setClipboard] = useState(null)
|
|
4031
4190
|
var [selectedPath, setSelectedPath] = useState(null)
|
|
@@ -4041,6 +4200,7 @@ window.__ModuleLoader__.load({
|
|
|
4041
4200
|
var promptInputRef = useRef(null)
|
|
4042
4201
|
/** The delete dialog's 取消 button: focus target so Esc/Enter never fall to BODY. */
|
|
4043
4202
|
var confirmCancelRef = useRef(null)
|
|
4203
|
+
var moveCancelRef = useRef(null)
|
|
4044
4204
|
/** Auto-retry bookkeeping for an unreachable/reloading host. */
|
|
4045
4205
|
var treeRetryRef = useRef({ attempt: 0, timer: null })
|
|
4046
4206
|
var levelsRef = useRef(levels)
|
|
@@ -4050,6 +4210,10 @@ window.__ModuleLoader__.load({
|
|
|
4050
4210
|
var treeRefreshTimersRef = useRef({})
|
|
4051
4211
|
/** A tree frame arrived while the page was hidden: reload once on return. */
|
|
4052
4212
|
var treeDirtyRef = useRef(false)
|
|
4213
|
+
/** When the last `paste` event reached the tree (ms). The Ctrl+V keydown
|
|
4214
|
+
* cannot see the OS clipboard, so it waits one beat for this and only falls
|
|
4215
|
+
* back to the tree's own clipboard when no paste event arrived at all. */
|
|
4216
|
+
var pasteAtRef = useRef(0)
|
|
4053
4217
|
|
|
4054
4218
|
/** The parent folder of a path (the tree only needs string maths). */
|
|
4055
4219
|
function parentOf(path) {
|
|
@@ -4220,6 +4384,10 @@ window.__ModuleLoader__.load({
|
|
|
4220
4384
|
var paths = [activeRoot].concat(Object.keys(expanded).filter(function (path) { return expanded[path] === true }))
|
|
4221
4385
|
for (var index = 0; index < paths.length; index += 1) await loadLevel(paths[index], true)
|
|
4222
4386
|
}
|
|
4387
|
+
// `dsh web` restarting breaks the SSE stream and leaves the red retrying
|
|
4388
|
+
// banner up. The host is back when the stream reopens: clear the banner and
|
|
4389
|
+
// re-read the level on screen instead of waiting for the next poll tick.
|
|
4390
|
+
useHostRecovery(function () { setError(undefined); void recoverTree() })
|
|
4223
4391
|
// While an error is on screen, keep retrying by itself: stopping dsh used to
|
|
4224
4392
|
// leave a dead "重试" banner that survived the host coming back.
|
|
4225
4393
|
useEffect(function () {
|
|
@@ -4307,6 +4475,24 @@ window.__ModuleLoader__.load({
|
|
|
4307
4475
|
}
|
|
4308
4476
|
}, [pendingDelete])
|
|
4309
4477
|
|
|
4478
|
+
// Same contract for the move confirmation: 取消 owns focus, Esc cancels,
|
|
4479
|
+
// and the tree gets the keyboard back when it closes.
|
|
4480
|
+
useEffect(function () {
|
|
4481
|
+
if (pendingMove === null) return undefined
|
|
4482
|
+
var cancel = moveCancelRef.current
|
|
4483
|
+
if (cancel !== null && cancel !== undefined && typeof cancel.focus === 'function') cancel.focus()
|
|
4484
|
+
function onKey(event) {
|
|
4485
|
+
if (event.key !== 'Escape') return
|
|
4486
|
+
event.preventDefault()
|
|
4487
|
+
setPendingMove(null)
|
|
4488
|
+
}
|
|
4489
|
+
document.addEventListener('keydown', onKey, true)
|
|
4490
|
+
return function () {
|
|
4491
|
+
document.removeEventListener('keydown', onKey, true)
|
|
4492
|
+
focusTreeRoot()
|
|
4493
|
+
}
|
|
4494
|
+
}, [pendingMove])
|
|
4495
|
+
|
|
4310
4496
|
// The selection follows the disk: a path that vanished (deleted, moved away,
|
|
4311
4497
|
// watcher reload, folded folder) must leave the batch, or the status bar and
|
|
4312
4498
|
// the delete dialog count ghosts (PM review P1-3, found live: 「删除 3 项?」
|
|
@@ -4488,6 +4674,42 @@ window.__ModuleLoader__.load({
|
|
|
4488
4674
|
if (items.length === 0) return
|
|
4489
4675
|
setClipboard({ mode: mode, items: items })
|
|
4490
4676
|
notify((mode === 'copy' ? '已复制 ' : '已剪切 ') + (items.length > 1 ? items.length + ' 项' : '「' + items[0].name + '」'))
|
|
4677
|
+
// The tree's own Ctrl+V reads the in-memory clipboard; ALSO publishing the
|
|
4678
|
+
// same list to the OS clipboard is what lets the file manager paste it out.
|
|
4679
|
+
void publishSystemClipboard(items, mode)
|
|
4680
|
+
}
|
|
4681
|
+
|
|
4682
|
+
/**
|
|
4683
|
+
* Best-effort mirror of a tree copy onto the SYSTEM clipboard.
|
|
4684
|
+
*
|
|
4685
|
+
* A failure here must NOT fail the copy: the internal clipboard already holds
|
|
4686
|
+
* the entries, so the tree keeps working — only "paste outside the IDE" is
|
|
4687
|
+
* lost. When the Host has no backend at all (a Linux desktop without
|
|
4688
|
+
* xclip/wl-copy), fall back to the paths as TEXT, which a terminal or a text
|
|
4689
|
+
* field still accepts.
|
|
4690
|
+
* @param {Array<{path: string, isDir?: boolean, name?: string}>} items - the copied entries.
|
|
4691
|
+
* @param {'copy'|'cut'} mode - cut asks the OS for a MOVE intent.
|
|
4692
|
+
* @returns {Promise<void>} resolves either way; never rejects.
|
|
4693
|
+
*/
|
|
4694
|
+
async function publishSystemClipboard(items, mode) {
|
|
4695
|
+
try {
|
|
4696
|
+
await fsClipboardFiles(scope, items, mode === 'cut')
|
|
4697
|
+
return
|
|
4698
|
+
} catch (problem) {
|
|
4699
|
+
var code = problem !== null && problem !== undefined && typeof problem.code === 'string' ? problem.code : ''
|
|
4700
|
+
if (code === 'unsupported') {
|
|
4701
|
+
// No OS clipboard backend on this machine at all: a text list is still
|
|
4702
|
+
// better than nothing, and it cannot move any file.
|
|
4703
|
+
try {
|
|
4704
|
+
await navigator.clipboard.writeText(items.map(function (item) { return item.path }).join('\n'))
|
|
4705
|
+
} catch (denied) { /* the tree copy still stands */ }
|
|
4706
|
+
return
|
|
4707
|
+
}
|
|
4708
|
+
// Staging refused (too large / host failure). Saying nothing and falling
|
|
4709
|
+
// back to "the paths as text" would look like success while the files
|
|
4710
|
+
// never left the tree — report it instead.
|
|
4711
|
+
notify('没能放到系统剪贴板:' + messageOf(problem))
|
|
4712
|
+
}
|
|
4491
4713
|
}
|
|
4492
4714
|
|
|
4493
4715
|
/** Whether a failed host call was the "target exists" collision. */
|
|
@@ -4589,6 +4811,11 @@ window.__ModuleLoader__.load({
|
|
|
4589
4811
|
* Resolve a parked batch collision: 覆盖 replaces the existing names,
|
|
4590
4812
|
* 生成副本 suffixes them (`… 副本`, `… 副本(2)`). Every created/deleted path is
|
|
4591
4813
|
* folded into ONE undo entry.
|
|
4814
|
+
*
|
|
4815
|
+
* Two kinds of batch reach this card: tree entries (copy/cut, `item.path`)
|
|
4816
|
+
* and OS-pasted files (`external: true` — a `File` blob or an outside path,
|
|
4817
|
+
* so they are re-sent through `/fs/upload` / `/fs/import` instead of a
|
|
4818
|
+
* host-side copy).
|
|
4592
4819
|
* @param {string} policy - `'overwrite'` | `'copy'`.
|
|
4593
4820
|
*/
|
|
4594
4821
|
async function resolveBatchConflict(policy) {
|
|
@@ -4602,6 +4829,20 @@ window.__ModuleLoader__.load({
|
|
|
4602
4829
|
var failures = []
|
|
4603
4830
|
for (var index = 0; index < pending.items.length; index += 1) {
|
|
4604
4831
|
var item = pending.items[index]
|
|
4832
|
+
if (pending.external === true) {
|
|
4833
|
+
try {
|
|
4834
|
+
if (policy === 'overwrite') {
|
|
4835
|
+
created.push(await importOne(item, pending.dir, item.name, true))
|
|
4836
|
+
} else {
|
|
4837
|
+
var placedExternal = await importOneWithCopyName(item, pending.dir)
|
|
4838
|
+
created.push(placedExternal.path)
|
|
4839
|
+
if (placedExternal.renamed === true) renamed.push(placedExternal.name)
|
|
4840
|
+
}
|
|
4841
|
+
} catch (problem) {
|
|
4842
|
+
failures.push(item.name + '(' + messageOf(problem) + ')')
|
|
4843
|
+
}
|
|
4844
|
+
continue
|
|
4845
|
+
}
|
|
4605
4846
|
var leaf = fileBaseName(item.path)
|
|
4606
4847
|
try {
|
|
4607
4848
|
if (policy === 'overwrite') {
|
|
@@ -4622,15 +4863,16 @@ window.__ModuleLoader__.load({
|
|
|
4622
4863
|
}
|
|
4623
4864
|
}
|
|
4624
4865
|
if (created.length > 0) {
|
|
4625
|
-
var
|
|
4866
|
+
var external = pending.external === true
|
|
4867
|
+
var note = external ? '导入 ' : pending.mode === 'cut' ? '移动 ' : '粘贴 '
|
|
4626
4868
|
rememberUndo(note + created.length + ' 项', async function () {
|
|
4627
4869
|
for (var undo = created.length - 1; undo >= 0; undo -= 1) {
|
|
4628
|
-
if (pending.mode === 'cut') await fsMoveEntry(scope, created[undo], parentOf(origins[undo]), fileBaseName(origins[undo]))
|
|
4870
|
+
if (pending.mode === 'cut' && external !== true) await fsMoveEntry(scope, created[undo], parentOf(origins[undo]), fileBaseName(origins[undo]))
|
|
4629
4871
|
else await fsRemoveEntry(scope, created[undo], true)
|
|
4630
4872
|
}
|
|
4631
4873
|
for (var scan = 0; scan < touched.length; scan += 1) await refreshLevel(touched[scan])
|
|
4632
4874
|
})
|
|
4633
|
-
if (pending.mode === 'cut') setClipboard(null)
|
|
4875
|
+
if (external !== true && pending.mode === 'cut') setClipboard(null)
|
|
4634
4876
|
setExpanded(function (prev) { var next = Object.assign({}, prev); next[pending.dir] = true; return next })
|
|
4635
4877
|
setSelectedPaths(created.slice())
|
|
4636
4878
|
setSelectedPath(created[created.length - 1])
|
|
@@ -4638,8 +4880,11 @@ window.__ModuleLoader__.load({
|
|
|
4638
4880
|
for (var refresh = 0; refresh < touched.length; refresh += 1) await refreshLevel(touched[refresh])
|
|
4639
4881
|
if (renamed.length > 0 || failures.length > 0) notifyCollisionCopies(renamed, failures)
|
|
4640
4882
|
if (created.length > 0) {
|
|
4641
|
-
|
|
4642
|
-
|
|
4883
|
+
var done = pending.external === true
|
|
4884
|
+
? '已导入 ' + created.length + ' 个文件'
|
|
4885
|
+
: (pending.mode === 'cut' ? '已移动 ' : '已粘贴 ') + created.length + ' 项'
|
|
4886
|
+
var undone = '撤销这次' + (pending.external === true ? '导入' : pending.mode === 'cut' ? '移动' : '粘贴') + '(也可 Ctrl+Z)'
|
|
4887
|
+
notifyWithAction(done, undoAction(undone))
|
|
4643
4888
|
}
|
|
4644
4889
|
}
|
|
4645
4890
|
|
|
@@ -4759,7 +5004,7 @@ window.__ModuleLoader__.load({
|
|
|
4759
5004
|
} else if (source.kind === 'file') {
|
|
4760
5005
|
await fsUpload(scope, dir, name, source.file, replace)
|
|
4761
5006
|
} else {
|
|
4762
|
-
await fsImportPath(scope,
|
|
5007
|
+
await fsImportPath(scope, source.path, dir, name, replace)
|
|
4763
5008
|
}
|
|
4764
5009
|
} catch (problem) {
|
|
4765
5010
|
if (isExistsProblem(problem)) {
|
|
@@ -4798,53 +5043,274 @@ window.__ModuleLoader__.load({
|
|
|
4798
5043
|
await runPaste({ kind: 'clipboard' }, dirPath, undefined)
|
|
4799
5044
|
}
|
|
4800
5045
|
|
|
5046
|
+
/**
|
|
5047
|
+
* Put ONE OS-pasted source into `dir`: a `File` blob goes up as raw bytes,
|
|
5048
|
+
* an outside path goes through `/fs/import`.
|
|
5049
|
+
* @param {{kind:'file'|'path', file?:File, path?:string, name:string}} source - one pasted item.
|
|
5050
|
+
* @param {string} dir - absolute destination directory.
|
|
5051
|
+
* @param {string} name - leaf name to write.
|
|
5052
|
+
* @param {boolean} [overwrite] - replace an existing entry.
|
|
5053
|
+
* @returns {Promise<string>} the created absolute path.
|
|
5054
|
+
*/
|
|
5055
|
+
async function importOne(source, dir, name, overwrite) {
|
|
5056
|
+
var trimmedDir = dir.replace(/[\\/]+$/, '')
|
|
5057
|
+
if (source.kind === 'file') await fsUpload(scope, trimmedDir, name, source.file, overwrite === true)
|
|
5058
|
+
else await fsImportPath(scope, source.path, trimmedDir, name, overwrite === true)
|
|
5059
|
+
return trimmedDir + '/' + name
|
|
5060
|
+
}
|
|
5061
|
+
|
|
5062
|
+
/**
|
|
5063
|
+
* Put one OS-pasted source down WITHOUT colliding: retry as `… 副本`,
|
|
5064
|
+
* `… 副本(2)`, … exactly like a batch tree paste (see {@link collisionCopyName}).
|
|
5065
|
+
* @param {{kind:'file'|'path', name:string}} source - one pasted item.
|
|
5066
|
+
* @param {string} dir - absolute destination directory.
|
|
5067
|
+
* @returns {Promise<{path:string, name:string, renamed:boolean}>} where it landed.
|
|
5068
|
+
*/
|
|
5069
|
+
async function importOneWithCopyName(source, dir) {
|
|
5070
|
+
var attempt = 0
|
|
5071
|
+
while (attempt < 60) {
|
|
5072
|
+
var name = attempt === 0 ? source.name : collisionCopyName(source.name, false, attempt)
|
|
5073
|
+
try {
|
|
5074
|
+
return { path: await importOne(source, dir, name, false), name: name, renamed: attempt > 0 }
|
|
5075
|
+
} catch (problem) {
|
|
5076
|
+
if (!isExistsProblem(problem)) throw problem
|
|
5077
|
+
attempt += 1
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
throw new Error('同名条目太多,换个目标目录再试')
|
|
5081
|
+
}
|
|
5082
|
+
|
|
4801
5083
|
/**
|
|
4802
5084
|
* Import OS-clipboard content (a `paste` with no tree clipboard): `File`
|
|
4803
5085
|
* blobs go up as raw bytes, `file://`/path text goes through `/fs/import`.
|
|
4804
|
-
*
|
|
4805
|
-
*
|
|
5086
|
+
*
|
|
5087
|
+
* ONE pasted file keeps the single-file behavior: a collision opens the
|
|
5088
|
+
* 粘贴为 card (改名 / 覆盖). SEVERAL files must never stop on a collision —
|
|
5089
|
+
* the loop used to `break` there, so every file AFTER the first existing
|
|
5090
|
+
* name was silently dropped (copy three files into a folder that already
|
|
5091
|
+
* holds one of them and only part of the batch arrived). A batch therefore
|
|
5092
|
+
* collects the colliding names and parks the same 覆盖 / 生成副本 card a
|
|
5093
|
+
* batch tree paste uses; the rest of the batch is imported right away.
|
|
4806
5094
|
* @param {string} dir - absolute destination directory.
|
|
4807
5095
|
* @param {File[]} files - pasted blobs (may be empty).
|
|
4808
5096
|
* @param {string[]} paths - parseClipboardPaths() result (may be empty).
|
|
4809
5097
|
*/
|
|
4810
5098
|
async function importExternal(dir, files, paths) {
|
|
4811
|
-
var
|
|
4812
|
-
var
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5099
|
+
var trimmedDir = dir.replace(/[\\/]+$/, '')
|
|
5100
|
+
var sources = []
|
|
5101
|
+
var seen = {}
|
|
5102
|
+
for (var index = 0; index < files.length; index += 1) {
|
|
5103
|
+
var file = files[index]
|
|
5104
|
+
var fileName = String(file !== null && file !== undefined && file.name !== undefined ? file.name : '')
|
|
5105
|
+
if (fileName === '' || seen[fileName] === true) continue
|
|
5106
|
+
seen[fileName] = true
|
|
5107
|
+
sources.push({ kind: 'file', file: file, name: fileName })
|
|
5108
|
+
}
|
|
5109
|
+
for (var scan = 0; scan < paths.length; scan += 1) {
|
|
5110
|
+
var leaf = fileBaseName(paths[scan])
|
|
5111
|
+
if (leaf === '' || seen[leaf] === true) continue
|
|
5112
|
+
seen[leaf] = true
|
|
5113
|
+
sources.push({ kind: 'path', path: paths[scan], name: leaf })
|
|
5114
|
+
}
|
|
5115
|
+
if (sources.length === 0) return
|
|
5116
|
+
var created = []
|
|
5117
|
+
var conflicts = []
|
|
5118
|
+
var failures = []
|
|
5119
|
+
for (var cursor = 0; cursor < sources.length; cursor += 1) {
|
|
5120
|
+
var source = sources[cursor]
|
|
5121
|
+
try {
|
|
5122
|
+
created.push(await importOne(source, trimmedDir, source.name, false))
|
|
5123
|
+
} catch (problem) {
|
|
5124
|
+
if (!isExistsProblem(problem)) { failures.push(source.name + '(' + messageOf(problem) + ')'); continue }
|
|
5125
|
+
if (sources.length === 1) {
|
|
5126
|
+
// A single pasted file: the collision is a choice, not a batch.
|
|
5127
|
+
parkPasteName(source, trimmedDir, source.name)
|
|
5128
|
+
return
|
|
5129
|
+
}
|
|
5130
|
+
conflicts.push(source)
|
|
5131
|
+
}
|
|
4820
5132
|
}
|
|
4821
|
-
|
|
5133
|
+
setExpanded(function (prev) { var next = Object.assign({}, prev); next[trimmedDir] = true; return next })
|
|
5134
|
+
if (conflicts.length > 0) {
|
|
5135
|
+
// The unresolved names (and the undo entry for the whole batch) belong to
|
|
5136
|
+
// the card's 覆盖 / 生成副本 resolution. The files that DID land are already
|
|
5137
|
+
// on disk, so the listing is refreshed here: cancelling the card must not
|
|
5138
|
+
// leave them invisible until the next manual refresh.
|
|
5139
|
+
await refreshLevel(trimmedDir)
|
|
5140
|
+
setBatchConflict({
|
|
5141
|
+
mode: 'copy', dir: trimmedDir, items: conflicts, created: created,
|
|
5142
|
+
origins: [], touched: [trimmedDir], external: true,
|
|
5143
|
+
})
|
|
5144
|
+
if (failures.length > 0) notify(failures.length + ' 项失败:' + failures[0])
|
|
5145
|
+
return
|
|
5146
|
+
}
|
|
5147
|
+
await refreshLevel(trimmedDir)
|
|
5148
|
+
if (created.length > 0) {
|
|
5149
|
+
setSelectedPaths(created.slice())
|
|
5150
|
+
setSelectedPath(created[created.length - 1])
|
|
5151
|
+
rememberUndo('导入 ' + created.length + ' 项', async function () {
|
|
5152
|
+
for (var undo = created.length - 1; undo >= 0; undo -= 1) await fsRemoveEntry(scope, created[undo], true)
|
|
5153
|
+
await refreshLevel(trimmedDir)
|
|
5154
|
+
})
|
|
5155
|
+
}
|
|
5156
|
+
var messages = []
|
|
5157
|
+
if (created.length > 0) messages.push('已导入 ' + created.length + ' 个文件')
|
|
5158
|
+
if (failures.length > 0) messages.push(failures.length + ' 项失败:' + failures[0])
|
|
5159
|
+
if (messages.length > 0) notify(messages.join(';'))
|
|
4822
5160
|
}
|
|
4823
5161
|
|
|
4824
5162
|
/**
|
|
4825
5163
|
* The tree list's `paste` handler. The tree only prevents the browser's
|
|
4826
5164
|
* default paste when it actually imports something: an ordinary text paste
|
|
4827
5165
|
* still behaves like a text paste.
|
|
5166
|
+
*
|
|
5167
|
+
* `files` and the URI list are read TOGETHER: some desktops hand over only
|
|
5168
|
+
* `text/uri-list` (no `File` blobs), and a clipboard can carry both — reading
|
|
5169
|
+
* just one half is how a multi-file copy lost the files it did not deliver
|
|
5170
|
+
* as blobs. Names seen on both halves are de-duplicated in
|
|
5171
|
+
* {@link importExternal}.
|
|
4828
5172
|
* @param {ClipboardEvent} event - paste event on the focused tree.
|
|
4829
5173
|
*/
|
|
4830
5174
|
function handleTreePaste(event) {
|
|
4831
5175
|
var transfer = event.clipboardData
|
|
4832
5176
|
if (transfer === null || transfer === undefined) return
|
|
5177
|
+
pasteAtRef.current = Date.now()
|
|
4833
5178
|
var files = []
|
|
4834
5179
|
try { files = Array.prototype.slice.call(transfer.files || []) } catch { files = [] }
|
|
4835
|
-
var dir = pasteTargetDir()
|
|
4836
|
-
if (files.length > 0) {
|
|
4837
|
-
event.preventDefault()
|
|
4838
|
-
void importExternal(dir, files, [])
|
|
4839
|
-
return
|
|
4840
|
-
}
|
|
4841
5180
|
var text = ''
|
|
4842
5181
|
try { text = transfer.getData('text/uri-list') || '' } catch { text = '' }
|
|
4843
5182
|
if (text.trim() === '') { try { text = transfer.getData('text/plain') || '' } catch { text = '' } }
|
|
4844
|
-
var paths = parseClipboardPaths(text)
|
|
4845
|
-
|
|
5183
|
+
var paths = text.trim() === '' ? [] : parseClipboardPaths(text)
|
|
5184
|
+
// The tree handles the gesture either way: it owns the destination.
|
|
4846
5185
|
event.preventDefault()
|
|
4847
|
-
|
|
5186
|
+
if (files.length > 0 || paths.length > 0) {
|
|
5187
|
+
void pasteTreePayload(files, paths)
|
|
5188
|
+
return
|
|
5189
|
+
}
|
|
5190
|
+
// EMPTY payload: in WSL a file copy made in Explorer never reaches the page
|
|
5191
|
+
// (the Windows CF_HDROP flavour is not bridged into Chromium), so the Host —
|
|
5192
|
+
// which can read the OS clipboard — has the final say.
|
|
5193
|
+
void pasteFromOsClipboard(text)
|
|
5194
|
+
}
|
|
5195
|
+
|
|
5196
|
+
/**
|
|
5197
|
+
* Paste content the browser DID deliver, deciding where it came from.
|
|
5198
|
+
*
|
|
5199
|
+
* `beginCopy` publishes the tree's selection to the OS clipboard too, so our
|
|
5200
|
+
* own copy comes back looking exactly like external content. Matching names
|
|
5201
|
+
* are not proof on WSL (a desktop copy of same-named files looks identical),
|
|
5202
|
+
* so the Host's reading of the clipboard settles it: the same paths mean the
|
|
5203
|
+
* tree's own copy (keep cut = move); anything else is NEWER content.
|
|
5204
|
+
* @param {File[]} files - blobs from the paste payload.
|
|
5205
|
+
* @param {string[]} paths - paths parsed from the payload text.
|
|
5206
|
+
*/
|
|
5207
|
+
async function pasteTreePayload(files, paths) {
|
|
5208
|
+
if (clipboard !== null && isTreeClipboardCopy(files, paths)) {
|
|
5209
|
+
var host = await readHostClipboard()
|
|
5210
|
+
if (host === null || host.files.length === 0 || samePathList(host.files, clipboardItems())) {
|
|
5211
|
+
void pasteInto(pasteTargetDir())
|
|
5212
|
+
return
|
|
5213
|
+
}
|
|
5214
|
+
}
|
|
5215
|
+
// Different files than the tree copied — or the same names now pointing at a
|
|
5216
|
+
// NEWER location: the newer clipboard wins, the in-memory copy is dropped.
|
|
5217
|
+
if (clipboard !== null) setClipboard(null)
|
|
5218
|
+
void importExternal(pasteTargetDir(), files, paths)
|
|
5219
|
+
}
|
|
5220
|
+
|
|
5221
|
+
/**
|
|
5222
|
+
* Paste when the payload is empty but the SYSTEM clipboard may still hold a
|
|
5223
|
+
* file list the page cannot see (WSL: Explorer → tree).
|
|
5224
|
+
* @param {string} text - the (usually empty) payload text flavour.
|
|
5225
|
+
*/
|
|
5226
|
+
async function pasteFromOsClipboard(text) {
|
|
5227
|
+
var host = await readHostClipboard()
|
|
5228
|
+
if (host !== null && host.files.length > 0) {
|
|
5229
|
+
if (clipboard !== null && samePathList(host.files, clipboardItems())) {
|
|
5230
|
+
// The tree's own copy is still what the OS clipboard carries.
|
|
5231
|
+
void pasteInto(pasteTargetDir())
|
|
5232
|
+
return
|
|
5233
|
+
}
|
|
5234
|
+
// Fresh files from the OS: a stale in-memory copy must not resurface them.
|
|
5235
|
+
if (clipboard !== null) setClipboard(null)
|
|
5236
|
+
void importExternal(pasteTargetDir(), [], host.files)
|
|
5237
|
+
return
|
|
5238
|
+
}
|
|
5239
|
+
if (clipboard === null) return
|
|
5240
|
+
// Something that is not a file list sits on the OS clipboard (a text copy):
|
|
5241
|
+
// the newer clipboard wins and the stale in-memory one is dropped.
|
|
5242
|
+
var newer = text.trim() !== '' || (host !== null && host.text.trim() !== '')
|
|
5243
|
+
if (newer) {
|
|
5244
|
+
setClipboard(null)
|
|
5245
|
+
notify('系统剪贴板里不是文件,已清空文件树里的旧复制')
|
|
5246
|
+
return
|
|
5247
|
+
}
|
|
5248
|
+
// No paste payload at all and nothing readable: the tree's own clipboard is
|
|
5249
|
+
// the only thing there is to paste.
|
|
5250
|
+
void pasteInto(pasteTargetDir())
|
|
5251
|
+
}
|
|
5252
|
+
|
|
5253
|
+
/**
|
|
5254
|
+
* Whether the OS clipboard holds exactly the entries the tree copied.
|
|
5255
|
+
* Paths are the only identity both sides share.
|
|
5256
|
+
* @param {string[]} files - paths the Host read back from the OS clipboard.
|
|
5257
|
+
* @param {Array<{path: string}>} items - the tree's in-memory clipboard.
|
|
5258
|
+
* @returns {boolean} true when both sides describe the same entries.
|
|
5259
|
+
*/
|
|
5260
|
+
function samePathList(files, items) {
|
|
5261
|
+
if (!Array.isArray(files) || files.length !== items.length) return false
|
|
5262
|
+
var left = files.map(function (path) { return trimTrailingSeparator(path) }).sort()
|
|
5263
|
+
var right = items.map(function (item) { return trimTrailingSeparator(item.path) }).sort()
|
|
5264
|
+
for (var index = 0; index < left.length; index += 1) {
|
|
5265
|
+
if (left[index] !== right[index]) return false
|
|
5266
|
+
}
|
|
5267
|
+
return true
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5270
|
+
/** `/a/b/` → `/a/b`; `/` stays `/` (the root itself is a legal selection). */
|
|
5271
|
+
function trimTrailingSeparator(path) {
|
|
5272
|
+
var value = String(path === null || path === undefined ? '' : path)
|
|
5273
|
+
return value.length > 1 ? value.replace(/[\\/]+$/, '') : value
|
|
5274
|
+
}
|
|
5275
|
+
|
|
5276
|
+
/** The Host's reading of the OS clipboard, or null when it cannot read it. */
|
|
5277
|
+
async function readHostClipboard() {
|
|
5278
|
+
try {
|
|
5279
|
+
var payload = await fsClipboardState(scope)
|
|
5280
|
+
if (payload === null || payload === undefined || payload.ok !== true) return null
|
|
5281
|
+
return {
|
|
5282
|
+
files: Array.isArray(payload.files) ? payload.files : [],
|
|
5283
|
+
text: typeof payload.text === 'string' ? payload.text : '',
|
|
5284
|
+
}
|
|
5285
|
+
} catch (problem) {
|
|
5286
|
+
return null
|
|
5287
|
+
}
|
|
5288
|
+
}
|
|
5289
|
+
|
|
5290
|
+
/**
|
|
5291
|
+
* Whether a `paste` payload is the tree's own clipboard coming back.
|
|
5292
|
+
*
|
|
5293
|
+
* Compares the name multiset (the only identity a pasted `File` exposes):
|
|
5294
|
+
* same names and same count means the OS clipboard carries the very entries
|
|
5295
|
+
* `beginCopy` published, so the tree can paste them itself.
|
|
5296
|
+
* @param {File[]} files - file blobs the OS clipboard delivered.
|
|
5297
|
+
* @param {string[]} paths - absolute paths read from the clipboard text.
|
|
5298
|
+
* @returns {boolean} true when this paste is our own copy.
|
|
5299
|
+
*/
|
|
5300
|
+
function isTreeClipboardCopy(files, paths) {
|
|
5301
|
+
if (clipboard === null) return false
|
|
5302
|
+
var own = clipboardItems().map(function (item) { return item.name || fileBaseName(item.path) })
|
|
5303
|
+
var seen = files.map(function (file) { return file.name })
|
|
5304
|
+
for (var index = 0; index < paths.length; index += 1) seen.push(fileBaseName(paths[index]))
|
|
5305
|
+
if (own.length === 0 || seen.length !== own.length) return false
|
|
5306
|
+
var bag = {}
|
|
5307
|
+
for (var count = 0; count < own.length; count += 1) bag[own[count]] = (bag[own[count]] || 0) + 1
|
|
5308
|
+
for (var scan = 0; scan < seen.length; scan += 1) {
|
|
5309
|
+
var name = seen[scan]
|
|
5310
|
+
if (bag[name] === undefined || bag[name] === 0) return false
|
|
5311
|
+
bag[name] -= 1
|
|
5312
|
+
}
|
|
5313
|
+
return true
|
|
4848
5314
|
}
|
|
4849
5315
|
/** Remember one inverse operation for Ctrl+Z (bounded: 50 entries). */
|
|
4850
5316
|
function rememberUndo(label, run) {
|
|
@@ -4868,7 +5334,7 @@ window.__ModuleLoader__.load({
|
|
|
4868
5334
|
/**
|
|
4869
5335
|
* Delete one row, or every row of the multi-selection (Del / menu 删除).
|
|
4870
5336
|
*
|
|
4871
|
-
* Delete = move into `<workspace>/.dsh-ris-ide
|
|
5337
|
+
* Delete = move into `<workspace>/.dsh-ris-ide/trash`, so Ctrl+Z restores it
|
|
4872
5338
|
* and nothing is lost by a mis-click. A batch is one compound undo entry.
|
|
4873
5339
|
* @param {Array<object>} entries - entries to remove, primary last.
|
|
4874
5340
|
*/
|
|
@@ -4915,13 +5381,44 @@ window.__ModuleLoader__.load({
|
|
|
4915
5381
|
}
|
|
4916
5382
|
}
|
|
4917
5383
|
/**
|
|
4918
|
-
*
|
|
4919
|
-
*
|
|
5384
|
+
* Paths a drop on `dirPath` would actually move: skips the folder itself,
|
|
5385
|
+
* rows already in it, and a folder dragged into its own subtree.
|
|
5386
|
+
* @param {string[]} paths - dragged absolute paths.
|
|
5387
|
+
* @param {string} dirPath - drop directory.
|
|
5388
|
+
* @returns {string[]} the paths worth confirming.
|
|
5389
|
+
*/
|
|
5390
|
+
function movablePaths(paths, dirPath) {
|
|
5391
|
+
var trimmedDir = dirPath.replace(/[\\/]+$/, '')
|
|
5392
|
+
var movable = []
|
|
5393
|
+
for (var index = 0; index < paths.length; index += 1) {
|
|
5394
|
+
var from = paths[index]
|
|
5395
|
+
if (typeof from !== 'string' || from === '') continue
|
|
5396
|
+
if (from === trimmedDir || parentOf(from) === trimmedDir) continue
|
|
5397
|
+
var entry = findEntry(from)
|
|
5398
|
+
if (entry !== undefined && entry !== null && entry.isDir === true && trimmedDir.indexOf(from + '/') === 0) continue
|
|
5399
|
+
movable.push(from)
|
|
5400
|
+
}
|
|
5401
|
+
return movable
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
/** A drop inside the tree: ask first, announce exactly what moves where. */
|
|
5405
|
+
function requestMove(paths, dirPath) {
|
|
5406
|
+
var movable = movablePaths(paths, dirPath)
|
|
5407
|
+
setDropTarget(null)
|
|
5408
|
+
if (movable.length === 0) return
|
|
5409
|
+
setSelectedPaths(movable)
|
|
5410
|
+
setSelectedPath(movable[movable.length - 1])
|
|
5411
|
+
setPendingMove({ paths: movable, dir: dirPath })
|
|
5412
|
+
}
|
|
5413
|
+
|
|
5414
|
+
/**
|
|
5415
|
+
* Move rows (one confirmed drag of a row, or of the whole multi-selection)
|
|
5416
|
+
* into `dirPath`.
|
|
4920
5417
|
*
|
|
4921
|
-
* Every collision becomes a `… 副本` name — a
|
|
4922
|
-
* dialog — and the batch is reported in one toast. Rows
|
|
4923
|
-
* target (or a directory dropped into itself) are
|
|
4924
|
-
* entry (Ctrl+Z) puts everything back.
|
|
5418
|
+
* Every collision becomes a `… 副本` name — even a confirmed move must not
|
|
5419
|
+
* stop half way for a dialog — and the batch is reported in one toast. Rows
|
|
5420
|
+
* already inside the target (or a directory dropped into itself) are
|
|
5421
|
+
* skipped. One compound undo entry (Ctrl+Z) puts everything back.
|
|
4925
5422
|
* @param {string[]} paths - absolute source paths, in drop order.
|
|
4926
5423
|
* @param {string} dirPath - absolute destination directory.
|
|
4927
5424
|
*/
|
|
@@ -5023,7 +5520,7 @@ window.__ModuleLoader__.load({
|
|
|
5023
5520
|
|| active === root
|
|
5024
5521
|
)
|
|
5025
5522
|
if (!inside) return
|
|
5026
|
-
if (prompt !== null || pendingDelete !== null) return
|
|
5523
|
+
if (prompt !== null || pendingDelete !== null || pendingMove !== null) return
|
|
5027
5524
|
if (event.key === 'Escape' && selectedPaths.length > 1) {
|
|
5028
5525
|
// Esc drops the batch but keeps the primary row: batch ops are silent,
|
|
5029
5526
|
// so there must be a one-key way out of a mis-clicked selection.
|
|
@@ -5080,8 +5577,16 @@ window.__ModuleLoader__.load({
|
|
|
5080
5577
|
// leave the key alone so the browser fires `paste` and
|
|
5081
5578
|
// `handleTreePaste` can import it. Only our own clipboard is ours.
|
|
5082
5579
|
if (clipboard === null) return
|
|
5083
|
-
|
|
5084
|
-
|
|
5580
|
+
// A text field owns Ctrl+V: a tree copy must not hijack typing.
|
|
5581
|
+
if (isTextEntry(event.target)) return
|
|
5582
|
+
// The OS clipboard WINS whenever it carries files: only the `paste`
|
|
5583
|
+
// event can see that, so never preventDefault here. An EMPTY OS
|
|
5584
|
+
// clipboard fires no paste at all — wait one beat, then paste ours.
|
|
5585
|
+
var askedAt = Date.now()
|
|
5586
|
+
window.setTimeout(function () {
|
|
5587
|
+
if (pasteAtRef.current >= askedAt) return
|
|
5588
|
+
void pasteInto(pasteTargetDir())
|
|
5589
|
+
}, 150)
|
|
5085
5590
|
}
|
|
5086
5591
|
}
|
|
5087
5592
|
window.addEventListener('keydown', onKey, true)
|
|
@@ -5180,12 +5685,18 @@ window.__ModuleLoader__.load({
|
|
|
5180
5685
|
seen[entry.path] = true
|
|
5181
5686
|
var open = expanded[entry.path] === true
|
|
5182
5687
|
var isActive = props.activePath === entry.path
|
|
5183
|
-
var isRevealed = reveal !== null && reveal.path === entry.path
|
|
5184
5688
|
var isSelected = selectedPath === entry.path
|
|
5185
5689
|
&& (entry.isDir === true || !Array.isArray(props.openFiles) || props.openFiles.indexOf(entry.path) !== -1)
|
|
5186
5690
|
// Extra rows of a multi-selection: highlighted but NOT the primary row
|
|
5187
5691
|
// (menus, rename/delete and the paste target keep acting on `selectedPath`).
|
|
5188
5692
|
var isMulti = selectedPaths.length > 1 && selectedPaths.indexOf(entry.path) !== -1 && !isSelected
|
|
5693
|
+
// The STRONG row tint means one thing only: this is the file the editor is
|
|
5694
|
+
// showing (or the directory a rename/delete/paste is aimed at). A locate
|
|
5695
|
+
// used to paint the located row and keep it lit until the next locate, so
|
|
5696
|
+
// old files stayed highlighted after switching tabs; a file row that is
|
|
5697
|
+
// merely selected (right click, Ctrl+click) now wears the softer multi
|
|
5698
|
+
// tint, keeping the tree's current-file highlight in step with the tabs.
|
|
5699
|
+
var isCurrent = isActive || (isSelected && entry.isDir === true)
|
|
5189
5700
|
// Dropping ON a file means "into the folder that file lives in" — a row
|
|
5190
5701
|
// is always a drop target; only the expand/collapse toggle is dir-only.
|
|
5191
5702
|
var dropDir = entry.isDir === true ? entry.path : parentOf(entry.path)
|
|
@@ -5193,14 +5704,14 @@ window.__ModuleLoader__.load({
|
|
|
5193
5704
|
out.push(h('div', {
|
|
5194
5705
|
key: entry.path,
|
|
5195
5706
|
style: Object.assign({},
|
|
5196
|
-
|
|
5707
|
+
isCurrent ? S.treeRowOn : (isMulti || isSelected ? S.treeRowMulti : S.treeRow),
|
|
5197
5708
|
{
|
|
5198
5709
|
paddingLeft: indent,
|
|
5199
5710
|
boxShadow: isDropTarget ? 'inset 0 0 0 1px #d29922' : undefined,
|
|
5200
5711
|
}),
|
|
5201
5712
|
title: entry.path + (entry.isDir === true ? '(点击:把这个目录当作文件树根 / 三角:展开折叠)' : '') + '(Ctrl+点击 多选 / 右键:新建/粘贴/复制/剪切/删除/刷新)',
|
|
5202
5713
|
'data-tree-path': entry.path,
|
|
5203
|
-
'data-tree-
|
|
5714
|
+
'data-tree-current': isCurrent ? '1' : undefined,
|
|
5204
5715
|
'data-tree-selected': isSelected ? '1' : undefined,
|
|
5205
5716
|
'data-tree-multi': isMulti ? '1' : undefined,
|
|
5206
5717
|
'data-tree-drop': isDropTarget ? '1' : undefined,
|
|
@@ -5240,8 +5751,8 @@ window.__ModuleLoader__.load({
|
|
|
5240
5751
|
var paths = dragPaths(event.dataTransfer)
|
|
5241
5752
|
if (paths.length === 0 && selectedPath !== null) paths = [selectedPath]
|
|
5242
5753
|
paths = paths.filter(function (item) { return item !== entry.path })
|
|
5243
|
-
if (paths.length > 0)
|
|
5244
|
-
setDropTarget(null)
|
|
5754
|
+
if (paths.length > 0) requestMove(paths, dropDir)
|
|
5755
|
+
else setDropTarget(null)
|
|
5245
5756
|
},
|
|
5246
5757
|
onClick: function (event) {
|
|
5247
5758
|
var additive = event.ctrlKey === true || event.metaKey === true
|
|
@@ -5605,10 +6116,46 @@ window.__ModuleLoader__.load({
|
|
|
5605
6116
|
]
|
|
5606
6117
|
}
|
|
5607
6118
|
|
|
6119
|
+
/** The move confirmation: what moves where, 取消 by default. */
|
|
6120
|
+
function renderTreeMoveConfirm() {
|
|
6121
|
+
if (pendingMove === null) return null
|
|
6122
|
+
var paths = pendingMove.paths
|
|
6123
|
+
var dir = pendingMove.dir
|
|
6124
|
+
var first = findEntry(paths[0])
|
|
6125
|
+
var isDir = first !== undefined && first !== null && first.isDir === true
|
|
6126
|
+
var label = paths.length > 1
|
|
6127
|
+
? '移动 ' + paths.length + ' 项?'
|
|
6128
|
+
: (isDir ? '移动这个文件夹?' : '移动这个文件?')
|
|
6129
|
+
var detail = paths.map(function (item) { return fileBaseName(item) + (findEntry(item) !== undefined && findEntry(item) !== null && findEntry(item).isDir === true ? '/' : '') }).join('、')
|
|
6130
|
+
var anchor = dialogAnchor(360, 176)
|
|
6131
|
+
return [
|
|
6132
|
+
h('div', { key: 'move-mask', style: { position: 'fixed', inset: 0, zIndex: 949, background: 'transparent' }, 'data-tree-move-mask': '1', onClick: function () { setPendingMove(null) } }),
|
|
6133
|
+
h('div', {
|
|
6134
|
+
key: 'move-card',
|
|
6135
|
+
style: { position: 'fixed', left: anchor.left, top: anchor.top, zIndex: 950, width: 360, maxWidth: '92vw', background: 'Canvas', color: 'inherit', border: '1px solid color-mix(in srgb, currentColor 25%, transparent)', borderRadius: 6, boxShadow: '0 18px 48px rgba(0,0,0,0.4)', padding: 10, display: 'flex', flexDirection: 'column', gap: 8, fontFamily: 'system-ui, sans-serif', fontSize: 12 },
|
|
6136
|
+
'data-tree-move-confirm': '1',
|
|
6137
|
+
},
|
|
6138
|
+
h('div', { style: { fontWeight: 600 } }, label),
|
|
6139
|
+
h('div', { style: { opacity: 0.75, wordBreak: 'break-all' } }, detail),
|
|
6140
|
+
h('div', { style: { opacity: 0.6, wordBreak: 'break-all' } }, '移动到:' + dir),
|
|
6141
|
+
h('div', { style: { opacity: 0.6 } }, '移动后可按 Ctrl+Z 撤销'),
|
|
6142
|
+
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 6 } },
|
|
6143
|
+
h('button', { type: 'button', style: S.buttonOff, ref: moveCancelRef, 'data-tree-move-cancel': '1', onClick: function () { setPendingMove(null) } }, '取消'),
|
|
6144
|
+
h('button', {
|
|
6145
|
+
type: 'button', style: S.button, 'data-tree-move-ok': '1',
|
|
6146
|
+
onClick: function () {
|
|
6147
|
+
var pending = pendingMove
|
|
6148
|
+
setPendingMove(null)
|
|
6149
|
+
if (pending !== null) void moveEntriesInto(pending.paths, pending.dir)
|
|
6150
|
+
},
|
|
6151
|
+
}, '移动'))),
|
|
6152
|
+
]
|
|
6153
|
+
}
|
|
6154
|
+
|
|
5608
6155
|
// Freeze the anchor once per dialog opening and release it when the last
|
|
5609
6156
|
// dialog closes. Assigning during render is safe here: it only pins the
|
|
5610
6157
|
// point the JSX below already reads; it never drives rendering.
|
|
5611
|
-
var anyDialogOpen = prompt !== null || pendingDelete !== null || batchConflict !== null
|
|
6158
|
+
var anyDialogOpen = prompt !== null || pendingDelete !== null || batchConflict !== null || pendingMove !== null
|
|
5612
6159
|
if (anyDialogOpen === false) dialogPointRef.current = null
|
|
5613
6160
|
else if (dialogPointRef.current === null && pointerRef.current !== null) dialogPointRef.current = pointerRef.current
|
|
5614
6161
|
|
|
@@ -5654,7 +6201,7 @@ window.__ModuleLoader__.load({
|
|
|
5654
6201
|
var paths = dragPaths(event.dataTransfer)
|
|
5655
6202
|
if (paths.length === 0 && selectedPath !== null) paths = [selectedPath]
|
|
5656
6203
|
paths = paths.filter(function (item) { return parentOf(item) !== rootDir })
|
|
5657
|
-
if (paths.length > 0)
|
|
6204
|
+
if (paths.length > 0) requestMove(paths, rootDir)
|
|
5658
6205
|
},
|
|
5659
6206
|
}, rootTrail.length > 0
|
|
5660
6207
|
? h('div', {
|
|
@@ -5668,6 +6215,7 @@ window.__ModuleLoader__.load({
|
|
|
5668
6215
|
renderTreeMenu(),
|
|
5669
6216
|
renderTreePrompt(),
|
|
5670
6217
|
renderTreeConfirm(),
|
|
6218
|
+
renderTreeMoveConfirm(),
|
|
5671
6219
|
renderBatchConflict())
|
|
5672
6220
|
}
|
|
5673
6221
|
|
|
@@ -5687,6 +6235,7 @@ window.__ModuleLoader__.load({
|
|
|
5687
6235
|
var lines = text.split('\n')
|
|
5688
6236
|
var areaRef = useRef(null)
|
|
5689
6237
|
var [findOpen, setFindOpen] = useState(false)
|
|
6238
|
+
var findInputRef = useRef(null)
|
|
5690
6239
|
var [findText, setFindText] = useState('')
|
|
5691
6240
|
var [replaceText, setReplaceText] = useState('')
|
|
5692
6241
|
var [findNote, setFindNote] = useState(undefined)
|
|
@@ -5757,6 +6306,13 @@ window.__ModuleLoader__.load({
|
|
|
5757
6306
|
}
|
|
5758
6307
|
}
|
|
5759
6308
|
setFindOpen(true)
|
|
6309
|
+
// The bar's input is `autoFocus` only on the render that MOUNTS it: with
|
|
6310
|
+
// the bar already open a second Ctrl+F must still move the caret there.
|
|
6311
|
+
var findInput = findInputRef.current
|
|
6312
|
+
if (findInput !== null && findInput !== undefined) {
|
|
6313
|
+
findInput.focus()
|
|
6314
|
+
if (typeof findInput.select === 'function') findInput.select()
|
|
6315
|
+
}
|
|
5760
6316
|
return
|
|
5761
6317
|
}
|
|
5762
6318
|
if ((event.ctrlKey || event.metaKey) && (event.key === 's' || event.key === 'S')) {
|
|
@@ -5781,7 +6337,7 @@ window.__ModuleLoader__.load({
|
|
|
5781
6337
|
}
|
|
5782
6338
|
var findBar = findOpen ? h('div', { style: S.findBar, 'data-editor-find': '1' },
|
|
5783
6339
|
h('input', {
|
|
5784
|
-
style: S.findInput, value: findText, placeholder: '在文件中查找…', autoFocus: true,
|
|
6340
|
+
ref: findInputRef, style: S.findInput, value: findText, placeholder: '在文件中查找…', autoFocus: true,
|
|
5785
6341
|
'data-action': 'find-input',
|
|
5786
6342
|
onChange: function (event) { setFindText(event.target.value); setFindNote(undefined) },
|
|
5787
6343
|
onKeyDown: function (event) {
|
|
@@ -6035,7 +6591,11 @@ window.__ModuleLoader__.load({
|
|
|
6035
6591
|
* using the same `color-mix` / inherited-colour palette as the title bars, so
|
|
6036
6592
|
* light and dark themes both follow the page instead of hard-coding colours.
|
|
6037
6593
|
*/
|
|
6038
|
-
|
|
6594
|
+
// `z-index:20` (baseTheme says 300): the panel only has to sit above the editor's
|
|
6595
|
+
// own content layers, and 300 made it cover the workspace-search dropdown — that
|
|
6596
|
+
// dropdown is anchored in the pane's header row (`editorPaneHead`, z-index 30) and
|
|
6597
|
+
// opens right over the editor's top edge. The header row therefore has to win.
|
|
6598
|
+
var SEARCH_PANEL_CSS = '[data-workbench="ris-ide"] .cm-panels{background:color-mix(in srgb, Canvas 96%, transparent) !important;color:inherit !important;border:0 !important;z-index:20 !important}'
|
|
6039
6599
|
+ '[data-workbench="ris-ide"] .cm-panels-top{border-bottom:1px solid color-mix(in srgb, currentColor 12%, transparent) !important}'
|
|
6040
6600
|
+ '[data-workbench="ris-ide"] .cm-panels-bottom{border-top:1px solid color-mix(in srgb, currentColor 12%, transparent) !important}'
|
|
6041
6601
|
// The panel is the IDE's own (`ideFindPanel` in the editor chunk): two rows,
|
|
@@ -6499,6 +7059,33 @@ window.__ModuleLoader__.load({
|
|
|
6499
7059
|
return h('div', { key: first + index, style: S.largeTextLine, 'data-large-text-line': String(first + index + 1) }, line === '' ? '\u00a0' : line)
|
|
6500
7060
|
})))))
|
|
6501
7061
|
}
|
|
7062
|
+
/**
|
|
7063
|
+
* The ■ stop mark, drawn instead of typed. The character's ink is roughly
|
|
7064
|
+
* half its advance width, so at the control rows' 11–12px it read as a tiny
|
|
7065
|
+
* dot inside the 20px sidebar buttons and the 25px workbench ones (and not
|
|
7066
|
+
* the same size in both). A fixed square is unambiguous at a glance.
|
|
7067
|
+
*
|
|
7068
|
+
* Module scope on purpose: BOTH consoles draw it — the standalone
|
|
7069
|
+
* ProgramWorkbench (rows + batch bar) and the sidebar ProgramsPanel.
|
|
7070
|
+
*/
|
|
7071
|
+
function stopGlyph(size) {
|
|
7072
|
+
var side = typeof size === 'number' ? size : 10
|
|
7073
|
+
return h('span', {
|
|
7074
|
+
'data-glyph': 'stop',
|
|
7075
|
+
style: {
|
|
7076
|
+
// inline-block, not block: a block box carries no line box, so the
|
|
7077
|
+
// typed-glyph buttons around it kept their 20px line and the ■ one
|
|
7078
|
+
// collapsed to the square's own 10px — a visibly shorter border.
|
|
7079
|
+
// inline-block + `middle`, not a block box: a block box carries no
|
|
7080
|
+
// line box, so the typed-glyph buttons around it kept their 20px line
|
|
7081
|
+
// and the ■ one collapsed to the square's own height — a visibly
|
|
7082
|
+
// shorter border. As an inline box it inherits that line again.
|
|
7083
|
+
display: 'inline-block', verticalAlign: 'middle',
|
|
7084
|
+
width: side, height: side, flex: '0 0 auto',
|
|
7085
|
+
background: 'currentColor', borderRadius: 2,
|
|
7086
|
+
},
|
|
7087
|
+
})
|
|
7088
|
+
}
|
|
6502
7089
|
function ProgramWorkbench(props) {
|
|
6503
7090
|
var scope = props ? props.scope : undefined
|
|
6504
7091
|
var tab = props ? props.tab : undefined
|
|
@@ -6736,7 +7323,7 @@ var [ui, setUi] = useState(function () {
|
|
|
6736
7323
|
if (found === undefined) {
|
|
6737
7324
|
// Not in the workspace: it is a dependency class. Ask the host to pull
|
|
6738
7325
|
// it out of a `-sources.jar`, decompile it, or at least javap it (the
|
|
6739
|
-
// files land in `.dsh-ris-ide
|
|
7326
|
+
// files land in `.dsh-ris-ide/cache` and open in the editor).
|
|
6740
7327
|
statusNote('正在获取依赖源码:' + cleaned + '…', 0)
|
|
6741
7328
|
found = await fsDependencySource(scopeRef.current, cleaned, activePathRef === undefined ? activePath : activePathRef.current)
|
|
6742
7329
|
setStatusText('')
|
|
@@ -6843,6 +7430,8 @@ var [ui, setUi] = useState(function () {
|
|
|
6843
7430
|
/** Latest docs map for async loaders (state is closure-stale otherwise). */
|
|
6844
7431
|
var docsRef = useRef(docs)
|
|
6845
7432
|
docsRef.current = docs
|
|
7433
|
+
/** Latest `ensureDoc` (the recovery hook runs outside this render). */
|
|
7434
|
+
var ensureDocRef = useRef(function () {})
|
|
6846
7435
|
/**
|
|
6847
7436
|
* Paths the user chose to force-edit from a large preview: reopening such a
|
|
6848
7437
|
* tab must skip the read-only preview and load the whole file again.
|
|
@@ -7226,6 +7815,23 @@ var [ui, setUi] = useState(function () {
|
|
|
7226
7815
|
return next
|
|
7227
7816
|
})
|
|
7228
7817
|
}
|
|
7818
|
+
// A `dsh web` restart fails every open document once ("读取失败"). The stream
|
|
7819
|
+
// reopening means the host is back: retry only the failed ones (a doc the user
|
|
7820
|
+
// already edited must not be replaced, hence the kind check).
|
|
7821
|
+
useHostRecovery(function () {
|
|
7822
|
+
Object.keys(docsRef.current).forEach(function (path) {
|
|
7823
|
+
var doc = docsRef.current[path]
|
|
7824
|
+
if (doc === null || doc === undefined || doc.kind !== 'error') return
|
|
7825
|
+
setDocs(function (prev) {
|
|
7826
|
+
if (prev[path] === undefined) return prev
|
|
7827
|
+
var next = Object.assign({}, prev)
|
|
7828
|
+
delete next[path]
|
|
7829
|
+
return next
|
|
7830
|
+
})
|
|
7831
|
+
})
|
|
7832
|
+
setTimeout(function () { Object.keys(docsRef.current).forEach(function (path) { ensureDocRef.current(path) }) }, 0)
|
|
7833
|
+
})
|
|
7834
|
+
|
|
7229
7835
|
/** Load one document (idempotent): media kinds need no read at all. */
|
|
7230
7836
|
function ensureDoc(path) {
|
|
7231
7837
|
if (typeof path !== 'string' || path === '') return
|
|
@@ -7295,6 +7901,8 @@ var [ui, setUi] = useState(function () {
|
|
|
7295
7901
|
})
|
|
7296
7902
|
})
|
|
7297
7903
|
}
|
|
7904
|
+
ensureDocRef.current = ensureDoc
|
|
7905
|
+
|
|
7298
7906
|
/**
|
|
7299
7907
|
* Append the next page to a large text preview.
|
|
7300
7908
|
*
|
|
@@ -7491,7 +8099,7 @@ var [ui, setUi] = useState(function () {
|
|
|
7491
8099
|
}
|
|
7492
8100
|
// 📄 in the CONSOLE title bar of the standalone window: that window has no
|
|
7493
8101
|
// DSH sidebar editor, so the panel hands the config path over and it opens
|
|
7494
|
-
// here as an ordinary tab (`.dsh-ris-ide.json` is a hidden dotfile, so the
|
|
8102
|
+
// here as an ordinary tab (`.dsh-ris-ide/config.json` is a hidden dotfile, so the
|
|
7495
8103
|
// tree and the search box cannot reach it).
|
|
7496
8104
|
var configOpenNonce = props.openConfigRequest !== null && typeof props.openConfigRequest === 'object'
|
|
7497
8105
|
&& typeof props.openConfigRequest.nonce === 'number' ? props.openConfigRequest.nonce : 0
|
|
@@ -8347,7 +8955,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8347
8955
|
return function () { window.removeEventListener('mousedown', onDown); window.removeEventListener('keydown', onKey) }
|
|
8348
8956
|
}, [tabMenu])
|
|
8349
8957
|
|
|
8350
|
-
/** Toolbar search: debounce, then
|
|
8958
|
+
/** Toolbar search: debounce, then stream matches page by page from the host route. */
|
|
8351
8959
|
useEffect(function () {
|
|
8352
8960
|
var text = treeQuery.trim()
|
|
8353
8961
|
if (text === '') { setSearchHits(null); setSearchBusy(false); return undefined }
|
|
@@ -8358,27 +8966,43 @@ var [ui, setUi] = useState(function () {
|
|
|
8358
8966
|
return undefined
|
|
8359
8967
|
}
|
|
8360
8968
|
var cancelled = false
|
|
8969
|
+
var controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
8361
8970
|
setSearchBusy(true)
|
|
8362
8971
|
var timer = setTimeout(function () {
|
|
8363
|
-
|
|
8972
|
+
var matches = []
|
|
8973
|
+
fsSearchStream(scopeRef.current, text, {
|
|
8974
|
+
onPage: function (page) {
|
|
8975
|
+
if (cancelled || Array.isArray(page) !== true) return
|
|
8976
|
+
for (var index = 0; index < page.length; index += 1) {
|
|
8977
|
+
if (typeof page[index] === 'string') matches.push(page[index])
|
|
8978
|
+
}
|
|
8979
|
+
// Paint the first page immediately: later roots append while the user reads.
|
|
8980
|
+
if (matches.length > 0) setSearchHits({ matches: matches.slice(), dirs: {} })
|
|
8981
|
+
},
|
|
8982
|
+
}, controller === null ? undefined : controller.signal).then(function () {
|
|
8364
8983
|
if (cancelled) return
|
|
8365
|
-
var payload = searchHitPayload(
|
|
8984
|
+
var payload = searchHitPayload({ matches: matches.slice(), dirs: {} }, cwd)
|
|
8366
8985
|
rememberSearchEntry(searchCacheRef.current, 'name:' + text, payload)
|
|
8367
8986
|
setSearchHits(payload)
|
|
8368
8987
|
setSearchBusy(false)
|
|
8369
8988
|
}).catch(function (problem) {
|
|
8370
|
-
if (cancelled) return
|
|
8989
|
+
if (cancelled || isAbortError(problem)) return
|
|
8371
8990
|
setSearchHits({ error: messageOf(problem) || '未知错误' })
|
|
8372
8991
|
setSearchBusy(false)
|
|
8373
8992
|
})
|
|
8374
8993
|
}, 250)
|
|
8375
|
-
return function () {
|
|
8994
|
+
return function () {
|
|
8995
|
+
cancelled = true
|
|
8996
|
+
clearTimeout(timer)
|
|
8997
|
+
if (controller !== null) controller.abort()
|
|
8998
|
+
}
|
|
8376
8999
|
}, [treeQuery, cwd])
|
|
8377
9000
|
|
|
8378
9001
|
/**
|
|
8379
9002
|
* Content search for the same query: slower than the name search (one
|
|
8380
9003
|
* `git grep -n` per call, no index — a deliberate product promise), so it
|
|
8381
|
-
* runs on its own slightly longer debounce
|
|
9004
|
+
* runs on its own slightly longer debounce, never blocks the file list, and
|
|
9005
|
+
* streams its hits page by page like the name search.
|
|
8382
9006
|
*/
|
|
8383
9007
|
useEffect(function () {
|
|
8384
9008
|
var text = treeQuery.trim()
|
|
@@ -8390,20 +9014,33 @@ var [ui, setUi] = useState(function () {
|
|
|
8390
9014
|
return undefined
|
|
8391
9015
|
}
|
|
8392
9016
|
var cancelled = false
|
|
9017
|
+
var controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
8393
9018
|
setContentBusy(true)
|
|
8394
9019
|
var timer = setTimeout(function () {
|
|
8395
|
-
|
|
9020
|
+
var hits = []
|
|
9021
|
+
fsSearchContentStream(scopeRef.current, text, {
|
|
9022
|
+
onPage: function (page) {
|
|
9023
|
+
if (cancelled || Array.isArray(page) !== true) return
|
|
9024
|
+
for (var index = 0; index < page.length; index += 1) hits.push(page[index])
|
|
9025
|
+
if (hits.length > 0) setContentHits(hits.slice())
|
|
9026
|
+
},
|
|
9027
|
+
}, controller === null ? undefined : controller.signal).then(function () {
|
|
8396
9028
|
if (cancelled) return
|
|
8397
|
-
|
|
8398
|
-
|
|
9029
|
+
var payload = hits.slice()
|
|
9030
|
+
rememberSearchEntry(searchCacheRef.current, 'content:' + text, payload)
|
|
9031
|
+
setContentHits(payload)
|
|
8399
9032
|
setContentBusy(false)
|
|
8400
|
-
}).catch(function () {
|
|
8401
|
-
if (cancelled) return
|
|
9033
|
+
}).catch(function (problem) {
|
|
9034
|
+
if (cancelled || isAbortError(problem)) return
|
|
8402
9035
|
setContentHits([])
|
|
8403
9036
|
setContentBusy(false)
|
|
8404
9037
|
})
|
|
8405
9038
|
}, 450)
|
|
8406
|
-
return function () {
|
|
9039
|
+
return function () {
|
|
9040
|
+
cancelled = true
|
|
9041
|
+
clearTimeout(timer)
|
|
9042
|
+
if (controller !== null) controller.abort()
|
|
9043
|
+
}
|
|
8407
9044
|
}, [treeQuery, cwd])
|
|
8408
9045
|
|
|
8409
9046
|
/**
|
|
@@ -9417,7 +10054,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9417
10054
|
h('span', { style: S.status }, '已勾选 ' + checkedIds.length + ' 项'),
|
|
9418
10055
|
h('span', { style: S.spacer }),
|
|
9419
10056
|
button('▶', function () { void consoleBatch('start') }, { icon: true, width: 25, start: true, action: 'batch-start', title: '按列表顺序启动勾选的项目(跳过已运行的)' }),
|
|
9420
|
-
button(
|
|
10057
|
+
button(stopGlyph(11), function () { void consoleBatch('stop') }, { icon: true, width: 25, stop: true, action: 'batch-stop', title: '按列表倒序停止勾选的项目(跳过未运行的)' }),
|
|
9421
10058
|
button('清除', function () { setCheckedIds([]) }, { action: 'batch-clear', title: '取消全部勾选' }))
|
|
9422
10059
|
: null
|
|
9423
10060
|
return h('div', { style: S.ideBody },
|
|
@@ -9458,7 +10095,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9458
10095
|
? h('span', { style: S.meta, title: '常驻内存(VmRSS)' }, formatMemory(program.running.rssBytes))
|
|
9459
10096
|
: null,
|
|
9460
10097
|
startable && !alive ? button('▶', function (event) { event.stopPropagation(); void consoleStart(program) }, { icon: true, width: 25, start: true, action: 'console-start', title: '启动 ' + program.name }) : null,
|
|
9461
|
-
alive ? button(
|
|
10098
|
+
alive ? button(stopGlyph(11), function (event) { event.stopPropagation(); void consoleStop(program) }, { icon: true, width: 25, stop: true, action: 'console-stop', title: '停止 ' + program.name }) : null,
|
|
9462
10099
|
// ⟳ shares ▶'s green: both (re)start the program, only ■ is red.
|
|
9463
10100
|
startable ? button('⟳', function (event) { event.stopPropagation(); void consoleRestart(program) }, { icon: true, width: 25, start: true, action: 'console-restart', title: '重启 ' + program.name }) : null,
|
|
9464
10101
|
program.kind === 'spring' ? button(ideBadgeIcon('bug', 'play', 13), function (event) { event.stopPropagation(); void consoleDebug(program) }, { icon: true, width: 25, debug: true, off: ui.busy, action: 'console-debug', title: '调试 ' + program.name }) : null,
|
|
@@ -9676,6 +10313,38 @@ var [ui, setUi] = useState(function () {
|
|
|
9676
10313
|
return function () { window.removeEventListener('keydown', onKey) }
|
|
9677
10314
|
}, [visible])
|
|
9678
10315
|
|
|
10316
|
+
// Ctrl/Cmd+F is the editor's find chord and, in the standalone IDE window, it
|
|
10317
|
+
// must never fall through to the browser's own find bar. CodeMirror handles it
|
|
10318
|
+
// while the caret sits in the document, and the panel handles keys pressed
|
|
10319
|
+
// inside itself (both mark the event handled — see `defaultPrevented`); this
|
|
10320
|
+
// listener is the last line for every other focus: the tabs bar, the tree, or
|
|
10321
|
+
// the workspace search box. There it opens the open file's find panel, and the
|
|
10322
|
+
// workspace search box when the open file has no editor (images, "no file").
|
|
10323
|
+
useEffect(function () {
|
|
10324
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
10325
|
+
if (visible === false) return undefined
|
|
10326
|
+
function onFindKey(event) {
|
|
10327
|
+
if (event.defaultPrevented === true) return
|
|
10328
|
+
if (event.ctrlKey !== true && event.metaKey !== true) return
|
|
10329
|
+
if (event.altKey === true || event.shiftKey === true) return
|
|
10330
|
+
var key = String(event.key === undefined || event.key === null ? '' : event.key).toLowerCase()
|
|
10331
|
+
if (key !== 'f') return
|
|
10332
|
+
if (!ownsKeyTarget(event.target)) return
|
|
10333
|
+
event.preventDefault()
|
|
10334
|
+
event.stopPropagation()
|
|
10335
|
+
var controls = typeof openFile === 'string' ? viewerControlsRef.current[openFile] : undefined
|
|
10336
|
+
if (controls !== undefined && controls !== null && typeof controls.find === 'function') {
|
|
10337
|
+
controls.find()
|
|
10338
|
+
return
|
|
10339
|
+
}
|
|
10340
|
+
if (searchInputRef.current === null) return
|
|
10341
|
+
searchFocusPendingRef.current = true
|
|
10342
|
+
setSearchFocusNonce(function (value) { return value + 1 })
|
|
10343
|
+
}
|
|
10344
|
+
window.addEventListener('keydown', onFindKey)
|
|
10345
|
+
return function () { window.removeEventListener('keydown', onFindKey) }
|
|
10346
|
+
}, [visible, openFile])
|
|
10347
|
+
|
|
9679
10348
|
/** Bottom-right help: every shortcut group plus a short how-to. */
|
|
9680
10349
|
function renderHelpPanel() {
|
|
9681
10350
|
return h('div', {
|
|
@@ -9723,16 +10392,16 @@ var [ui, setUi] = useState(function () {
|
|
|
9723
10392
|
}))
|
|
9724
10393
|
}
|
|
9725
10394
|
// The config actions belong to the CONSOLE title bar, not the source pane's:
|
|
9726
|
-
// `.dsh-ris-ide.json` describes the PROGRAMS the console lists (the sidebar
|
|
10395
|
+
// `.dsh-ris-ide/config.json` describes the PROGRAMS the console lists (the sidebar
|
|
9727
10396
|
// console already keeps 打开配置/更新配置 there), so the two controls moved
|
|
9728
10397
|
// next to the program list.
|
|
9729
10398
|
var paneConfig = props.onConfig !== null && typeof props.onConfig === 'object' ? props.onConfig : null
|
|
9730
10399
|
var consoleConfigActions = []
|
|
9731
10400
|
if (paneConfig !== null && typeof paneConfig.open === 'function') {
|
|
9732
|
-
consoleConfigActions.push(button('📄', function () { paneConfig.open() }, { key: 'config-open', icon: true, height: 20, action: 'config-open', title: '打开配置文件 .dsh-ris-ide.json(启动参数由你维护)' }))
|
|
10401
|
+
consoleConfigActions.push(button('📄', function () { paneConfig.open() }, { key: 'config-open', icon: true, height: 20, action: 'config-open', title: '打开配置文件 .dsh-ris-ide/config.json(启动参数由你维护)' }))
|
|
9733
10402
|
}
|
|
9734
10403
|
if (paneConfig !== null && typeof paneConfig.generate === 'function') {
|
|
9735
|
-
consoleConfigActions.push(button('⚙', function () { paneConfig.generate() }, { key: 'config-generate', icon: true, height: 20, action: 'config-generate', title: paneConfig.exists === true ? '更新配置:按当前扫描结果同步 .dsh-ris-ide.json(保留你改过的字段)' : '生成配置:把扫描到的程序写成 .dsh-ris-ide.json' }))
|
|
10404
|
+
consoleConfigActions.push(button('⚙', function () { paneConfig.generate() }, { key: 'config-generate', icon: true, height: 20, action: 'config-generate', title: paneConfig.exists === true ? '更新配置:按当前扫描结果同步 .dsh-ris-ide/config.json(保留你改过的字段)' : '生成配置:把扫描到的程序写成 .dsh-ris-ide/config.json' }))
|
|
9736
10405
|
}
|
|
9737
10406
|
paneActions.push(button('⟲', resetLayout, { key: 'layout-reset', icon: true, height: 20, action: 'layout-reset', title: '还原布局尺寸:左列 300px、调试区 300px、两个下层 260px(不改变最大化状态)' }))
|
|
9738
10407
|
|
|
@@ -9831,7 +10500,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9831
10500
|
settingsRow('反编译工具 jar(可选)', '如 CFR / Procyon 的 jar;填了就把字节码还原成 .java。', jarInput),
|
|
9832
10501
|
settingsRow('参数(可选)', '默认 {classfile}。', argsInput),
|
|
9833
10502
|
h('div', { style: { fontSize: 11, opacity: 0.5, lineHeight: 1.5, marginTop: 10 } },
|
|
9834
|
-
'缓存:.dsh-ris-ide
|
|
10503
|
+
'缓存:.dsh-ris-ide/cache(已从文件树隐藏)'),
|
|
9835
10504
|
debugSettings.error === '' ? null : h('div', { style: { fontSize: 11, color: '#d9534f', marginTop: 8 } }, debugSettings.error),
|
|
9836
10505
|
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 12 } },
|
|
9837
10506
|
h('button', { type: 'button', style: S.buttonOn || S.buttonOff, 'data-debug-settings-save': '1', disabled: debugSettings.loading === true, onClick: function () { void saveDebugSettings() } }, debugSettings.loading === true ? '保存中…' : '保存'),
|
|
@@ -10009,7 +10678,7 @@ var [ui, setUi] = useState(function () {
|
|
|
10009
10678
|
? '当前工作区没有可用的 git:文件树本就显示所有文件'
|
|
10010
10679
|
: (treeShowAll === true
|
|
10011
10680
|
? '显示所有文件:开(含 .gitignore 忽略的;点击恢复过滤)'
|
|
10012
|
-
: '.gitignore
|
|
10681
|
+
: '.gitignore 过滤:开(.git 元数据一并隐藏;点击显示所有文件)'),
|
|
10013
10682
|
onClick: toggleTreeFilter,
|
|
10014
10683
|
}, ideIcon(treeShowAll === true ? 'eyeOff' : 'eye', 14)),
|
|
10015
10684
|
maximize)
|
|
@@ -10467,7 +11136,19 @@ var [ui, setUi] = useState(function () {
|
|
|
10467
11136
|
* @returns {Window} the opened window handle.
|
|
10468
11137
|
* @throws {Error} when the environment has no `window.open`, or the popup was blocked.
|
|
10469
11138
|
*/
|
|
10470
|
-
|
|
11139
|
+
/**
|
|
11140
|
+
* Open — or bring forward — the workspace's ONE IDE window.
|
|
11141
|
+
*
|
|
11142
|
+
* A workspace owns exactly one IDE window, so the registry is asked BEFORE any
|
|
11143
|
+
* window exists: its entries come from the windows' own streams, so it stays
|
|
11144
|
+
* right across `dsh web` restarts (the page reconnects) and only goes quiet well
|
|
11145
|
+
* after the window is really gone. Creating a blank window first and closing it
|
|
11146
|
+
* again (the previous approach) flashes a popup that then disappears and still
|
|
11147
|
+
* cannot focus the window the user already has.
|
|
11148
|
+
* @param {{sessionId?: string, cwd?: string, windowCwd?: string, programId?: string, debug?: boolean}} [options] - scope and target.
|
|
11149
|
+
* @returns {Promise<Window|null>} the window when one was opened, else null (an existing window was asked to come forward).
|
|
11150
|
+
*/
|
|
11151
|
+
async function openStandaloneWindow(options) {
|
|
10471
11152
|
var opts = options === null || options === undefined ? {} : options
|
|
10472
11153
|
if (typeof window === 'undefined' || typeof window.open !== 'function') {
|
|
10473
11154
|
throw new Error('当前环境不支持打开独立窗口')
|
|
@@ -10487,6 +11168,16 @@ var [ui, setUi] = useState(function () {
|
|
|
10487
11168
|
// `debug: true` = open on that program AND start its JDWP session, which is
|
|
10488
11169
|
// what the compact panel's 🐞 button promises (the window owns the debug UI).
|
|
10489
11170
|
if (opts.debug === true) url.searchParams.set('debug', '1')
|
|
11171
|
+
var state = await standaloneWindowState(windowName, windowCwd)
|
|
11172
|
+
if (state.exists === true && state.alive === true) {
|
|
11173
|
+
// The browser will not let this document raise a window some OTHER document
|
|
11174
|
+
// opened, and it will not put the old one on top either. The old window does
|
|
11175
|
+
// not have that problem with itself: ask it to close (it was opened by
|
|
11176
|
+
// script, so it may), wait for the lock to be free, then open a fresh one.
|
|
11177
|
+
// Worst case (old window unresponsive) the new window still boots and shows
|
|
11178
|
+
// the single-window notice with a manual choice.
|
|
11179
|
+
await requestStandaloneWindowClose(windowName)
|
|
11180
|
+
}
|
|
10490
11181
|
// A browser cannot be told to "maximize" through window.open features, so ask
|
|
10491
11182
|
// for the screen's work area at 0,0; window.html enforces it once more on load
|
|
10492
11183
|
// in case the opener size is clamped (the OS still allows restore/resize).
|
|
@@ -10501,6 +11192,112 @@ var [ui, setUi] = useState(function () {
|
|
|
10501
11192
|
return handle
|
|
10502
11193
|
}
|
|
10503
11194
|
|
|
11195
|
+
/**
|
|
11196
|
+
* Ask the host whether the workspace's IDE window is there.
|
|
11197
|
+
* @param windowName - the window name to look up.
|
|
11198
|
+
* @param windowCwd - workspace, for the older name-less registrations.
|
|
11199
|
+
* @returns {Promise<{exists: boolean, alive: boolean}>} what the registry knows.
|
|
11200
|
+
*/
|
|
11201
|
+
async function standaloneWindowState(windowName, windowCwd) {
|
|
11202
|
+
var missing = { exists: false, alive: false }
|
|
11203
|
+
try {
|
|
11204
|
+
var url = routeUrl('dsh-ris-ide/windows')
|
|
11205
|
+
if (typeof windowName === 'string' && windowName !== '') url.searchParams.set('name', windowName)
|
|
11206
|
+
if (typeof windowCwd === 'string' && windowCwd !== '') url.searchParams.set('cwd', windowCwd)
|
|
11207
|
+
var signal = typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(1500) : undefined
|
|
11208
|
+
var response = await fetch(url.href, { headers: { accept: 'application/json' }, signal: signal })
|
|
11209
|
+
if (response.ok !== true) return missing
|
|
11210
|
+
var payload = await response.json()
|
|
11211
|
+
var list = payload !== null && payload !== undefined && Array.isArray(payload.windows) ? payload.windows : []
|
|
11212
|
+
if (list.length === 0) return missing
|
|
11213
|
+
return { exists: true, alive: list.some(function (entry) { return entry !== null && entry.alive === true }) }
|
|
11214
|
+
} catch (error) {
|
|
11215
|
+
return missing
|
|
11216
|
+
}
|
|
11217
|
+
}
|
|
11218
|
+
|
|
11219
|
+
/**
|
|
11220
|
+
* Bring the workspace's window to the front through its BroadcastChannel.
|
|
11221
|
+
* @param windowName - the channel the window listens on.
|
|
11222
|
+
* @returns {void}
|
|
11223
|
+
*/
|
|
11224
|
+
/**
|
|
11225
|
+
* Ask the ONE open IDE window of this workspace to close itself.
|
|
11226
|
+
*
|
|
11227
|
+
* The browser will not let us raise a window another document opened, but that
|
|
11228
|
+
* window was opened by `window.open`, so IT may call `window.close()` on itself.
|
|
11229
|
+
* The opener tells it to and waits (briefly) for the host registry to report the
|
|
11230
|
+
* stream gone, i.e. for the single-window lock to be free again.
|
|
11231
|
+
* @param {string} windowName - workspace-derived window/lock name.
|
|
11232
|
+
* @returns {Promise<boolean>} true when the old window closed in time.
|
|
11233
|
+
*/
|
|
11234
|
+
function requestStandaloneWindowClose(windowName) {
|
|
11235
|
+
if (typeof windowName !== 'string' || windowName === '' || typeof BroadcastChannel !== 'function') return Promise.resolve(false)
|
|
11236
|
+
var channel
|
|
11237
|
+
try {
|
|
11238
|
+
channel = new BroadcastChannel(windowName)
|
|
11239
|
+
} catch (error) {
|
|
11240
|
+
return Promise.resolve(false)
|
|
11241
|
+
}
|
|
11242
|
+
var done = false
|
|
11243
|
+
function release() { if (done === true) return; done = true; try { channel.close() } catch (error) { /* already closed */ } }
|
|
11244
|
+
try {
|
|
11245
|
+
channel.postMessage({ type: 'close' })
|
|
11246
|
+
} catch (error) {
|
|
11247
|
+
release()
|
|
11248
|
+
return Promise.resolve(false)
|
|
11249
|
+
}
|
|
11250
|
+
return new Promise(function (resolve) {
|
|
11251
|
+
var deadline = Date.now() + 1500
|
|
11252
|
+
function poll() {
|
|
11253
|
+
void standaloneWindowState(windowName, undefined).then(function (state) {
|
|
11254
|
+
if (state.alive !== true) { release(); resolve(true); return }
|
|
11255
|
+
if (Date.now() >= deadline) { release(); resolve(false); return }
|
|
11256
|
+
setTimeout(poll, 100)
|
|
11257
|
+
}, function () { release(); resolve(false) })
|
|
11258
|
+
}
|
|
11259
|
+
setTimeout(poll, 100)
|
|
11260
|
+
})
|
|
11261
|
+
}
|
|
11262
|
+
|
|
11263
|
+
/**
|
|
11264
|
+
* The standalone window's React root — it owns the scope the panels run on.
|
|
11265
|
+
*
|
|
11266
|
+
* The window's session id comes from the URL, so a window left open across a
|
|
11267
|
+
* `dsh web` restart keeps an id that no longer exists. The host's `hello` frame
|
|
11268
|
+
* carries the session the workspace is really on now; adopt it when this
|
|
11269
|
+
* window's own id is gone (and stay put while it is still live, so a window
|
|
11270
|
+
* opened by THIS dsh keeps the session its titles and logs belong to).
|
|
11271
|
+
* @param {{sessionId: string, cwd: string}} props - scope taken from the URL.
|
|
11272
|
+
* @returns {object} the panel tree.
|
|
11273
|
+
*/
|
|
11274
|
+
function StandaloneWindow(props) {
|
|
11275
|
+
var initial = props.sessionId
|
|
11276
|
+
var scopeState = useState(initial)
|
|
11277
|
+
var sessionId = scopeState[0]
|
|
11278
|
+
var setSessionId = scopeState[1]
|
|
11279
|
+
useEffect(function () {
|
|
11280
|
+
var hub = risStreamHub()
|
|
11281
|
+
return hub.subscribe({
|
|
11282
|
+
topics: ['hello'],
|
|
11283
|
+
handlers: {
|
|
11284
|
+
hello: function (payload) {
|
|
11285
|
+
if (payload === null || payload === undefined || payload.ok !== true) return
|
|
11286
|
+
var session = payload.session !== null && payload.session !== undefined ? payload.session : null
|
|
11287
|
+
var live = session !== null ? session.id : undefined
|
|
11288
|
+
if (typeof live !== 'string' || live === '' || live === sessionId) return
|
|
11289
|
+
var mine = payload.windowSession !== null && payload.windowSession !== undefined ? payload.windowSession : null
|
|
11290
|
+
// Still live: this window belongs to a session that exists, so the
|
|
11291
|
+
// newer session in the same workspace is a DIFFERENT thread — leave it.
|
|
11292
|
+
if (mine !== null && mine.live === true) return
|
|
11293
|
+
setSessionId(live)
|
|
11294
|
+
},
|
|
11295
|
+
},
|
|
11296
|
+
})
|
|
11297
|
+
}, [sessionId, props.cwd])
|
|
11298
|
+
return h(ProgramsPanel, { sessionId: sessionId, cwd: props.cwd, visible: true, compact: false })
|
|
11299
|
+
}
|
|
11300
|
+
|
|
10504
11301
|
/**
|
|
10505
11302
|
* Mount the IDE panel into a plain container, outside DSH's module system.
|
|
10506
11303
|
*
|
|
@@ -10530,9 +11327,15 @@ var [ui, setUi] = useState(function () {
|
|
|
10530
11327
|
var reactDom = require('react-dom/client')
|
|
10531
11328
|
var createRoot = reactDom !== null && reactDom !== undefined ? reactDom.createRoot : undefined
|
|
10532
11329
|
if (typeof createRoot !== 'function') throw new Error('react-dom/client 不可用')
|
|
11330
|
+
if (typeof window !== 'undefined') {
|
|
11331
|
+
// The hub puts these in the stream URL: `window=1` registers this window's
|
|
11332
|
+
// liveness with the host, and the name is what the DSH page looks up before
|
|
11333
|
+
// it opens a second one.
|
|
11334
|
+
window.__dshRisIdeWindowName = typeof opts.windowName === 'string' ? opts.windowName : ''
|
|
11335
|
+
}
|
|
10533
11336
|
var root = createRoot(container)
|
|
10534
11337
|
// The window always shows the FULL IDE (compact is the sidebar's shape).
|
|
10535
|
-
root.render(h(IdeErrorBoundary, null, h(
|
|
11338
|
+
root.render(h(IdeErrorBoundary, null, h(StandaloneWindow, { sessionId: sessionId, cwd: cwd })))
|
|
10536
11339
|
return root
|
|
10537
11340
|
}
|
|
10538
11341
|
|
|
@@ -10584,11 +11387,11 @@ var [ui, setUi] = useState(function () {
|
|
|
10584
11387
|
if (blocked === true) {
|
|
10585
11388
|
return h('span', { style: S.windowButtonError, role: 'status', title: '允许本站弹窗后重试' }, '窗口被拦截')
|
|
10586
11389
|
}
|
|
10587
|
-
function onClick(event) {
|
|
11390
|
+
async function onClick(event) {
|
|
10588
11391
|
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
10589
11392
|
try {
|
|
10590
|
-
var handle = openStandaloneWindow({ sessionId: sessionId })
|
|
10591
|
-
if (handle !== null && typeof handle.focus === 'function') handle.focus()
|
|
11393
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId })
|
|
11394
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
10592
11395
|
} catch (error) {
|
|
10593
11396
|
console.warn('dsh-ris-ide: 独立窗口打开失败:' + messageOf(error))
|
|
10594
11397
|
setBlocked(true)
|
|
@@ -11228,10 +12031,84 @@ var [ui, setUi] = useState(function () {
|
|
|
11228
12031
|
* @param {boolean} [overwrite] - replace an existing entry.
|
|
11229
12032
|
* @returns {Promise<object>} the host payload (`{ok, path, name}`).
|
|
11230
12033
|
*/
|
|
11231
|
-
async function fsImportPath(scope,
|
|
11232
|
-
|
|
12034
|
+
async function fsImportPath(scope, sourcePath, dir, name, overwrite) {
|
|
12035
|
+
// The host reads `from` = SOURCE and `dir` = DESTINATION; keep that order here.
|
|
12036
|
+
return fsOp('import', scope, { from: sourcePath, dir: dir, name: name, overwrite: overwrite === true })
|
|
11233
12037
|
}
|
|
11234
12038
|
|
|
12039
|
+
/**
|
|
12040
|
+
* `?sessionId&cwd` for the clipboard routes.
|
|
12041
|
+
*
|
|
12042
|
+
* The Host stages a COPY inside the workspace (`<root>/.dsh-ris-ide/stage`), so
|
|
12043
|
+
* both the publish and the read need to know WHICH workspace: the read has to
|
|
12044
|
+
* translate a staged path back to the original one, otherwise Ctrl+C → Ctrl+V
|
|
12045
|
+
* would look like foreign files and import a second copy.
|
|
12046
|
+
* @param {{sessionId?: string, cwd?: string}|undefined} scope - owning session.
|
|
12047
|
+
* @returns {string} a query string, `''` when the scope is unknown.
|
|
12048
|
+
*/
|
|
12049
|
+
function clipboardQuery(scope) {
|
|
12050
|
+
if (scope === null || scope === undefined) return ''
|
|
12051
|
+
var query = []
|
|
12052
|
+
if (typeof scope.sessionId === 'string' && scope.sessionId !== '') query.push('sessionId=' + encodeURIComponent(scope.sessionId))
|
|
12053
|
+
if (typeof scope.cwd === 'string' && scope.cwd !== '') query.push('cwd=' + encodeURIComponent(scope.cwd))
|
|
12054
|
+
return query.length === 0 ? '' : '?' + query.join('&')
|
|
12055
|
+
}
|
|
12056
|
+
|
|
12057
|
+
/**
|
|
12058
|
+
* Publish a file list to the SYSTEM clipboard through the Host.
|
|
12059
|
+
*
|
|
12060
|
+
* A web page cannot do this itself: Chromium refuses `text/uri-list` (and
|
|
12061
|
+
* `x-special/gnome-copied-files`) on `Clipboard.write`, and a synthetic
|
|
12062
|
+
* `copy` event only produces Chrome's private `x-web-custom-data` flavour.
|
|
12063
|
+
* Only the Host can put a real file list (CF_HDROP / `file://` URIs) on the
|
|
12064
|
+
* OS clipboard, so that a file manager can paste the files out of the tree.
|
|
12065
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
12066
|
+
* @param {Array<{path: string}>} items - entries to publish (absolute paths).
|
|
12067
|
+
* @param {boolean} cut - `true` for a MOVE intent, `false` for COPY.
|
|
12068
|
+
* @returns {Promise<{ok: boolean, count?: number, method?: string, staged?: boolean}>} host payload.
|
|
12069
|
+
*/
|
|
12070
|
+
async function fsClipboardFiles(scope, items, cut) {
|
|
12071
|
+
var response = await fetch(routeUrl('dsh-ris-ide/clipboard/files').href + clipboardQuery(scope), {
|
|
12072
|
+
method: 'POST',
|
|
12073
|
+
headers: { 'content-type': 'application/json' },
|
|
12074
|
+
body: JSON.stringify({
|
|
12075
|
+
paths: items.map(function (item) { return item.path }),
|
|
12076
|
+
cut: cut === true,
|
|
12077
|
+
}),
|
|
12078
|
+
})
|
|
12079
|
+
var parsed = await response.json().catch(function () { return null })
|
|
12080
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
12081
|
+
var failure = new Error(parsed !== null && parsed.message !== undefined ? parsed.message : 'HTTP ' + response.status)
|
|
12082
|
+
failure.code = parsed !== null && typeof parsed.code === 'string' ? parsed.code : ''
|
|
12083
|
+
throw failure
|
|
12084
|
+
}
|
|
12085
|
+
return parsed
|
|
12086
|
+
}
|
|
12087
|
+
|
|
12088
|
+
/**
|
|
12089
|
+
* Ask the Host what the SYSTEM clipboard holds (file list + text flavour).
|
|
12090
|
+
*
|
|
12091
|
+
* The page cannot read a file list itself — and on WSL it cannot even tell that
|
|
12092
|
+
* one exists: a copy made in Explorer arrives as an EMPTY paste payload.
|
|
12093
|
+
* @returns {Promise<object>} `{ ok, files, text, method }`.
|
|
12094
|
+
*/
|
|
12095
|
+
async function fsClipboardState(scope) {
|
|
12096
|
+
var response = await fetch(routeUrl('dsh-ris-ide/clipboard/read').href + clipboardQuery(scope), { method: 'GET' })
|
|
12097
|
+
var parsed = await response.json().catch(function () { return null })
|
|
12098
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
12099
|
+
var failure = new Error(parsed !== null && parsed.message !== undefined ? parsed.message : 'HTTP ' + response.status)
|
|
12100
|
+
failure.code = parsed !== null && typeof parsed.code === 'string' ? parsed.code : ''
|
|
12101
|
+
throw failure
|
|
12102
|
+
}
|
|
12103
|
+
return parsed
|
|
12104
|
+
}
|
|
12105
|
+
|
|
12106
|
+
/**
|
|
12107
|
+
* Bytes per upload chunk for a save too large for one request. The host stages
|
|
12108
|
+
* the chunks in a sibling temp file and renames it on the last one, so a big
|
|
12109
|
+
* document is saved without a body-size ceiling (and never half-written).
|
|
12110
|
+
*/
|
|
12111
|
+
var SAVE_CHUNK_BYTES = 512 * 1024
|
|
11235
12112
|
/**
|
|
11236
12113
|
* Write a text file back.
|
|
11237
12114
|
*
|
|
@@ -11245,23 +12122,50 @@ var [ui, setUi] = useState(function () {
|
|
|
11245
12122
|
* @returns {Promise<{mtimeMs?: number}>} the fresh baseline.
|
|
11246
12123
|
*/
|
|
11247
12124
|
async function fsWrite(scope, path, content) {
|
|
11248
|
-
var
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11253
|
-
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
12125
|
+
var payload = {
|
|
12126
|
+
sessionId: scope.sessionId,
|
|
12127
|
+
...(typeof scope.cwd === 'string' && scope.cwd !== '' ? { cwd: scope.cwd } : {}),
|
|
12128
|
+
path: path,
|
|
12129
|
+
}
|
|
12130
|
+
/** POST one body and return the host's answer, or throw its message. */
|
|
12131
|
+
async function postWrite(body) {
|
|
12132
|
+
var url = routeUrl('dsh-ris-ide/fs/write')
|
|
12133
|
+
var response = await fetch(url.href, {
|
|
12134
|
+
method: 'POST',
|
|
12135
|
+
headers: { 'content-type': 'application/json' },
|
|
12136
|
+
body: JSON.stringify(body),
|
|
12137
|
+
})
|
|
12138
|
+
var parsed = await response.json().catch(function () { return null })
|
|
12139
|
+
if (!response.ok || parsed === null || parsed.ok !== true) {
|
|
12140
|
+
if (parsed !== null && parsed.message !== undefined) throw new Error(parsed.message)
|
|
12141
|
+
throw new Error('HTTP ' + response.status)
|
|
12142
|
+
}
|
|
12143
|
+
return parsed
|
|
12144
|
+
}
|
|
12145
|
+
// A save is chunked only when it would be a big body: a normal file must
|
|
12146
|
+
// stay ONE request (the host writes the whole document and answers once).
|
|
12147
|
+
var bytes = typeof TextEncoder === 'function' ? new TextEncoder().encode(content) : null
|
|
12148
|
+
if (bytes === null || bytes.length <= SAVE_CHUNK_BYTES) {
|
|
12149
|
+
var single = await postWrite(Object.assign({}, payload, { content: content }))
|
|
12150
|
+
return { mtimeMs: single.mtimeMs }
|
|
12151
|
+
}
|
|
12152
|
+
// Chunked save: utf8-safe slices, byte offsets, staged rename on the host.
|
|
12153
|
+
var decoder = typeof TextDecoder === 'function' ? new TextDecoder() : null
|
|
12154
|
+
var offset = 0
|
|
12155
|
+
var answer = null
|
|
12156
|
+
while (offset < bytes.length) {
|
|
12157
|
+
var end = Math.min(offset + SAVE_CHUNK_BYTES, bytes.length)
|
|
12158
|
+
// Never cut a multi-byte code point: back off to its leading byte.
|
|
12159
|
+
while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) end -= 1
|
|
12160
|
+
var piece = decoder === null ? content : decoder.decode(bytes.subarray(offset, end))
|
|
12161
|
+
answer = await postWrite(Object.assign({}, payload, {
|
|
12162
|
+
content: piece,
|
|
12163
|
+
offset: offset,
|
|
12164
|
+
final: end >= bytes.length,
|
|
12165
|
+
}))
|
|
12166
|
+
offset = end
|
|
11263
12167
|
}
|
|
11264
|
-
return { mtimeMs:
|
|
12168
|
+
return { mtimeMs: answer === null ? undefined : answer.mtimeMs }
|
|
11265
12169
|
}
|
|
11266
12170
|
/**
|
|
11267
12171
|
* Workspace filename search — through THIS plugin's host route, which runs
|
|
@@ -11320,6 +12224,147 @@ var [ui, setUi] = useState(function () {
|
|
|
11320
12224
|
})
|
|
11321
12225
|
}
|
|
11322
12226
|
|
|
12227
|
+
/**
|
|
12228
|
+
* Whether `problem` is the AbortController's own rejection; the search effects
|
|
12229
|
+
* abort on every keystroke, so that is expected and must never surface as an
|
|
12230
|
+
* error line in the dropdown.
|
|
12231
|
+
* @param {unknown} problem - the caught value.
|
|
12232
|
+
* @returns {boolean} true for an abort.
|
|
12233
|
+
*/
|
|
12234
|
+
function isAbortError(problem) {
|
|
12235
|
+
return problem !== null && problem !== undefined && problem.name === 'AbortError'
|
|
12236
|
+
}
|
|
12237
|
+
|
|
12238
|
+
/**
|
|
12239
|
+
* Read one NDJSON search answer frame by frame.
|
|
12240
|
+
*
|
|
12241
|
+
* The host streams `start`, then one `page` per page of matches (in tree
|
|
12242
|
+
* order), then `done`. Rendering each page as it lands is the whole point:
|
|
12243
|
+
* the dropdown paints the first matches while the remaining repo roots are
|
|
12244
|
+
* still being listed (the batch route made the user wait for all of them).
|
|
12245
|
+
* @param {Response} response - the fetch answer (its body is a stream).
|
|
12246
|
+
* @param {(items: Array) => void} onPage - called with each page.
|
|
12247
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} the `done` frame.
|
|
12248
|
+
*/
|
|
12249
|
+
async function readSearchStream(response, onPage) {
|
|
12250
|
+
var body = response.body
|
|
12251
|
+
if (body === null || body === undefined || typeof body.getReader !== 'function') {
|
|
12252
|
+
throw new Error('这个浏览器不支持流式读取')
|
|
12253
|
+
}
|
|
12254
|
+
var reader = body.getReader()
|
|
12255
|
+
var decoder = new TextDecoder()
|
|
12256
|
+
var buffer = ''
|
|
12257
|
+
var done = null
|
|
12258
|
+
function handleLine(line) {
|
|
12259
|
+
var text = line.trim()
|
|
12260
|
+
if (text === '') return
|
|
12261
|
+
var frame = null
|
|
12262
|
+
try { frame = JSON.parse(text) } catch (problem) { return }
|
|
12263
|
+
if (frame === null || typeof frame !== 'object') return
|
|
12264
|
+
if (frame.type === 'page' && Array.isArray(frame.items)) { onPage(frame.items); return }
|
|
12265
|
+
if (frame.type === 'error') throw new Error(typeof frame.message === 'string' ? frame.message : '检索失败')
|
|
12266
|
+
if (frame.type === 'done') {
|
|
12267
|
+
done = {
|
|
12268
|
+
matches: typeof frame.matches === 'number' ? frame.matches : 0,
|
|
12269
|
+
files: typeof frame.files === 'number' ? frame.files : 0,
|
|
12270
|
+
truncated: frame.truncated === true,
|
|
12271
|
+
}
|
|
12272
|
+
}
|
|
12273
|
+
}
|
|
12274
|
+
for (;;) {
|
|
12275
|
+
var chunk = await reader.read()
|
|
12276
|
+
if (chunk.done === true) break
|
|
12277
|
+
buffer += decoder.decode(chunk.value, { stream: true })
|
|
12278
|
+
var index = buffer.indexOf('\n')
|
|
12279
|
+
while (index !== -1) {
|
|
12280
|
+
handleLine(buffer.slice(0, index))
|
|
12281
|
+
buffer = buffer.slice(index + 1)
|
|
12282
|
+
index = buffer.indexOf('\n')
|
|
12283
|
+
}
|
|
12284
|
+
}
|
|
12285
|
+
buffer += decoder.decode()
|
|
12286
|
+
if (buffer !== '') handleLine(buffer)
|
|
12287
|
+
if (done === null) throw new Error('检索连接中断')
|
|
12288
|
+
return done
|
|
12289
|
+
}
|
|
12290
|
+
|
|
12291
|
+
/**
|
|
12292
|
+
* Streamed workspace filename search — pages arrive while the remaining repo
|
|
12293
|
+
* roots are still being listed, so the dropdown can paint the first hit long
|
|
12294
|
+
* before the batch route would have answered.
|
|
12295
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
12296
|
+
* @param {string} query - case-insensitive path/basename substring.
|
|
12297
|
+
* @param {{onPage?: Function}} handlers - receives each page of absolute paths.
|
|
12298
|
+
* @param {AbortSignal} [signal] - aborts the request when the query changes.
|
|
12299
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} totals.
|
|
12300
|
+
*/
|
|
12301
|
+
async function fsSearchStream(scope, query, handlers, signal) {
|
|
12302
|
+
var url = routeUrl('dsh-ris-ide/search/stream')
|
|
12303
|
+
url.searchParams.set('sessionId', scope.sessionId)
|
|
12304
|
+
var routeCwd = scopeCwd(scope)
|
|
12305
|
+
if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
|
|
12306
|
+
url.searchParams.set('q', query)
|
|
12307
|
+
url.searchParams.set('limit', '300')
|
|
12308
|
+
url.searchParams.set('pageSize', String(SEARCH_STREAM_PAGE_SIZE))
|
|
12309
|
+
var onPage = handlers !== undefined && handlers !== null && typeof handlers.onPage === 'function'
|
|
12310
|
+
? handlers.onPage
|
|
12311
|
+
: function () {}
|
|
12312
|
+
var response = await fetch(url.href, { headers: { accept: 'application/x-ndjson' }, signal: signal })
|
|
12313
|
+
if (response.status === 404) {
|
|
12314
|
+
// A host older than 1.7.3 has no stream route yet (the client half reloads
|
|
12315
|
+
// with a page refresh, the host half only on `dsh web` restart). Answer the
|
|
12316
|
+
// batch route as ONE page instead of showing "HTTP 404" in the dropdown.
|
|
12317
|
+
var batch = await fsSearch(scope, query)
|
|
12318
|
+
onPage(batch.matches)
|
|
12319
|
+
return { matches: batch.matches.length, files: 0, truncated: false }
|
|
12320
|
+
}
|
|
12321
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
12322
|
+
return readSearchStream(response, onPage)
|
|
12323
|
+
}
|
|
12324
|
+
|
|
12325
|
+
/**
|
|
12326
|
+
* Streamed workspace CONTENT search (`git grep` hits), same page-by-page
|
|
12327
|
+
* contract as {@link fsSearchStream}.
|
|
12328
|
+
* @param {{sessionId: string, cwd?: string}} scope - owning session.
|
|
12329
|
+
* @param {string} query - literal text to find.
|
|
12330
|
+
* @param {{onPage?: Function}} handlers - receives each page of hits.
|
|
12331
|
+
* @param {AbortSignal} [signal] - aborts the request when the query changes.
|
|
12332
|
+
* @returns {Promise<{matches: number, files: number, truncated: boolean}>} totals.
|
|
12333
|
+
*/
|
|
12334
|
+
async function fsSearchContentStream(scope, query, handlers, signal) {
|
|
12335
|
+
var url = routeUrl('dsh-ris-ide/search-content/stream')
|
|
12336
|
+
url.searchParams.set('sessionId', scope.sessionId)
|
|
12337
|
+
var routeCwd = scopeCwd(scope)
|
|
12338
|
+
if (routeCwd !== undefined) url.searchParams.set('cwd', routeCwd)
|
|
12339
|
+
url.searchParams.set('q', query)
|
|
12340
|
+
url.searchParams.set('limit', '200')
|
|
12341
|
+
url.searchParams.set('pageSize', String(SEARCH_STREAM_PAGE_SIZE))
|
|
12342
|
+
var onPage = handlers !== undefined && handlers !== null && typeof handlers.onPage === 'function'
|
|
12343
|
+
? handlers.onPage
|
|
12344
|
+
: function () {}
|
|
12345
|
+
var response = await fetch(url.href, { headers: { accept: 'application/x-ndjson' }, signal: signal })
|
|
12346
|
+
if (response.status === 404) {
|
|
12347
|
+
// Pre-1.7.3 host: stream the batch route's hits as a single page.
|
|
12348
|
+
var hits = await fsSearchContent(scope, query)
|
|
12349
|
+
onPage(hits)
|
|
12350
|
+
return { matches: hits.length, files: 0, truncated: false }
|
|
12351
|
+
}
|
|
12352
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
12353
|
+
return readSearchStream(response, function (items) {
|
|
12354
|
+
var hits = []
|
|
12355
|
+
for (var index = 0; index < items.length; index += 1) {
|
|
12356
|
+
var hit = items[index]
|
|
12357
|
+
if (hit === null || hit === undefined || typeof hit.path !== 'string') continue
|
|
12358
|
+
hits.push({
|
|
12359
|
+
path: hit.path,
|
|
12360
|
+
line: typeof hit.line === 'number' ? hit.line : Number(hit.line) || 0,
|
|
12361
|
+
text: typeof hit.text === 'string' ? hit.text : '',
|
|
12362
|
+
})
|
|
12363
|
+
}
|
|
12364
|
+
onPage(hits)
|
|
12365
|
+
})
|
|
12366
|
+
}
|
|
12367
|
+
|
|
11323
12368
|
/**
|
|
11324
12369
|
* Work out what `mvn test` call would run one Java test FILE (PM gap #6).
|
|
11325
12370
|
*
|
|
@@ -11480,6 +12525,12 @@ var [ui, setUi] = useState(function () {
|
|
|
11480
12525
|
*/
|
|
11481
12526
|
/** How many query → results pairs the search dropdown keeps warm. */
|
|
11482
12527
|
var SEARCH_CACHE_LIMIT = 40
|
|
12528
|
+
/**
|
|
12529
|
+
* Matches per streamed page. The host flushes a page as soon as it fills, so
|
|
12530
|
+
* a small page is what makes the first hits visible while the remaining repo
|
|
12531
|
+
* roots are still being listed (the batch route had to finish all of them).
|
|
12532
|
+
*/
|
|
12533
|
+
var SEARCH_STREAM_PAGE_SIZE = 40
|
|
11483
12534
|
|
|
11484
12535
|
/**
|
|
11485
12536
|
* Remember one search result set (or refresh an existing key's position).
|
|
@@ -12148,6 +13199,10 @@ var [ui, setUi] = useState(function () {
|
|
|
12148
13199
|
}
|
|
12149
13200
|
}, [sessionId, cwd])
|
|
12150
13201
|
|
|
13202
|
+
// After a `dsh web` restart the console keeps its error row ("扫描失败…")
|
|
13203
|
+
// until something re-reads. The stream reopening IS that signal.
|
|
13204
|
+
useHostRecovery(function () { void refresh(false) })
|
|
13205
|
+
|
|
12151
13206
|
/** Console rows stream (fallback: the 3 s poll below). */
|
|
12152
13207
|
var [streamOk, setStreamOk] = useState(function () { return typeof EventSource === 'function' })
|
|
12153
13208
|
useEffect(function () {
|
|
@@ -12343,7 +13398,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12343
13398
|
}
|
|
12344
13399
|
// The standalone window has no DSH right sidebar, so there is no sidebar
|
|
12345
13400
|
// editor to open into: the workbench editor is the only editor there, so
|
|
12346
|
-
// hand the path over and let it open `.dsh-ris-ide.json` as a normal tab
|
|
13401
|
+
// hand the path over and let it open `.dsh-ris-ide/config.json` as a normal tab
|
|
12347
13402
|
// (a hidden dotfile is not reachable from the tree or the search box).
|
|
12348
13403
|
if (panelCtx === null || panelCtx === undefined) {
|
|
12349
13404
|
setOpenConfigRequest(function (previous) {
|
|
@@ -12360,7 +13415,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12360
13415
|
|
|
12361
13416
|
/**
|
|
12362
13417
|
* Config notices the console owes the user: first-run generation, a config
|
|
12363
|
-
* sync, and drift between `.dsh-ris-ide.json` and the current scan. The
|
|
13418
|
+
* sync, and drift between `.dsh-ris-ide/config.json` and the current scan. The
|
|
12364
13419
|
* dismissal signature travels with each item so closing one sticks.
|
|
12365
13420
|
* @returns {Array<{kind: string, signature: string, text: string}>} live notices.
|
|
12366
13421
|
*/
|
|
@@ -12454,14 +13509,17 @@ var [ui, setUi] = useState(function () {
|
|
|
12454
13509
|
/** Open the standalone window on the picked program (or on the workspace). */
|
|
12455
13510
|
function openCompactWindow() {
|
|
12456
13511
|
var picked = compactProgram()
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
13512
|
+
void (async function () {
|
|
13513
|
+
try {
|
|
13514
|
+
// One window per workspace: a second click on ⧉ must focus the IDE the
|
|
13515
|
+
// user already has (the registry knows), never open a twin.
|
|
13516
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: picked !== undefined ? picked.id : undefined })
|
|
13517
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
13518
|
+
else setState(function (prev) { return Object.assign({}, prev, { note: '已切到本工作空间的 IDE 窗口' }) })
|
|
13519
|
+
} catch (error) {
|
|
13520
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
13521
|
+
}
|
|
13522
|
+
})()
|
|
12465
13523
|
}
|
|
12466
13524
|
|
|
12467
13525
|
/** Drag the hairline above the log pane; the height is remembered on release. */
|
|
@@ -12563,7 +13621,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12563
13621
|
type: 'button', style: busy ? S.paneIconOff : S.stopIcon, disabled: busy, 'data-action': 'stop',
|
|
12564
13622
|
title: '停止 ' + program.name,
|
|
12565
13623
|
onClick: function (event) { event.stopPropagation(); void act('stop', program) },
|
|
12566
|
-
}, busy ? '…' :
|
|
13624
|
+
}, busy ? '…' : stopGlyph())
|
|
12567
13625
|
: null,
|
|
12568
13626
|
// Restart is the daily loop after a code change (PM gap #1): it works on
|
|
12569
13627
|
// a running program (stop → start, pidfile released first) and on a
|
|
@@ -12582,11 +13640,13 @@ var [ui, setUi] = useState(function () {
|
|
|
12582
13640
|
title: '在独立窗口里调试 ' + program.name + '(含断点/调用栈/变量)',
|
|
12583
13641
|
onClick: function (event) {
|
|
12584
13642
|
event.stopPropagation()
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
13643
|
+
void (async function () {
|
|
13644
|
+
try {
|
|
13645
|
+
await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: program.id, debug: true })
|
|
13646
|
+
} catch (error) {
|
|
13647
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
13648
|
+
}
|
|
13649
|
+
})()
|
|
12590
13650
|
},
|
|
12591
13651
|
}, ideBadgeIcon('bug', 'play', 13))
|
|
12592
13652
|
: null,
|
|
@@ -12634,7 +13694,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12634
13694
|
configExists === true
|
|
12635
13695
|
? h('button', {
|
|
12636
13696
|
type: 'button', style: S.paneIcon, 'data-action': 'compact-config-open',
|
|
12637
|
-
title: '打开配置文件 .dsh-ris-ide.json(启动参数由你维护)',
|
|
13697
|
+
title: '打开配置文件 .dsh-ris-ide/config.json(启动参数由你维护)',
|
|
12638
13698
|
onClick: openConfig,
|
|
12639
13699
|
}, '📄')
|
|
12640
13700
|
: null,
|
|
@@ -12642,8 +13702,8 @@ var [ui, setUi] = useState(function () {
|
|
|
12642
13702
|
type: 'button', style: busyId === '__config__' ? S.paneIconOff : S.paneIcon,
|
|
12643
13703
|
disabled: busyId === '__config__', 'data-action': 'compact-config-generate',
|
|
12644
13704
|
title: configExists === true
|
|
12645
|
-
? '更新配置:按当前扫描结果同步 .dsh-ris-ide.json(保留你改过的字段)'
|
|
12646
|
-
: '生成配置:把扫描到的程序写成 .dsh-ris-ide.json',
|
|
13705
|
+
? '更新配置:按当前扫描结果同步 .dsh-ris-ide/config.json(保留你改过的字段)'
|
|
13706
|
+
: '生成配置:把扫描到的程序写成 .dsh-ris-ide/config.json',
|
|
12647
13707
|
onClick: function () { generateConfigFile(configExists ? 'update' : undefined) },
|
|
12648
13708
|
}, busyId === '__config__' ? '…' : '⚙'),
|
|
12649
13709
|
h('button', {
|
|
@@ -12692,17 +13752,18 @@ var [ui, setUi] = useState(function () {
|
|
|
12692
13752
|
h('span', { style: S.status }, '已勾选 ' + checkedIds.length + ' 项'),
|
|
12693
13753
|
h('span', { style: S.spacer }),
|
|
12694
13754
|
h('button', {
|
|
12695
|
-
|
|
13755
|
+
// Same tones as the row actions they repeat: ▶/⟳ green, ■ red.
|
|
13756
|
+
type: 'button', style: busyId !== undefined || bulk !== null ? S.paneIconOff : S.startIcon, 'data-action': 'batch-start',
|
|
12696
13757
|
disabled: busyId !== undefined || bulk !== null,
|
|
12697
13758
|
title: '按列表顺序启动勾选的项目(跳过已在运行的)',
|
|
12698
13759
|
onClick: function () { void actMany('start') },
|
|
12699
13760
|
}, bulk !== null && bulk.kind === 'start' ? (bulk.index + 1) + '/' + bulk.total : '▶'),
|
|
12700
13761
|
h('button', {
|
|
12701
|
-
type: 'button', style: S.
|
|
13762
|
+
type: 'button', style: busyId !== undefined || bulk !== null ? S.paneIconOff : S.stopIcon, 'data-action': 'batch-stop',
|
|
12702
13763
|
disabled: busyId !== undefined || bulk !== null,
|
|
12703
13764
|
title: '按列表倒序停止勾选的项目(跳过未运行的)',
|
|
12704
13765
|
onClick: function () { void actMany('stop') },
|
|
12705
|
-
}, bulk !== null && bulk.kind === 'stop' ? (bulk.index + 1) + '/' + bulk.total :
|
|
13766
|
+
}, bulk !== null && bulk.kind === 'stop' ? (bulk.index + 1) + '/' + bulk.total : stopGlyph()),
|
|
12706
13767
|
h('button', {
|
|
12707
13768
|
type: 'button', style: S.paneButton, 'data-action': 'batch-clear',
|
|
12708
13769
|
title: '取消全部勾选',
|
|
@@ -12839,7 +13900,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12839
13900
|
return h('div', { key: program.id, style: S.progRow, 'data-program': program.name, 'data-kind': program.kind },
|
|
12840
13901
|
h('span', { style: alive ? S.instDotOn : S.instDotOff, title: alive ? '运行中' : '未运行' }, '●'),
|
|
12841
13902
|
h('span', { style: S.instName, title: program.dir }, program.name,
|
|
12842
|
-
edited ? h('span', { style: S.editedMark, title: '来自 .dsh-ris-ide.json(可编辑/禁用/改启动参数)' }, '✎') : null),
|
|
13903
|
+
edited ? h('span', { style: S.editedMark, title: '来自 .dsh-ris-ide/config.json(可编辑/禁用/改启动参数)' }, '✎') : null),
|
|
12843
13904
|
h('span', { style: kindStyle, title: program.kind }, kindLabel),
|
|
12844
13905
|
h('span', { style: S.progWhere },
|
|
12845
13906
|
h('span', { style: S.progRel, title: program.dir }, program.relDir),
|
|
@@ -12859,7 +13920,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12859
13920
|
type: 'button', style: busy ? S.stopDisabled : S.stop, disabled: busy, 'data-action': 'stop',
|
|
12860
13921
|
title: '停止 ' + program.name,
|
|
12861
13922
|
onClick: function () { act('stop', program) },
|
|
12862
|
-
}, busy ? '…' :
|
|
13923
|
+
}, busy ? '…' : stopGlyph())
|
|
12863
13924
|
: h('button', { type: 'button', style: S.buttonOff, disabled: true, 'data-action': 'stop' }, '停止'),
|
|
12864
13925
|
program.kind === 'spring'
|
|
12865
13926
|
? h('button', {
|
|
@@ -12892,7 +13953,7 @@ var [ui, setUi] = useState(function () {
|
|
|
12892
13953
|
type: 'button', style: S.button, disabled: busyId === '__config__', 'data-action': 'config',
|
|
12893
13954
|
title: state.config !== undefined && state.config !== null && state.config.exists === true
|
|
12894
13955
|
? '按当前扫描结果更新配置:新增的程序补上、失效的自动条目删掉,你改过的字段与自定义程序保持不动'
|
|
12895
|
-
: '把扫描到的程序与启停参数写成 .dsh-ris-ide.json,之后由你维护',
|
|
13956
|
+
: '把扫描到的程序与启停参数写成 .dsh-ris-ide/config.json,之后由你维护',
|
|
12896
13957
|
onClick: function () {
|
|
12897
13958
|
var exists = state.config !== undefined && state.config !== null && state.config.exists === true
|
|
12898
13959
|
generateConfigFile(exists ? 'update' : undefined)
|
|
@@ -12966,6 +14027,8 @@ var [ui, setUi] = useState(function () {
|
|
|
12966
14027
|
RisIdeWindowAction: RisIdeWindowAction,
|
|
12967
14028
|
openStandaloneWindow: openStandaloneWindow,
|
|
12968
14029
|
mountStandalone: mountStandalone,
|
|
14030
|
+
StandaloneWindow: StandaloneWindow,
|
|
14031
|
+
requestStandaloneWindowClose: requestStandaloneWindowClose,
|
|
12969
14032
|
fetchProgramById: fetchProgramById,
|
|
12970
14033
|
WINDOW_NAME: WINDOW_NAME,
|
|
12971
14034
|
standaloneWindowKey: standaloneWindowKey,
|
|
@@ -13012,6 +14075,11 @@ var [ui, setUi] = useState(function () {
|
|
|
13012
14075
|
searchHitActiveIndex: searchHitActiveIndex,
|
|
13013
14076
|
rememberSearchEntry: rememberSearchEntry,
|
|
13014
14077
|
fsSearchContent: fsSearchContent,
|
|
14078
|
+
fsSearchStream: fsSearchStream,
|
|
14079
|
+
fsSearchContentStream: fsSearchContentStream,
|
|
14080
|
+
readSearchStream: readSearchStream,
|
|
14081
|
+
isAbortError: isAbortError,
|
|
14082
|
+
SEARCH_STREAM_PAGE_SIZE: SEARCH_STREAM_PAGE_SIZE,
|
|
13015
14083
|
runTestStart: runTestStart,
|
|
13016
14084
|
runTestStatus: runTestStatus,
|
|
13017
14085
|
/**
|
|
@@ -13034,6 +14102,7 @@ var [ui, setUi] = useState(function () {
|
|
|
13034
14102
|
readSavedUi: readSavedUi,
|
|
13035
14103
|
treeLabel: treeLabel,
|
|
13036
14104
|
childEntryFor: childEntryFor,
|
|
14105
|
+
pathWithin: pathWithin,
|
|
13037
14106
|
sourceRelativeSuffix: sourceRelativeSuffix,
|
|
13038
14107
|
parseGutterLine: parseGutterLine,
|
|
13039
14108
|
// Log level filter (PM gap #4) and the "what did I change" diff (#5): both
|